diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1c2fe482..1ca4a6e9 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -57,7 +57,7 @@ jobs: - name: Check for parser.rb is up to date run: | - bundle exec rake build:racc_parser + bundle exec rake build:parser git diff --color --no-ext-diff --ignore-submodules --exit-code lib/lrama/parser.rb steep-check: runs-on: ubuntu-20.04 diff --git a/Rakefile b/Rakefile index bc713a27..d1d5a570 100644 --- a/Rakefile +++ b/Rakefile @@ -1,13 +1,8 @@ require "bundler/gem_tasks" namespace "build" do - desc "build parser from parser.y by using Racc" - task :racc_parser do - sh "bundle exec racc parser.y --embedded -o lib/lrama/parser.rb" - end - - desc "build parser for debugging" - task :racc_verbose_parser do + desc "build parser from parser.y" + task :parser do sh "bundle exec racc parser.y --embedded -o lib/lrama/parser.rb -t --log-file=parser.output" end end diff --git a/lib/lrama/command.rb b/lib/lrama/command.rb index afaecda5..ee3c1d31 100644 --- a/lib/lrama/command.rb +++ b/lib/lrama/command.rb @@ -8,7 +8,7 @@ def run(argv) warning = Lrama::Warning.new text = options.y.read options.y.close if options.y != STDIN - grammar = Lrama::Parser.new(text, options.grammar_file).parse + grammar = Lrama::Parser.new(text, options.grammar_file, options.debug).parse states = Lrama::States.new(grammar, warning, trace_state: (options.trace_opts[:automaton] || options.trace_opts[:closure])) states.compute context = Lrama::Context.new(states) diff --git a/lib/lrama/option_parser.rb b/lib/lrama/option_parser.rb index b0415cdf..e52d03bf 100644 --- a/lib/lrama/option_parser.rb +++ b/lib/lrama/option_parser.rb @@ -58,6 +58,7 @@ def parse_by_option_parser(argv) o.separator 'Tuning the Parser:' o.on('-S', '--skeleton=FILE', 'specify the skeleton to use') {|v| @options.skeleton = v } o.on('-t', 'reserved, do nothing') { } + o.on('--debug', 'display debugging outputs of internal parser') {|v| @options.debug = true } o.separator '' o.separator 'Output:' o.on('-H', '--header=[FILE]', 'also produce a header file named FILE') {|v| @options.header = true; @options.header_file = v } diff --git a/lib/lrama/options.rb b/lib/lrama/options.rb index 01b3e701..007661f6 100644 --- a/lib/lrama/options.rb +++ b/lib/lrama/options.rb @@ -4,7 +4,8 @@ class Options attr_accessor :skeleton, :header, :header_file, :report_file, :outfile, :error_recovery, :grammar_file, - :report_file, :trace_opts, :report_opts, :y + :report_file, :trace_opts, :report_opts, :y, + :debug def initialize @skeleton = "bison/yacc.c" diff --git a/lib/lrama/parser.rb b/lib/lrama/parser.rb index 96d0bd46..2448726d 100644 --- a/lib/lrama/parser.rb +++ b/lib/lrama/parser.rb @@ -672,9 +672,10 @@ class Parser < Racc::Parser include Lrama::Report::Duration -def initialize(text, path) +def initialize(text, path, debug = false) @text = text @path = path + @yydebug = debug end def parse @@ -1102,7 +1103,7 @@ def on_error(error_token_id, error_value, value_stack) "generic_symlist_item" ] Ractor.make_shareable(Racc_token_to_s_table) if defined?(Ractor) -Racc_debug_parser = false +Racc_debug_parser = true ##### State transition tables end ##### diff --git a/parser.y b/parser.y index 47253c65..18c59f8f 100644 --- a/parser.y +++ b/parser.y @@ -388,9 +388,10 @@ end include Lrama::Report::Duration -def initialize(text, path) +def initialize(text, path, debug = false) @text = text @path = path + @yydebug = debug end def parse diff --git a/spec/lrama/option_parser_spec.rb b/spec/lrama/option_parser_spec.rb index 023720d3..2bf12ca2 100644 --- a/spec/lrama/option_parser_spec.rb +++ b/spec/lrama/option_parser_spec.rb @@ -47,6 +47,7 @@ Tuning the Parser: -S, --skeleton=FILE specify the skeleton to use -t reserved, do nothing + --debug display debugging outputs of internal parser Output: -H, --header=[FILE] also produce a header file named FILE