Skip to content

Commit

Permalink
Add debug mode to command
Browse files Browse the repository at this point in the history
- Display Racc's debug output
- Set --debug flag to enable it
  • Loading branch information
junk0612 committed Oct 29, 2023
1 parent 9ec1aa6 commit c717dd1
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lib/lrama/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/lrama/option_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
3 changes: 2 additions & 1 deletion lib/lrama/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions lib/lrama/parser.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/lrama/option_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c717dd1

Please sign in to comment.