Module: Liquidscript::Compiler::ICR::Helpers

Included in:
Liquidscript::Compiler::ICR
Defined in:
lib/liquidscript/compiler/icr/helpers.rb

Instance Method Summary collapse

Instance Method Details

#_compile_blockObject



25
26
27
28
29
30
31
32
# File 'lib/liquidscript/compiler/icr/helpers.rb', line 25

def _compile_block
  if peek?(:lbrace)
    shift :lbrace
    collect_compiles(:expression, :rbrace)
  else
    [compile_expression]
  end
end

#check(literal) ⇒ Object



14
15
16
17
18
19
# File 'lib/liquidscript/compiler/icr/helpers.rb', line 14

def check(literal)
  top.context.get(literal.value.intern,
    :dry_run => true)
rescue InvalidReferenceError
  false
end

#code(type, *args) ⇒ Object



21
22
23
# File 'lib/liquidscript/compiler/icr/helpers.rb', line 21

def code(type, *args)
  Liquidscript::ICR::Code.new type, *args
end

#ref(literal) ⇒ Object



6
7
8
# File 'lib/liquidscript/compiler/icr/helpers.rb', line 6

def ref(literal)
  top.context.get(literal.value.intern)
end

#set(literal) ⇒ Object



10
11
12
# File 'lib/liquidscript/compiler/icr/helpers.rb', line 10

def set(literal)
  top.context.set(literal.value.intern)
end

#value_expect(v, &default) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/liquidscript/compiler/icr/helpers.rb', line 34

def value_expect(v, &default)
  out = expect \
         :lparen => action { compile_call(v)       },
         :equal  => action { compile_assignment(v) },
         :prop   => action { compile_property(v)   },
         :lbrack => action { compile_access(v)     },
         :range  => action { |_| compile_range(v)  },
         :erange => action { |_| compile_erange(v) },
         [:binop,
          :minus,
          :plus] => action { compile_binop(v)      },
         :unop   => action { |o| code :op, v, o    },
         :_      => default || action { v          }

  if out != v
    value_expect(out)
  else
    out
  end
end