diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2019-05-13 21:25:22 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2019-06-19 18:17:25 +0900 |
commit | 1a2546c2be839baa7d0a50dc056d4d6987d26852 (patch) | |
tree | 19fef5d8b8d96452a51ab68e8093ea895192ca27 /lib/racc/parser.rb | |
parent | cbe06cd3501fdadd0e6e63094da2973484d70b0b (diff) | |
download | ruby-1a2546c2be839baa7d0a50dc056d4d6987d26852.tar.gz |
Backport racc-1.4.15 from upstream.
Diffstat (limited to 'lib/racc/parser.rb')
-rw-r--r-- | lib/racc/parser.rb | 85 |
1 files changed, 50 insertions, 35 deletions
diff --git a/lib/racc/parser.rb b/lib/racc/parser.rb index 0cdb42e49d..41740ade39 100644 --- a/lib/racc/parser.rb +++ b/lib/racc/parser.rb @@ -1,7 +1,5 @@ # frozen_string_literal: false #-- -# $originalId: parser.rb,v 1.8 2006/07/06 11:42:07 aamine Exp $ -# # Copyright (c) 1999-2006 Minero Aoki # # This program is free software. @@ -12,6 +10,12 @@ # without restriction. #++ +require 'racc/info' + +unless defined?(NotImplementedError) + NotImplementedError = NotImplementError # :nodoc: +end + module Racc class ParseError < StandardError; end end @@ -49,12 +53,12 @@ end # [-v, --verbose] # verbose mode. create +filename+.output file, like yacc's y.output file. # [-g, --debug] -# add debug code to parser class. To display debugging information, +# add debug code to parser class. To display debuggin information, # use this '-g' option and set @yydebug true in parser class. # [-E, --embedded] # Output parser which doesn't need runtime files (racc/parser.rb). # [-C, --check-only] -# Check syntax of racc grammar file and quit. +# Check syntax of racc grammer file and quit. # [-S, --output-status] # Print messages time to time while compiling. # [-l, --no-line-convert] @@ -171,29 +175,34 @@ end # This command creates myparser.rb which `includes' Racc runtime. # Only you must do is to distribute your parser file (myparser.rb). # -# Note: parser.rb is LGPL, but your parser is not. +# Note: parser.rb is ruby license, but your parser is not. # Your own parser is completely yours. module Racc - unless defined?(Racc_No_Extensions) - Racc_No_Extensions = false # :nodoc: + unless defined?(Racc_No_Extentions) + 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 = ::Racc::VERSION + Racc_Runtime_Revision = '$Id: 87af5c09d4467cae567837b4162ec2145417a90e $' - Racc_Runtime_Core_Version_R = '1.4.6' - Racc_Runtime_Core_Revision_R = %w$originalRevision: 1.8 $[1] + Racc_Runtime_Core_Version_R = ::Racc::VERSION + Racc_Runtime_Core_Revision_R = '$Id: 87af5c09d4467cae567837b4162ec2145417a90e $'.split[1] begin - require 'racc/cparse' - # Racc_Runtime_Core_Version_C = (defined in extension) + if Object.const_defined?(:RUBY_ENGINE) and RUBY_ENGINE == 'jruby' + require 'racc/cparse-jruby.jar' + com.headius.racc.Cparse.new.load(JRuby.runtime, false) + else + require 'racc/cparse' + end + # Racc_Runtime_Core_Version_C = (defined in extention) Racc_Runtime_Core_Revision_C = Racc_Runtime_Core_Id_C.split[2] unless new.respond_to?(:_racc_do_parse_c, true) raise LoadError, 'old cparse.so' end - if Racc_No_Extensions + if Racc_No_Extentions raise LoadError, 'selecting ruby version of racc runtime core' end @@ -203,6 +212,8 @@ module Racc Racc_Runtime_Core_Revision = Racc_Runtime_Core_Revision_C # :nodoc: Racc_Runtime_Type = 'c' # :nodoc: rescue LoadError +puts $! +puts $!.backtrace Racc_Main_Parsing_Routine = :_racc_do_parse_rb Racc_YY_Parse_Method = :_racc_yyparse_rb Racc_Runtime_Core_Version = Racc_Runtime_Core_Version_R @@ -255,9 +266,11 @@ module Racc # def next_token # @q.shift # end + class_eval %{ def do_parse - __send__(Racc_Main_Parsing_Routine, _racc_setup(), false) + #{Racc_Main_Parsing_Routine}(_racc_setup(), false) end + } # The method to fetch next token. # If you use #do_parse method, you must implement #next_token. @@ -274,8 +287,7 @@ module Racc def _racc_do_parse_rb(arg, in_debug) action_table, action_check, action_default, action_pointer, _, _, _, _, - _, _, token_table, _, - _, _, * = arg + _, _, token_table, * = arg _racc_init_sysvars tok = act = i = nil @@ -316,19 +328,18 @@ module Racc # # RECEIVER#METHOD_ID is a method to get next token. # It must 'yield' the token, which format is [TOKEN-SYMBOL, VALUE]. + class_eval %{ def yyparse(recv, mid) - __send__(Racc_YY_Parse_Method, recv, mid, _racc_setup(), true) + #{Racc_YY_Parse_Method}(recv, mid, _racc_setup(), true) end + } def _racc_yyparse_rb(recv, mid, arg, c_debug) action_table, action_check, action_default, action_pointer, - _, _, _, _, - _, _, token_table, _, - _, _, * = arg + _, _, _, _, + _, _, token_table, * = arg _racc_init_sysvars - act = nil - i = nil catch(:racc_end_parse) { until i = action_pointer[@racc_state[-1]] @@ -355,9 +366,9 @@ module Racc ; end - while not(i = action_pointer[@racc_state[-1]]) or - not @racc_read_next or - @racc_t == 0 # $ + while !(i = action_pointer[@racc_state[-1]]) || + ! @racc_read_next || + @racc_t == 0 # $ unless i and i += @racc_t and i >= 0 and act = action_table[i] and @@ -378,16 +389,17 @@ module Racc def _racc_evalact(act, arg) action_table, action_check, _, action_pointer, - _, _, _, _, - _, _, _, shift_n, reduce_n, - _, _, * = arg + _, _, _, _, + _, _, _, shift_n, + reduce_n, * = arg + nerr = 0 # tmp if act > 0 and act < shift_n # # shift # if @racc_error_status > 0 - @racc_error_status -= 1 unless @racc_t == 1 # error token + @racc_error_status -= 1 unless @racc_t <= 1 # error token or EOF end @racc_vstack.push @racc_val @racc_state.push act @@ -431,10 +443,13 @@ module Racc case @racc_error_status when 0 unless arg[21] # user_yyerror + nerr += 1 on_error @racc_t, @racc_val, @racc_vstack end when 3 if @racc_t == 0 # is $ + # We're at EOF, and another error occurred immediately after + # attempting auto-recovery throw :racc_end_parse, nil end @racc_read_next = true @@ -470,10 +485,11 @@ module Racc end def _racc_do_reduce(arg, act) - _, _, _, _, - goto_table, goto_check, goto_default, goto_pointer, - nt_base, reduce_table, _, _, - _, use_result, * = arg + _, _, _, _, + goto_table, goto_check, goto_default, goto_pointer, + nt_base, reduce_table, _, _, + _, use_result, * = arg + state = @racc_state vstack = @racc_vstack tstack = @racc_tstack @@ -569,7 +585,6 @@ module Racc toks.each {|t| out.print ' ', racc_token2str(t) } end out.puts " --> #{racc_token2str(sim)}" - racc_print_stacks tstack, vstack @racc_debug_out.puts end |