Module: Aurum::Engine::SemanticActionExecutable

Defined in:
lib/aurum/engine/parsing_facility.rb

Defined Under Namespace

Classes: Attributes, SemanticContext

Instance Method Summary collapse

Instance Method Details

#execute_semantic_action(lexer, handle, values) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/aurum/engine/parsing_facility.rb', line 64

def execute_semantic_action lexer, handle, values
  nonterminal_name = handle.nonterminal.name rescue handle.nonterminal
  context = {nonterminal_name => [Attributes.new]}
  handle.symbols.reverse.each_with_index do |symbol, index|
    name = symbol.name rescue symbol
    context[name] = [] unless context.has_key?(name)
    context[name] << values[-index-1]
  end
  mappings = (handle.mappings || {} rescue {})
  action = semantic_actions[handle.name]
  SemanticContext.new(@lexer, context, mappings).instance_eval(&action)
  context[nonterminal_name] ? context[nonterminal_name][0] : nil
end