lib/liquidscript/compiler/icr/expressions.rb in liquidscript-0.10.4 vs lib/liquidscript/compiler/icr/expressions.rb in liquidscript-0.11.0.rc1

- old
+ new

@@ -7,11 +7,12 @@ # context, such that anything can be returned. # # @return [ICR::Code] def compile_expression expect :if, :unless, :class, :module, :loop, :for, - :while, :action, :try, :_ => :vexpression + :while, :action, :try, :return, + :colon => :directive, :_ => :vexpression end # Compiles an expression that returns a value. # # @return [ICR::Code] @@ -60,10 +61,15 @@ def compile_unop code :unop, shift(:unop, :preunop), compile_vexpression end + def compile_return + shift :return + code :return, compile_vexpression + end + # Handles an assignment of the form `identifier = expression`, # with the argument being the identifier, and the position of # the compiler being after it. # # @return [ICR::Code] @@ -98,10 +104,34 @@ else _compile_lparen_expression end end + def compile_directive + shift :colon + shift :lbrack + command = shift(:identifier).value + old, @in_directive = @in_directive, true + arguments = collect_compiles :rbrack do + expect :lbrace => action { _compile_block }, + :identifier => action.shift, + :_ => :vexpression + end + + directive = { + :command => command, + :arguments => arguments } + + @in_directive = old + + if @in_directive + directive + else + handle_directive(directive) + end + end + def _compile_lparen_method ident = shift :identifier if peek?(:comma, :rparen) _compile_lparen_method_final(ident) @@ -109,9 +139,10 @@ out = value_expect(ref(ident)) shift :rparen code :expression, out end end + def _compile_lparen_method_final(ident = nil) components = [ident].compact while peek?(:comma) do