lib/liquidscript/compiler/icr/expressions.rb in liquidscript-0.8.2 vs lib/liquidscript/compiler/icr/expressions.rb in liquidscript-0.9.0

- old
+ new

@@ -88,64 +88,47 @@ # if it's an expression, it can have anything but commas in it. # # @return [ICR::Code] def compile_lparen shift :lparen - maybe_func = 1 - components = [] - unless peek?(:identifier, :rparen) - maybe_func = 0 + if peek?(:identifier) + _compile_lparen_method + elsif peek?(:rparen) + _compile_lparen_method_final + else + _compile_lparen_expression end + end - expression = action do - maybe_func = 0 - components << compile_vexpression - end + def _compile_lparen_method + ident = shift :identifier - ident = action do |i| - if peek?(:comma) - maybe_func = 2 - components << i - elsif peek?(:rparen) - components << i - else - components << value_expect(compile_identifier(i)) - end + if peek?(:comma, :rparen) + _compile_lparen_method_final(ident) + else + value_expect(ident) 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 => ident, - :_ => expression - when 2 - expect :rparen => action.end_loop, - :comma => action.shift, - :identifier => action { |i| components << i } + def _compile_lparen_method_final(ident = nil) + components = [ident].compact + + while peek?(:comma) do + shift(:comma) + components << shift(:identifier) end - end - func_decl = (maybe_func == 1 && peek?(:arrow)) || - (maybe_func == 2) + shift :rparen + compile_function_with_parameters(components) + end - if func_decl - compile_function_with_parameters(components) - else - code(:expression, components.map do |c| - if c.is_a?(Scanner::Token) - compile_identifier(c) - else - c - end - end) - end + def _compile_lparen_expression + out = compile_vexpression + shift :rparen + code :expression, out end + end end end end