From 7c2e580d366941e17e5f10d458164c389e2a3669 Mon Sep 17 00:00:00 2001 From: ydah <13041216+ydah@users.noreply.github.com> Date: Thu, 25 Jan 2024 01:31:46 +0900 Subject: [PATCH] Use Lrama::States::Item methods --- lib/lrama/context.rb | 2 +- lib/lrama/states_reporter.rb | 18 ++++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/lrama/context.rb b/lib/lrama/context.rb index 5ca28179..d796de12 100644 --- a/lib/lrama/context.rb +++ b/lib/lrama/context.rb @@ -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 diff --git a/lib/lrama/states_reporter.rb b/lib/lrama/states_reporter.rb index 6630abed..6a0b75d9 100644 --- a/lib/lrama/states_reporter.rb +++ b/lib/lrama/states_reporter.rb @@ -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? @@ -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"