Module: Liquidscript::Compiler::ICR::Expressions
- Included in:
- Liquidscript::Compiler::ICR
- Defined in:
- lib/liquidscript/compiler/icr/expressions.rb
Instance Method Summary collapse
- #_compile_lparen_expression ⇒ Object
- #_compile_lparen_method ⇒ Object
- #_compile_lparen_method_final(ident = nil) ⇒ Object
-
#compile_assignment(identifier) ⇒ ICR::Code
Handles an assignment of the form ‘identifier = expression`, with the argument being the identifier, and the position of the compiler being after it.
- #compile_binop(left) ⇒ Object
-
#compile_expression ⇒ ICR::Code
Compiles an expression.
-
#compile_lparen ⇒ ICR::Code
We don’t know, at this point, whether this is a function declaration, or an expression; if it’s a function declaration, the contents of the lparen can only be commas and identifiers; if it’s an expression, it can have anything but commas in it.
- #compile_minus ⇒ Object
- #compile_plus ⇒ Object
- #compile_unop ⇒ Object
-
#compile_vexpression ⇒ ICR::Code
Compiles an expression that returns a value.
Instance Method Details
#_compile_lparen_expression ⇒ Object
125 126 127 128 129 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 125 def _compile_lparen_expression out = compile_vexpression shift :rparen code :expression, out end |
#_compile_lparen_method ⇒ Object
103 104 105 106 107 108 109 110 111 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 103 def _compile_lparen_method ident = shift :identifier if peek?(:comma, :rparen) _compile_lparen_method_final(ident) else value_expect(ident) end end |
#_compile_lparen_method_final(ident = nil) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 113 def _compile_lparen_method_final(ident = nil) components = [ident].compact while peek?(:comma) do shift(:comma) components << shift(:identifier) end shift :rparen compile_function_with_parameters(components) end |
#compile_assignment(identifier) ⇒ ICR::Code
Handles an assignment of the form ‘identifier = expression`, with the argument being the identifier, and the position of the compiler being after it.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 70 def compile_assignment(identifier) shift :equal 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 |
#compile_binop(left) ⇒ Object
56 57 58 59 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 56 def compile_binop(left) code :binop, shift(:binop, :minus, :plus), left, compile_vexpression end |
#compile_expression ⇒ ICR::Code
Compiles an expression. This is primarily used in a general context, such that anything can be returned.
10 11 12 13 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 10 def compile_expression expect :if, :unless, :class, :module, :loop, :for, :while, :action, :try, :_ => :vexpression end |
#compile_lparen ⇒ ICR::Code
We don’t know, at this point, whether this is a function declaration, or an expression; if it’s a function declaration, the contents of the lparen can only be commas and identifiers; if it’s an expression, it can have anything but commas in it.
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 91 def compile_lparen shift :lparen if peek?(:identifier) _compile_lparen_method elsif peek?(:rparen) _compile_lparen_method_final else _compile_lparen_expression end end |
#compile_minus ⇒ Object
44 45 46 47 48 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 44 def compile_minus shift :minus code :neg, compile_vexpression end |
#compile_plus ⇒ Object
50 51 52 53 54 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 50 def compile_plus shift :plus code :pos, compile_vexpression end |
#compile_unop ⇒ Object
61 62 63 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 61 def compile_unop code :unop, shift(:unop, :preunop), compile_vexpression end |
#compile_vexpression ⇒ ICR::Code
Compiles an expression that returns a value.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 18 def compile_vexpression out = expect :number, :identifier, :istring, :lparen, :sstring, :operator, :keyword, :regex, :newline, :istring_begin, :iheredoc_begin, :plus, :minus, :lbrace => :object, :lbrack => :array, :arrow => :function, [ :preunop, :unop ] => :unop, [ :heredoc_ref, :iheredoc_ref ] => :href, [ :heredoc, :iheredoc ] => :heredoc value_expect(out) end |