Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Lrama::Grammar::Rule#to_s to Lrama::Grammar:Rule::display_name #426

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/lrama/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def run(argv)

if options.trace_opts && options.trace_opts[:rules]
puts "Grammar rules:"
puts grammar.rules
grammar.rules.each { |rule| puts rule.display_name }
end

if options.trace_opts && options.trace_opts[:actions]
Expand Down
2 changes: 1 addition & 1 deletion lib/lrama/grammar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def validate_rule_lhs_is_nterm!
rules.each do |rule|
next if rule.lhs.nterm?

errors << "[BUG] LHS of #{rule} (line: #{rule.lineno}) is term. It should be nterm."
errors << "[BUG] LHS of #{rule.display_name} (line: #{rule.lineno}) is term. It should be nterm."
end

return if errors.empty?
Expand Down
2 changes: 1 addition & 1 deletion lib/lrama/grammar/code/rule_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def lhs
end

def raise_tag_not_found_error(ref)
raise "Tag is not specified for '$#{ref.value}' in '#{@rule}'"
raise "Tag is not specified for '$#{ref.value}' in '#{@rule.display_name}'"
end
end
end
Expand Down
5 changes: 2 additions & 3 deletions lib/lrama/grammar/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ def ==(other)
self.lineno == other.lineno
end

# TODO: Change this to display_name
def to_s
def display_name
l = lhs.id.s_value
r = empty_rule? ? "ε" : rhs.map {|r| r.id.s_value }.join(" ")

Expand All @@ -33,7 +32,7 @@ def as_comment
end

def with_actions
"#{to_s} {#{token_code&.s_value}}"
"#{display_name} {#{token_code&.s_value}}"
end

# opt_nl: ε <-- empty_rule
Expand Down
2 changes: 1 addition & 1 deletion lib/lrama/states_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def report_states(io, itemsets, lookaheads, solved, counterexamples, verbose)

a.each do |state_id2, nterm_id2|
n = @states.nterms.find {|n| n.token_id == nterm_id2 }
io << " (Rule: #{rule}) -> (State #{state_id2}, #{n.id.s_value})\n"
io << " (Rule: #{rule.display_name}) -> (State #{state_id2}, #{n.id.s_value})\n"
end
end
io << "\n"
Expand Down
2 changes: 2 additions & 0 deletions sig/lrama/grammar/rule.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ module Lrama
?precedence_sym: Lexer::Token?, ?lineno: Integer?
) -> void

def display_name: () -> String

def as_comment: -> String

def empty_rule?: -> bool
Expand Down