Class: Prattle::AST::ArrayLiteral

Inherits:
Node
  • Object
show all
Defined in:
lib/prattle/ast/array_literal.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#run

Constructor Details

#initialize(elements) ⇒ ArrayLiteral

Returns a new instance of ArrayLiteral



10
11
12
# File 'lib/prattle/ast/array_literal.rb', line 10

def initialize(elements)
  @elements = elements
end

Instance Attribute Details

#elementsObject (readonly)

Returns the value of attribute elements



14
15
16
# File 'lib/prattle/ast/array_literal.rb', line 14

def elements
  @elements
end

Class Method Details

.grammar(g) ⇒ Object



16
17
18
19
20
# File 'lib/prattle/ast/array_literal.rb', line 16

def self.grammar(g)
  g.array_literal = g.seq("{", :sp, g.t(:expressions), :sp, "}") { |e|
    ArrayLiteral.new(e)
  }
end

.rule_nameObject



6
7
8
# File 'lib/prattle/ast/array_literal.rb', line 6

def self.rule_name
  "array"
end

Instance Method Details

#bytecode(g) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/prattle/ast/array_literal.rb', line 22

def bytecode(g)
  @elements.each do |e|
    e.bytecode(g)
  end

  g.make_array @elements.size
end