Module: Liquidscript::Compiler::ICR::Literals
- Included in:
- Liquidscript::Compiler::ICR
- Defined in:
- lib/liquidscript/compiler/icr/literals.rb
Instance Method Summary collapse
- #_compile_for_in(ident) ⇒ Object
- #_compile_for_seg(first) ⇒ Object
- #compile_action ⇒ Object
- #compile_array ⇒ Object
- #compile_erange(subject) ⇒ Object
- #compile_for ⇒ Object
- #compile_function ⇒ Object
- #compile_heredoc ⇒ Object
- #compile_href ⇒ Object
- #compile_identifier(identifier) ⇒ Object
- #compile_iheredoc_begin ⇒ Object
- #compile_istring ⇒ Object
- #compile_istring_begin ⇒ Object
- #compile_keyword ⇒ Object
- #compile_newline ⇒ Object
- #compile_number ⇒ Object
- #compile_object ⇒ Object
- #compile_object_key ⇒ Object
- #compile_operator ⇒ Object
- #compile_range(subject) ⇒ Object
- #compile_regex ⇒ Object
- #compile_sstring ⇒ Object
- #compile_while ⇒ Object
Instance Method Details
#_compile_for_in(ident) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/liquidscript/compiler/icr/literals.rb', line 60 def _compile_for_in(ident) content = shift :identifier unless content.value == "in" raise CompileError, "Expected `in', got #{content.value}" end obj = compile_vexpression shift :rparen v = set(ident) body = _compile_block code :for_in, v, obj, body end |
#_compile_for_seg(first) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/liquidscript/compiler/icr/literals.rb', line 74 def _compile_for_seg(first) first = value_expect(first) shift :comma second = compile_vexpression shift :comma third = compile_vexpression shift :rparen body = _compile_block code :for_seg, first, second, third, body end |
#compile_action ⇒ Object
23 24 25 |
# File 'lib/liquidscript/compiler/icr/literals.rb', line 23 def compile_action code :action, shift(:action) end |
#compile_array ⇒ Object
161 162 163 164 165 166 167 168 |
# File 'lib/liquidscript/compiler/icr/literals.rb', line 161 def compile_array shift :lbrack parts = collect_compiles(:vexpression, :rbrack, :comma => action.shift) code :array, parts end |
#compile_erange(subject) ⇒ Object
31 32 33 |
# File 'lib/liquidscript/compiler/icr/literals.rb', line 31 def compile_erange(subject) code :erange, subject, compile_vexpression end |
#compile_for ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/liquidscript/compiler/icr/literals.rb', line 44 def compile_for shift :for shift :lparen if peek?(:identifier) ident = shift :identifier if peek?(:identifier) _compile_for_in(ident) else _compile_for_seg(compile_identifier(ident)) end else compile_for_seg compile_vexpression end end |
#compile_function ⇒ Object
177 178 179 |
# File 'lib/liquidscript/compiler/icr/literals.rb', line 177 def compile_function compile_function_with_parameters([]) end |
#compile_heredoc ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/liquidscript/compiler/icr/literals.rb', line 107 def compile_heredoc h = shift(:heredoc, :iheredoc) top[:heredocs][top[:herenum]].body = [h] top[:herenum] += 1 nil end |
#compile_href ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/liquidscript/compiler/icr/literals.rb', line 98 def compile_href ref = shift :heredoc_ref, :iheredoc_ref heredoc = Heredoc.new(ref.value, ref.type == :iheredoc_ref) top[:heredocs] ||= [] top[:herenum] ||= 0 top[:heredocs] << heredoc code :href, heredoc end |
#compile_identifier(identifier) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/liquidscript/compiler/icr/literals.rb', line 86 def compile_identifier(identifier) if peek?(:equal) identifier else ref(identifier) end end |
#compile_iheredoc_begin ⇒ Object
115 116 117 118 119 120 121 122 123 |
# File 'lib/liquidscript/compiler/icr/literals.rb', line 115 def compile_iheredoc_begin start = shift :iheredoc_begin contents = [start] _compile_interop(:iheredoc, contents) top[:heredocs][top[:herenum]].body = contents top[:herenum] += 1 nil end |
#compile_istring ⇒ Object
133 134 135 |
# File 'lib/liquidscript/compiler/icr/literals.rb', line 133 def compile_istring code :istring, shift(:istring).value end |
#compile_istring_begin ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/liquidscript/compiler/icr/literals.rb', line 125 def compile_istring_begin start = shift :istring_begin contents = [start] _compile_interop(:istring, contents) code :interop, *contents end |
#compile_keyword ⇒ Object
145 146 147 |
# File 'lib/liquidscript/compiler/icr/literals.rb', line 145 def compile_keyword code :keyword, shift(:keyword) end |
#compile_newline ⇒ Object
181 182 183 184 185 186 |
# File 'lib/liquidscript/compiler/icr/literals.rb', line 181 def compile_newline if peek?(:newline) pop code :newline end end |
#compile_number ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/liquidscript/compiler/icr/literals.rb', line 6 def compile_number n = shift(:number) if peek?(:range, :erange) range = shift(:range, :erange) if peek?(:number) type = :"n#{range.type}" code(type, n.value, shift(:number).value) else send(:"compile_#{range.type}", code(:number, n.value)) end else code :number, n.value end end |
#compile_object ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/liquidscript/compiler/icr/literals.rb', line 149 def compile_object shift :lbrace objects = collect_compiles :rbrace, :comma => action.shift, :newline => action.shift do [compile_object_key, compile_vexpression] end code :object, objects end |
#compile_object_key ⇒ Object
170 171 172 173 174 175 |
# File 'lib/liquidscript/compiler/icr/literals.rb', line 170 def compile_object_key key = shift :identifier, :istring shift :colon key end |
#compile_operator ⇒ Object
141 142 143 |
# File 'lib/liquidscript/compiler/icr/literals.rb', line 141 def compile_operator code :operator, shift(:operator), compile_vexpression end |
#compile_range(subject) ⇒ Object
27 28 29 |
# File 'lib/liquidscript/compiler/icr/literals.rb', line 27 def compile_range(subject) code :range, subject, compile_vexpression end |
#compile_regex ⇒ Object
94 95 96 |
# File 'lib/liquidscript/compiler/icr/literals.rb', line 94 def compile_regex code :regex, shift(:regex) end |
#compile_sstring ⇒ Object
137 138 139 |
# File 'lib/liquidscript/compiler/icr/literals.rb', line 137 def compile_sstring code :sstring, shift(:sstring).value[1..-1] end |
#compile_while ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/liquidscript/compiler/icr/literals.rb', line 35 def compile_while shift :while shift :lparen conditional = compile_vexpression shift :rparen body = _compile_block code :while, conditional, body end |