On Feb 17, 2011, at 3:05 PM, Nick Lewis wrote:

> On Thu, Feb 17, 2011 at 2:58 PM, Luke Kanies <[email protected]> wrote:
> On Feb 17, 2011, at 2:46 PM, Nick Lewis wrote:
> 
>> On Thu, Feb 17, 2011 at 2:11 PM, Luke Kanies <[email protected]> wrote:
>> This looks more like a lexer problem than a parser problem to me.
>> 
>> Negative numbers should be lexed the same as positive numbers, because 
>> otherwise you have to go in and specifically allow negative numbers 
>> everywhere.
>> 
>> In the current solution, you have enabled negative numbers for functions, 
>> but not for parameter values:
>> 
>> file { "/tmp/asdf": owner => -1 }
>> 
>> That throws a parse exception.
>> 
>> Note that there's an easy workaround:
>> 
>> file { "/tmp/asdf": owner => "-1" }
>> 
>> This works just fine with functions, too (given that Puppet's language only 
>> has strings, no numbers).
>> 
>> It's true that this solution doesn't fix that problem. But it does fix the 
>> problem of not being able to call my_function(-$a), which has a more 
>> challenging workaround. A solution that would have solved both related 
>> problems would be more complex, and didn't feel appropriate for a fix 
>> targeting 2.6. In the future, there are a whole host of related lexer/parser 
>> issues I would like to address, including #5817, #5516, #5268, #3129.
> 
> 
> Hmm.  I think supporting that is actually a bug, and is one of the problems 
> with solving this at a syntactic level.  Ruby doesn't support that syntax, 
> and my guess is nothing else reasonable does, either.  If you want that, use 
> quotes:
> 
> 
> I may be misunderstanding you, but Ruby most definitely supports a unary 
> minus operator on variables.

luke@syringe $ ruby -e 'a = "foo"; b = -a'
-e:1: undefined method `-@' for "foo":String (NoMethodError)
luke@syringe $

Not that I can tell.

> my_function("-$a")
> 
> I think our lexer should support negative numbers, but our parser absolutely 
> shouldn't care about them.
> 
> 
> I agree with that, but I also think that what the parser should ideally do 
> and what we should do to the parser right now are different things.

I'm sorry; what do you mean?

If there's a problem, we should fix it the right way, and this definitely isn't 
it.  This is both a significant change to the language, and a very limited fix 
to the actual bug (which is a general bug and should not be related to 
functions at all).

In looking more closely at the grammer, the "correct" fix for this appears to 
be to allow expression as the argument to functions.  That's where Puppet gets 
its current unary minus behavior from, it looks like.

If you don't want to do that, then the bug should be rejected, because it has 
an easy workaround (use quotes).
-- 
Nothing is impossible for the man who doesn't have to do it himself.
-- A. H. Weiler
---------------------------------------------------------------------
Luke Kanies  -|-   http://puppetlabs.com   -|-   +1(615)594-8199



-- 
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