stefankroes / scribble

Scribble is a customer facing template language similar to Liquid build in Ruby
MIT License
122 stars 7 forks source link

unary operators do not work properly on chained objects. #10

Open ryanong opened 9 years ago

ryanong commented 9 years ago

scribble parses

!student.enrolled? => student.not.enrolled?

instead of

!student.enrolled? => student.enrolled?.not

Work around

!(student.enrolled?)

stefankroes commented 9 years ago

I did some work on this in the train yesterday. I wrote some tests and gave method invocation precedence over unary operators. I think this is the right approach and also the approach Ruby takes.

However, Scribble parses negative integers (ie. -1) as a positive integer and a unary operator. But in the case of -1.abs the minus should take precedence over the method invocation. Ruby manages this by parsing the minus as part of the integer instead of as an unary operator. I'll try to implement something similar.

edit: ... gave method invocation precedence over unary operators ...

stefankroes commented 9 years ago
1.9.3-p551 :002 > Fixnum.send :undef_method, :-@
 => Fixnum 
1.9.3-p551 :003 > -(1)
NoMethodError: undefined method `-@' for 1:Fixnum
    from (irb):3
    from /Users/stefan/.rvm/rubies/ruby-1.9.3-p551/bin/irb:12:in `<main>'
1.9.3-p551 :004 > -1
 => -1 
1.9.3-p551 :005 > --1
NoMethodError: undefined method `-@' for -1:Fixnum
    from (irb):5
    from /Users/stefan/.rvm/rubies/ruby-1.9.3-p551/bin/irb:12:in `<main>'
1.9.3-p551 :006 > 
ryanong commented 9 years ago

That is some voodoo there. Great example!