lib/lrama/states_reporter.rb in lrama-0.5.4 vs lib/lrama/states_reporter.rb in lrama-0.5.5

- old
+ new

@@ -108,11 +108,10 @@ io << sprintf("%5i %s %s%s\n", rule.id, l, r, la) end io << "\n" - # Report shifts tmp = state.term_transitions.select do |shift, _| !shift.not_selected end.map do |shift, next_state| [shift.next_sym, next_state.id] @@ -121,11 +120,10 @@ tmp.each do |term, state_id| io << " #{term.display_name.ljust(max_len)} shift, and go to state #{state_id}\n" end io << "\n" if !tmp.empty? - # Report error caused by %nonassoc nl = false tmp = state.resolved_conflicts.select do |resolved| resolved.which == :error end.map do |error| @@ -136,11 +134,10 @@ nl = true io << " #{name.ljust(max_len)} error (nonassociative)\n" end io << "\n" if !tmp.empty? - # Report reduces nl = false max_len = state.non_default_reduces.flat_map(&:look_ahead).compact.map(&:display_name).map(&:length).max || 0 max_len = [max_len, "$default".length].max if state.default_reduction_rule ary = [] @@ -169,11 +166,10 @@ io << " #{s} reduce using rule #{r.id} (#{r.lhs.display_name})\n" end end io << "\n" if nl - # Report nonterminal transitions tmp = [] max_len = 0 state.nterm_transitions.each do |shift, next_state| nterm = shift.next_sym @@ -187,11 +183,10 @@ tmp.each do |nterm, state_id| io << " #{nterm.id.s_value.ljust(max_len)} go to state #{state_id}\n" end io << "\n" if !tmp.empty? - if solved # Report conflict resolutions state.resolved_conflicts.each do |resolved| io << " #{resolved.report_message}\n" end @@ -200,17 +195,17 @@ if counterexamples && state.has_conflicts? # Report counterexamples examples = cex.compute(state) examples.each do |example| - label0 = example.type == :shift_reduce ? "shift/reduce" : "reduce/reduce" + label0 = example.type == :shift_reduce ? "shift/reduce" : "reduce/reduce" label1 = example.type == :shift_reduce ? "Shift derivation" : "First Reduce derivation" label2 = example.type == :shift_reduce ? "Reduce derivation" : "Second Reduce derivation" io << " #{label0} conflict on token #{example.conflict_symbol.id.s_value}:\n" - io << " #{example.path1_item.to_s}\n" - io << " #{example.path2_item.to_s}\n" + io << " #{example.path1_item}\n" + io << " #{example.path2_item}\n" io << " #{label1}\n" example.derivations1.render_strings_for_report.each do |str| io << " #{str}\n" end io << " #{label2}\n" @@ -232,11 +227,10 @@ str = terms.map {|sym| sym.id.s_value }.join(", ") io << " read #{nterm.id.s_value} shift #{str}\n" end io << "\n" - # Report reads_relation io << " [Reads Relation]\n" @states.nterms.each do |nterm| a = @states.reads_relation[[state.id, nterm.token_id]] next if !a @@ -246,11 +240,10 @@ io << " (State #{state_id2}, #{n.id.s_value})\n" end end io << "\n" - # Report read_sets io << " [Read sets]\n" read_sets = @states.read_sets @states.nterms.each do |nterm| terms = read_sets[[state.id, nterm.token_id]] @@ -261,11 +254,10 @@ io << " #{sym.id.s_value}\n" end end io << "\n" - # Report includes_relation io << " [Includes Relation]\n" @states.nterms.each do |nterm| a = @states.includes_relation[[state.id, nterm.token_id]] next if !a @@ -275,25 +267,23 @@ io << " (State #{state.id}, #{nterm.id.s_value}) -> (State #{state_id2}, #{n.id.s_value})\n" end end io << "\n" - # Report lookback_relation io << " [Lookback Relation]\n" @states.rules.each do |rule| a = @states.lookback_relation[[state.id, rule.id]] next if !a a.each do |state_id2, nterm_id2| n = @states.nterms.find {|n| n.token_id == nterm_id2 } - io << " (Rule: #{rule.to_s}) -> (State #{state_id2}, #{n.id.s_value})\n" + io << " (Rule: #{rule}) -> (State #{state_id2}, #{n.id.s_value})\n" end end io << "\n" - # Report follow_sets io << " [Follow sets]\n" follow_sets = @states.follow_sets @states.nterms.each do |nterm| terms = follow_sets[[state.id, nterm.token_id]] @@ -304,11 +294,10 @@ io << " #{nterm.id.s_value} -> #{sym.id.s_value}\n" end end io << "\n" - # Report LA io << " [Look-Ahead Sets]\n" tmp = [] max_len = 0 @states.rules.each do |rule| @@ -323,10 +312,9 @@ io << " #{sym.id.s_value.ljust(max_len)} reduce using rule #{rule.id} (#{rule.lhs.id.s_value})\n" end end io << "\n" if !tmp.empty? end - # End of Report State io << "\n" end end