lib/liquidscript/compiler/icr/expressions.rb in liquidscript-0.6.1 vs lib/liquidscript/compiler/icr/expressions.rb in liquidscript-0.6.2

- old
+ new

@@ -22,31 +22,45 @@ :keyword, :unop, :regex, :newline, :istring_begin, :iheredoc_begin, + :plus, :minus, :lbrace => :object, :lbrack => :array, :arrow => :function, [ :heredoc_ref, :iheredoc_ref ] => :href, [ :heredoc, :iheredoc ] => :heredoc - if peek? :binop + if peek? :binop, :minus, :plus compile_binop(out) elsif peek? :prop compile_property(out) else out end end + def compile_minus + shift :minus + + code :neg, compile_vexpression + end + + def compile_plus + shift :plus + + code :pos, compile_vexpression + end + def compile_binop(left) - code :binop, shift(:binop), left, compile_vexpression + code :binop, shift(:binop, :minus, :plus), left, + compile_vexpression end def compile_unop code :unop, shift(:unop), compile_vexpression end @@ -56,16 +70,17 @@ # the compiler being after it. # # @return [ICR::Code] def compile_assignment(identifier) shift :equal - value = compile_vexpression if identifier.type == :identifier variable = set(identifier) + value = compile_vexpression variable.value = value else + value = compile_vexpression variable = identifier end code :set, variable, value end @@ -88,18 +103,29 @@ expression = action do maybe_func = 0 components << compile_vexpression end + ident = action do |i| + if peek?(:comma) + maybe_func = 2 + components << i + elsif peek?(:rparen) + components << i + else + components << compile_identifier(i) + end + end + loop do case maybe_func when 0 expect :rparen => action.end_loop, :_ => expression when 1 expect :rparen => action.end_loop, :comma => action { maybe_func = 2 }, - :identifier => action { |i| components << i }, + :identifier => ident, :_ => expression when 2 expect :rparen => action.end_loop, :comma => action.shift, :identifier => action { |i| components << i }