Skip to content

Render Splitted States information on output file #624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/lrama/reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def report(io, states)
@terms.report(io, states)
@conflicts.report(io, states)
@grammar.report(io, states)
@states.report(io, states)
@states.report(io, states, ielr: states.ielr_defined?)
end
end
end
Expand Down
21 changes: 19 additions & 2 deletions lib/lrama/reporter/states.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
@verbose = verbose
end

# @rbs (IO io, Lrama::States states) -> void
def report(io, states)
# @rbs (IO io, Lrama::States states, ielr: bool) -> void
def report(io, states, ielr: false)
cex = Counterexamples.new(states) if @counterexamples

report_splitted_states(io, states.states) if ielr

states.states.each do |state|
report_state_header(io, state)
report_items(io, state)
Expand All @@ -35,6 +37,21 @@

private

# @rbs (IO io, Array[Lrama::State] states) -> void
def report_splitted_states(io, states)
ss = states.select(&:splitted_state?)

return if ss.empty?

io << "Splitted States\n\n"

Check failure on line 46 in lib/lrama/reporter/states.rb

View workflow job for this annotation

GitHub Actions / CodeSpell

Splitted ==> Split

ss.each do |state|
io << " State #{state.id} is splitted from state #{state.lalr_isocore.id}\n"

Check failure on line 49 in lib/lrama/reporter/states.rb

View workflow job for this annotation

GitHub Actions / CodeSpell

splitted ==> split
end

io << "\n"
end

# @rbs (IO io, Lrama::State state) -> void
def report_state_header(io, state)
io << "State #{state.id}\n\n"
Expand Down
5 changes: 5 additions & 0 deletions lib/lrama/state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ def rr_conflicts
end
end

# @rbs () -> bool
def splitted_state?
@lalr_isocore != self
end

# Definition 3.40 (propagate_lookaheads)
#
# @rbs (State next_state) -> lookahead_set
Expand Down
2 changes: 1 addition & 1 deletion lib/lrama/states.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class States
include Lrama::Tracer::Duration

def_delegators "@grammar", :symbols, :terms, :nterms, :rules,
:accept_symbol, :eof_symbol, :undef_symbol, :find_symbol_by_s_value!
:accept_symbol, :eof_symbol, :undef_symbol, :find_symbol_by_s_value!, :ielr_defined?

attr_reader :states #: Array[State]
attr_reader :reads_relation #: Hash[transition, Array[transition]]
Expand Down
7 changes: 5 additions & 2 deletions sig/generated/lrama/reporter/states.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ module Lrama
# @rbs (itemsets: bool, lookaheads: bool, solved: bool, counterexamples: bool, verbose: bool, **untyped _) -> void
def initialize: (itemsets: bool, lookaheads: bool, solved: bool, counterexamples: bool, verbose: bool, **untyped _) -> void

# @rbs (IO io, Lrama::States states) -> void
def report: (IO io, Lrama::States states) -> void
# @rbs (IO io, Lrama::States states, ielr: bool) -> void
def report: (IO io, Lrama::States states, ielr: bool) -> void

private

# @rbs (IO io, Array[Lrama::State] states) -> void
def report_splitted_states: (IO io, Array[Lrama::State] states) -> void

# @rbs (IO io, Lrama::State state) -> void
def report_state_header: (IO io, Lrama::State state) -> void

Expand Down
3 changes: 3 additions & 0 deletions sig/generated/lrama/state.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ module Lrama
# @rbs () -> Array[conflict]
def rr_conflicts: () -> Array[conflict]

# @rbs () -> bool
def splitted_state?: () -> bool

# Definition 3.40 (propagate_lookaheads)
#
# @rbs (State next_state) -> lookahead_set
Expand Down
6 changes: 6 additions & 0 deletions spec/lrama/states_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1815,6 +1815,12 @@
Lrama::Reporter.new(states: true).report(io, states)

expect(io.string).to eq(<<~STR)
Splitted States

Check failure on line 1818 in spec/lrama/states_spec.rb

View workflow job for this annotation

GitHub Actions / CodeSpell

Splitted ==> Split

State 19 is splitted from state 4

Check failure on line 1820 in spec/lrama/states_spec.rb

View workflow job for this annotation

GitHub Actions / CodeSpell

splitted ==> split
State 20 is splitted from state 9

Check failure on line 1821 in spec/lrama/states_spec.rb

View workflow job for this annotation

GitHub Actions / CodeSpell

splitted ==> split
State 21 is splitted from state 14

Check failure on line 1822 in spec/lrama/states_spec.rb

View workflow job for this annotation

GitHub Actions / CodeSpell

splitted ==> split

State 0

0 $accept: • S "end of file"
Expand Down