class Racc::ParserClassGenerator

Public Class Methods

new(states) click to toggle source
# File racc-1.7.1/lib/racc/statetransitiontable.rb, line 263
def initialize(states)
  @states = states
  @grammar = states.grammar
end

Public Instance Methods

generate() click to toggle source
# File racc-1.7.1/lib/racc/statetransitiontable.rb, line 268
def generate
  table = @states.state_transition_table
  c = Class.new(::Racc::Parser)
  c.const_set :Racc_arg, [table.action_table,
                          table.action_check,
                          table.action_default,
                          table.action_pointer,
                          table.goto_table,
                          table.goto_check,
                          table.goto_default,
                          table.goto_pointer,
                          table.nt_base,
                          table.reduce_table,
                          table.token_value_table,
                          table.shift_n,
                          table.reduce_n,
                          false]
  c.const_set :Racc_token_to_s_table, table.token_to_s_table
  c.const_set :Racc_debug_parser, true
  define_actions c
  c
end

Private Instance Methods

define_actions(c) click to toggle source
# File racc-1.7.1/lib/racc/statetransitiontable.rb, line 293
    def define_actions(c)
      c.module_eval "def _reduce_none(vals, vstack) vals[0] end"
      @grammar.each do |rule|
        if rule.action.empty?
          c.alias_method("_reduce_#{rule.ident}", :_reduce_none)
        else
          c.define_method("_racc_action_#{rule.ident}", &rule.action.proc)
          c.module_eval(<<-End, __FILE__, __LINE__ + 1)
            def _reduce_#{rule.ident}(vals, vstack)
              _racc_action_#{rule.ident}(*vals)
            end
          End
        end
      end
    end