Module: Liquidscript::Compiler::ICR::Expressions
- Included in:
- Liquidscript::Compiler::ICR
- Defined in:
- lib/liquidscript/compiler/icr/expressions.rb
Instance Method Summary collapse
- #_compile_lparen_argument ⇒ Object
- #_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_directive ⇒ 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_return ⇒ Object
- #compile_unop ⇒ Object
-
#compile_vexpression ⇒ ICR::Code
Compiles an expression that returns a value.
Instance Method Details
#_compile_lparen_argument ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 176 def _compile_lparen_argument shift(:comma) ident = shift(:identifier) set(ident) erange = action do |_| if top[:etc] raise CompileError, "A drain argument has already been specified!" end top[:etc] = ident :etc end value = expect :equal => action { |_| compile_vexpression }, :erange => erange, :_ => action { nil } [ident, value] end |
#_compile_lparen_expression ⇒ Object
170 171 172 173 174 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 170 def _compile_lparen_expression out = compile_vexpression shift :rparen code :expression, out end |
#_compile_lparen_method ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 135 def _compile_lparen_method ident = shift :identifier if peek?(:equal) shift(:equal) v = compile_vexpression else v = nil end if peek?(:comma, :rparen) _compile_lparen_method_final([ident, v]) else out = value_expect(ref(ident)) shift :rparen code :expression, out end end |
#_compile_lparen_method_final(ident = nil) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 155 def _compile_lparen_method_final(ident = nil) components = [ident].compact _build_set set(ident[0]) if ident while peek?(:comma) components << _compile_lparen_argument end @set.pop 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.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 76 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
57 58 59 60 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 57 def compile_binop(left) code :binop, shift(:binop, :minus, :plus), left, compile_vexpression end |
#compile_directive ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 109 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 } out = if old directive else handle_directive(directive) end @in_directive = old out 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 14 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 10 def compile_expression expect :if, :unless, :class, :module, :loop, :for, :while, :action, :try, :return, :colon => :directive, :_ => :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.
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 97 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
45 46 47 48 49 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 45 def compile_minus shift :minus code :neg, compile_vexpression end |
#compile_plus ⇒ Object
51 52 53 54 55 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 51 def compile_plus shift :plus code :pos, compile_vexpression end |
#compile_return ⇒ Object
66 67 68 69 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 66 def compile_return shift :return code :return, compile_vexpression end |
#compile_unop ⇒ Object
62 63 64 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 62 def compile_unop code :unop, shift(:unop, :preunop), compile_vexpression end |
#compile_vexpression ⇒ ICR::Code
Compiles an expression that returns a value.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/liquidscript/compiler/icr/expressions.rb', line 19 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 |