Project

General

Profile

Feature #6530 ยป 0001-Improve-racc-documentation-coverage.patch

zzak (zzak _), 06/02/2012 10:38 PM

View differences:

lib/racc/parser.rb
#
unless defined?(NotImplementedError)
NotImplementedError = NotImplementError
NotImplementedError = NotImplementError # :nodoc:
end
module Racc
......
ParseError = Racc::ParseError
end
# Racc is a LALR(1) parser generator.
# It is written in Ruby itself, and generates Ruby program.
#
# See Racc::Parser for the functions available to your parser.
#
# NOTE: Ruby 1.8.x comes with Racc runtime module. You
# can run your parsers generated by racc 1.4.x out of the
# box.
module Racc
unless defined?(Racc_No_Extentions)
Racc_No_Extentions = false
Racc_No_Extentions = false # :nodoc:
end
class Parser
Racc_Runtime_Version = '1.4.6'
Racc_Runtime_Revision = %w$originalRevision: 1.8 $[1]
Racc_Runtime_Version = '1.4.6' # :nodoc:
Racc_Runtime_Revision = %w$originalRevision: 1.8 $[1] # :nodoc:
Racc_Runtime_Core_Version_R = '1.4.6'
Racc_Runtime_Core_Revision_R = %w$originalRevision: 1.8 $[1]
Racc_Runtime_Core_Version_R = '1.4.6' # :nodoc:
Racc_Runtime_Core_Revision_R = %w$originalRevision: 1.8 $[1] # :nodoc:
begin
require 'racc/cparse'
# Racc_Runtime_Core_Version_C = (defined in extention)
......
raise LoadError, 'selecting ruby version of racc runtime core'
end
Racc_Main_Parsing_Routine = :_racc_do_parse_c
Racc_YY_Parse_Method = :_racc_yyparse_c
Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_C
Racc_Runtime_Core_Revision = Racc_Runtime_Core_Revision_C
Racc_Runtime_Type = 'c'
Racc_Main_Parsing_Routine = :_racc_do_parse_c # :nodoc:
Racc_YY_Parse_Method = :_racc_yyparse_c # :nodoc:
Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_C # :nodoc:
Racc_Runtime_Core_Revision = Racc_Runtime_Core_Revision_C # :nodoc:
Racc_Runtime_Type = 'c' # :nodoc:
rescue LoadError
Racc_Main_Parsing_Routine = :_racc_do_parse_rb
Racc_YY_Parse_Method = :_racc_yyparse_rb
......
Racc_Runtime_Type = 'ruby'
end
def Parser.racc_runtime_type
def Parser.racc_runtime_type # :nodoc:
Racc_Runtime_Type
end
......
###
class_eval %{
def do_parse
# The entry point of parser. This method is used with #next_token.
# If Racc wants to get token (and its value), calls next_token.
#
# Example:
# ---- inner
# def parse
# @q = [[1,1],
# [2,2],
# [3,3],
# [false, '$']]
# do_parse
# end
#
# def next_token
# @q.shift
# end
# --
def do_parse # :doc:
#{Racc_Main_Parsing_Routine}(_racc_setup(), false)
end
}
def next_token
# The method to fetch next token. If you use #do_parse method,
# you must implement #next_token. The format of return value is
# [TOKEN_SYMBOL, VALUE]. token-symbol is represented by Ruby's symbol
# by default, e.g. :IDENT for 'IDENT'. ";" (String) for ';'.
#
# The final symbol (End of file) must be false.
def next_token # :doc:
raise NotImplementedError, "#{self.class}\#next_token is not defined"
end
......
###
class_eval %{
def yyparse(recv, mid)
# The another entry point of parser.
# If you use this method, you must implement RECEIVER#METHOD_ID method.
#
# RECEIVER#METHOD_ID is a method to get next token.
# It must 'yield's token, which format is [TOKEN-SYMBOL, VALUE].
def yyparse(recv, mid) # :doc:
#{Racc_YY_Parse_Method}(recv, mid, _racc_setup(), true)
end
}
......
goto_default[k1]
end
def on_error(t, val, vstack)
# This method is called when parse error is found.
#
# ERROR_TOKEN_ID is an internal ID of token which caused error.
# You can get string replesentation of this ID by calling
# #token_to_str.
#
# ERROR_VALUE is a value of error token.
#
# value_stack is a stack of symbol values.
# DO NOT MODIFY this object.
#
# This method raises ParseError by default.
#
# If this method returns, parsers enter "error recovering mode".
def on_error(t, val, vstack) # :doc:
raise ParseError, sprintf("\nparse error on value %s (%s)",
val.inspect, token_to_str(t) || '?')
end
def yyerror
# Enter error recovering mode.
# This method does not call #on_error.
def yyerror # :doc:
throw :racc_jump, 1
end
def yyaccept
# Exit parser.
# Return value is Symbol_Value_Stack[0].
def yyaccept # :doc:
throw :racc_jump, 2
end
def yyerrok
# Leave error recovering mode.
def yyerrok # :doc:
@racc_error_status = 0
end
......
# for debugging output
#
def racc_read_token(t, tok, val)
def racc_read_token(t, tok, val) # :doc:
@racc_debug_out.print 'read '
@racc_debug_out.print tok.inspect, '(', racc_token2str(t), ') '
@racc_debug_out.puts val.inspect
@racc_debug_out.puts
end
def racc_shift(tok, tstack, vstack)
def racc_shift(tok, tstack, vstack) # :doc:
@racc_debug_out.puts "shift #{racc_token2str tok}"
racc_print_stacks tstack, vstack
@racc_debug_out.puts
end
def racc_reduce(toks, sim, tstack, vstack)
def racc_reduce(toks, sim, tstack, vstack) # :doc:
out = @racc_debug_out
out.print 'reduce '
if toks.empty?
......
@racc_debug_out.puts
end
def racc_accept
def racc_accept # :doc:
@racc_debug_out.puts 'accept'
@racc_debug_out.puts
end
def racc_e_pop(state, tstack, vstack)
def racc_e_pop(state, tstack, vstack) # :doc:
@racc_debug_out.puts 'error recovering mode: pop token'
racc_print_states state
racc_print_stacks tstack, vstack
@racc_debug_out.puts
end
def racc_next_state(curstate, state)
def racc_next_state(curstate, state) # :doc:
@racc_debug_out.puts "goto #{curstate}"
racc_print_states state
@racc_debug_out.puts
end
def racc_print_stacks(t, v)
def racc_print_stacks(t, v) # :doc:
out = @racc_debug_out
out.print ' ['
t.each_index do |i|
......
out.puts ' ]'
end
def racc_print_states(s)
def racc_print_states(s) # :doc:
out = @racc_debug_out
out.print ' ['
s.each {|st| out.print ' ', st }
out.puts ' ]'
end
def racc_token2str(tok)
def racc_token2str(tok) # :doc:
self.class::Racc_token_to_s_table[tok] or
raise "[Racc Bug] can't convert token #{tok} to string"
end
def token_to_str(t)
# Convert internal ID of token symbol to the string.
def token_to_str(t) # :doc:
self.class::Racc_token_to_s_table[t]
end
    (1-1/1)