lib/lrama/context.rb in lrama-0.6.9 vs lib/lrama/context.rb in lrama-0.6.10
- old
+ new
@@ -1,7 +1,9 @@
-require "lrama/report/duration"
+# frozen_string_literal: true
+require_relative "report/duration"
+
module Lrama
# This is passed to a template
class Context
include Report::Duration
@@ -251,11 +253,11 @@
end
end
# If no default_reduction_rule, default behavior is an
# error then replace ErrorActionNumber with zero.
- if !state.default_reduction_rule
+ unless state.default_reduction_rule
actions.map! do |e|
if e == ErrorActionNumber
0
else
e
@@ -299,20 +301,20 @@
nterm_to_next_states[key] << [state, next_state] # [from_state, to_state]
end
end
@states.nterms.each do |nterm|
- if !(states = nterm_to_next_states[nterm])
- default_goto = 0
- not_default_gotos = []
- else
+ if (states = nterm_to_next_states[nterm])
default_state = states.map(&:last).group_by {|s| s }.max_by {|_, v| v.count }.first
default_goto = default_state.id
not_default_gotos = []
states.each do |from_state, to_state|
next if to_state.id == default_goto
not_default_gotos << [from_state.id, to_state.id]
end
+ else
+ default_goto = 0
+ not_default_gotos = []
end
k = nterm_number_to_sequence_number(nterm.number)
@yydefgoto[k] = default_goto