Skip to content

Commit

Permalink
Merge pull request #426 from S-H-GAMELINKS/rename/grammar-rule-to-s
Browse files Browse the repository at this point in the history
Rename Lrama::Grammar::Rule#to_s to Lrama::Grammar:Rule::display_name
  • Loading branch information
ydah authored Jun 2, 2024
2 parents df614b4 + f152309 commit a931061
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
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

0 comments on commit a931061

Please sign in to comment.