#
# $Id: grammarfileparser.rb.in,v 1.5 2005/11/20 17:31:32 aamine Exp $
#
# Copyright (c) 1999-2005 Minero Aoki
#
# This program is free software.
# You can distribute/modify this program under the terms of
# the GNU LGPL, Lesser General Public License version 2.1.
# For details of the GNU LGPL, see the file "COPYING".
#

require 'racc/compat'
require 'racc/parser'
require 'racc/grammarfilescanner'
require 'racc/usercodeparser'
require 'racc/exception'

module Racc

  class GrammarFileParser < Parser

    def initialize(racc)
      @yydebug     = racc.d_parse && Racc_debug_parser
      @ruletable   = racc.ruletable
      @symboltable = racc.symboltable

      @class_name = nil
      @super_class = nil
    end

    attr_reader :class_name
    attr_reader :super_class

    def parse(str)
      @scanner = GrammarFileScanner.new(str)
      @scanner.debug = @yydebug
      do_parse
    end

    private

    def next_token
      @scanner.scan
    end

    def on_error(tok, val, _values)
      if val.respond_to?(:id2name)
        v = val.id2name
      elsif String === val
        v = val
      else
        v = val.inspect
      end
      raise CompileError, "#{@scanner.lineno}: unexpected token '#{v}'"
    end

    STATE_TRANSITION_TABLE

  end

end   # module Racc
