Module: Liquidscript::Compiler::ICR::Literals

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

Instance Method Summary collapse

Instance Method Details

#compile_arrayObject



63
64
65
66
67
68
69
70
# File 'lib/liquidscript/compiler/icr/literals.rb', line 63

def compile_array
  shift :lbrace

  parts = collect_compiles(:vexpression, :rbrace,
    :comma => action.shift)

  code :array, parts
end

#compile_functionObject



79
80
81
# File 'lib/liquidscript/compiler/icr/literals.rb', line 79

def compile_function
  compile_function_with_parameters([])
end

#compile_function_with_parameters(parameters) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/liquidscript/compiler/icr/literals.rb', line 90

def compile_function_with_parameters(parameters)
  shift :arrow
  shift :lbrack

  expressions = Liquidscript::ICR::Set.new
  expressions.context = Liquidscript::ICR::Context.new
  expressions.context.parent = top.context
  expressions[:arguments] = parameters
  @set << expressions

  parameters.each do |parameter|
    set(parameter).parameter!
  end


  expression = action do
    expressions << compile_expression
  end

  loop do
    expect :rbrack => action.end_loop,
           :_      => expression
  end

  code :function, @set.pop
end

#compile_identifier(identifier) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/liquidscript/compiler/icr/literals.rb', line 10

def compile_identifier(identifier)
  default = action do
    code :get, ref(identifier)
  end

  expect :equal  => action { compile_assignment(identifier) },
         :prop   => action { compile_property(identifier)   },
         :lparen => action { compile_call(identifier)       },
         :_      => default
end

#compile_istringObject



35
36
37
# File 'lib/liquidscript/compiler/icr/literals.rb', line 35

def compile_istring
  code :istring, shift(:istring).value
end

#compile_istring_beginObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/liquidscript/compiler/icr/literals.rb', line 21

def compile_istring_begin
  start = shift :istring_begin
  contents = [start]

  loop do
    contents << compile_vexpression
    contents << shift(:istring)
    peek?(:istring_begin)
  end


  code :interop, *contents
end

#compile_keywordObject



47
48
49
# File 'lib/liquidscript/compiler/icr/literals.rb', line 47

def compile_keyword
  code :keyword, shift(:keyword)
end

#compile_newlineObject



83
84
85
86
87
88
# File 'lib/liquidscript/compiler/icr/literals.rb', line 83

def compile_newline
  if peek?(:newline)
    pop
    code :newline
  end
end

#compile_numberObject



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

def compile_number
  code :number, pop.value
end

#compile_objectObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/liquidscript/compiler/icr/literals.rb', line 51

def compile_object
  shift :lbrack

  objects = collect_compiles :rbrack,
    :comma => action.shift,
    :newline => action.shift do
    [compile_object_key, compile_vexpression]
  end

  code :object, objects
end

#compile_object_keyObject



72
73
74
75
76
77
# File 'lib/liquidscript/compiler/icr/literals.rb', line 72

def compile_object_key
  key = shift :identifier, :dstring
  shift :colon

  key
end

#compile_operatorObject



43
44
45
# File 'lib/liquidscript/compiler/icr/literals.rb', line 43

def compile_operator
  code :operator, shift(:operator), compile_vexpression
end

#compile_sstringObject



39
40
41
# File 'lib/liquidscript/compiler/icr/literals.rb', line 39

def compile_sstring
  code :sstring, shift(:sstring).value[1..-1]
end