-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #444 from ydah/refactor-trace-reporter
Introduce the `Lrama::TraceReporter` class to organize the command.rb
- Loading branch information
Showing
3 changed files
with
33 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module Lrama | ||
class TraceReporter | ||
def initialize(grammar) | ||
@grammar = grammar | ||
end | ||
|
||
def report(**options) | ||
_report(**options) | ||
end | ||
|
||
private | ||
|
||
def _report(rules: false, actions: false, **_) | ||
report_rules if rules | ||
report_actions if actions | ||
end | ||
|
||
def report_rules | ||
puts "Grammar rules:" | ||
@grammar.rules.each { |rule| puts rule.display_name } | ||
end | ||
|
||
def report_actions | ||
puts "Grammar rules with actions:" | ||
@grammar.rules.each { |rule| puts rule.with_actions } | ||
end | ||
end | ||
end |