On Sep 21, 2008, at 4:41 AM, Brice Figureau wrote:
>>
>> Note that Puppet's language doesn't have numbers -- they're all
>> treated as strings (only 'true' and 'false', when unquoted, are
>> anything but strings) -- so you'll have to do a touch of magic to  
>> make
>> math work.
>
> Yes, I know, the code has some "to_i" to convert strings matching
> numbers to integer. But I'm not satisfied with this, as it doesn't
> handle float numbers.
> I'm willing to do something along the line (pseudocode) of:
>
>
> safeevaluate operand
> if !string or !number
>   raise error
>
> if string matches /^\d+$/
>   call to_i
>
> else if string matches /^\d+.\d+$/
>   call to_f
>
> then do the computation...
> And also, is it ok to raise ArgumentErrors during evaluate() when I
> encounter something that can't be safely converted in a number?
>
> Can I move this part to the scope class, as there is a true? method
> doing the same kind of things?

That seems reasonable.

>
> Also how does ruby manage coercion (or implicit cast) when doing
> integer/float computation?

I dunno, really.

>
> I couldn't find at first glance anything online discussing this (I  
> guess
> I'll have to purchase a ruby reference book sometimes).
>
>> Generally, I'm not opposed to this but I don't think it's all that
>> important, either.  I expect others will stauchly disagree with me,
>> though, and would love this functionality.
>
> I understand, it's just that's the low hanging fruits for me while
> coding in Puppet: I know this part of the code quite well now, and  
> it's
> only a minor modification above my previous if expression patch.
> And I know some people would welcome arithmetic computations, I  
> already
> saw some threads on the user list mentioning this.

Ok.  Suit yourself then. :)

>
>> The lack of racc documentation is quite fun -- I can only ever find  
>> my
>> own threads and code when looking for it. I can't imagine I'm the  
>> only
>> person to ever use it, but I might be the only one to ever publish
>> anything using it.
>
> It seems people are now using Coco/R where I could find more examples.
> In fact Racc mimic bison/yacc, so the bison documentation and samples
> are enough (but I found that after I sent my previous e-mail).

I haven't seen Coco/R.  Racc was the most complete and, surprisingly,  
best documented parser generator for ruby when I started Puppet, and  
it doesn't seem worth changing at this point.  I've thought about  
things like ANTLR, but they don't seem worth the change.

>
>> In terms of shift/reduce conflicts, they are the bane of LALR parser
>> generators.  I'm willing to do what I can to help, but they're pretty
>> unfun.  What's your code look like right now?
>
> I left my Dragon book at the office, so from home that was not easy to
> remember what I learnt 15 years ago about parsers :-)
> But I managed to rewrite the grammar to not be ambiguous, and there is
> no s/r conflicts anymore (for the moment), it even works fine for
> integers :-)

Awesome.  It's crazy that the Dragon book is the *only* useful book in  
this area, but there you go.

For all those budding parser writers out there -- buy the Dragon book  
and skip the rest.

>
>> BTW, one thing that might be useful is to create a stand-alone parser
>> that just does the arithmetic, and when you're happy with it, import
>> it into Puppet.  Then again, that might be 10x harder. :)
>
> Yes, puppet defines most of the thing (ie AST tree, the lexer and so
> on). I don't want to rewrite all of this :-)


I was just thinking the parser -- no code attached to the statement  
blocks.  But whatever works for you.

-- 
As a general rule, don't solve puzzles that open portals to Hell.
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to