Skip to content

Commit

Permalink
Use Lrama::States::Item methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Jan 24, 2024
1 parent 19cca53 commit 7c2e580
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/lrama/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def yysymbol_kind_t
def yyfinal
@states.states.find do |state|
state.items.find do |item|
item.rule.lhs.accept_symbol? && item.end_of_rule?
item.lhs.accept_symbol? && item.end_of_rule?
end
end.id
end
Expand Down
18 changes: 6 additions & 12 deletions lib/lrama/states_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,15 @@ def report_states(io, itemsets, lookaheads, solved, counterexamples, verbose)
last_lhs = nil
list = itemsets ? state.items : state.kernels
list.sort_by {|i| [i.rule_id, i.position] }.each do |item|
<<<<<<< Updated upstream
rule = item.rule
position = item.position
if rule.rhs.empty?
=======
if item.empty_rule?
>>>>>>> Stashed changes
r = "ε •"
else
r = rule.rhs.map(&:display_name).insert(position, "•").join(" ")
r = item.rhs.map(&:display_name).insert(item.position, "•").join(" ")
end
if rule.lhs == last_lhs
l = " " * rule.lhs.id.s_value.length + "|"
if item.lhs == last_lhs
l = " " * item.lhs.id.s_value.length + "|"
else
l = rule.lhs.id.s_value + ":"
l = item.lhs.id.s_value + ":"
end
la = ""
if lookaheads && item.end_of_rule?
Expand All @@ -108,9 +102,9 @@ def report_states(io, itemsets, lookaheads, solved, counterexamples, verbose)
la = " [#{look_ahead.map(&:display_name).join(", ")}]"
end
end
last_lhs = rule.lhs
last_lhs = item.lhs

io << sprintf("%5i %s %s%s\n", rule.id, l, r, la)
io << sprintf("%5i %s %s%s\n", item.rule_id, l, r, la)
end
io << "\n"

Expand Down

0 comments on commit 7c2e580

Please sign in to comment.