Class: Dhaka::ReduceAction

Inherits:
Action
  • Object
show all
Defined in:
lib/dhaka/parser/action.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Attributes inherited from Action

#action_code

Instance Method Summary collapse

Constructor Details

#initialize(production) ⇒ ReduceAction

Returns a new instance of ReduceAction.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dhaka/parser/action.rb', line 29

def initialize(production)
  @production  = production
  @action_code = Proc.new do
    composite_node = ParseTreeCompositeNode.new(production)

    production.expansion.each do |symbol|
      state_stack.pop
      composite_node.child_nodes.unshift(node_stack.pop)
    end

    node_stack << composite_node.instance_eval(&production.action)

    unless composite_node.head_node?
      @symbol_queue.concat [@current_token.symbol_name, production.symbol.name]
    end
  end
end

Instance Attribute Details

#productionObject (readonly)

Returns the value of attribute production.



27
28
29
# File 'lib/dhaka/parser/action.rb', line 27

def production
  @production
end

Instance Method Details

#compile_to_ruby_sourceObject



47
48
49
# File 'lib/dhaka/parser/action.rb', line 47

def compile_to_ruby_source
  "reduce_with #{production.name.inspect}"
end

#to_sObject



51
52
53
# File 'lib/dhaka/parser/action.rb', line 51

def to_s
  "Reduce with #{production}"
end