Skip to content
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

Refactor State#xxx_transitions #395

Merged
merged 1 commit into from
Apr 13, 2024
Merged
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
28 changes: 3 additions & 25 deletions lib/lrama/state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,38 +70,16 @@ def set_look_ahead(rule, look_ahead)
reduce.look_ahead = look_ahead
end

# Returns array of [Shift, next_state]
def nterm_transitions
return @nterm_transitions if @nterm_transitions

@nterm_transitions = []

shifts.each do |shift|
next if shift.next_sym.term?

@nterm_transitions << [shift, @items_to_state[shift.next_items]]
end

@nterm_transitions
@nterm_transitions ||= transitions.select {|shift, _| shift.next_sym.nterm? }
end

# Returns array of [Shift, next_state]
def term_transitions
return @term_transitions if @term_transitions

@term_transitions = []

shifts.each do |shift|
next if shift.next_sym.nterm?

@term_transitions << [shift, @items_to_state[shift.next_items]]
end

@term_transitions
@term_transitions ||= transitions.select {|shift, _| shift.next_sym.term? }
end

def transitions
term_transitions + nterm_transitions
@transitions ||= shifts.map {|shift| [shift, @items_to_state[shift.next_items]] }
end

def selected_term_transitions
Expand Down