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

Use def_delegators in Lrama::States::Item #365

Merged
merged 1 commit into from
Jan 29, 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
14 changes: 6 additions & 8 deletions lib/lrama/states/item.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# TODO: Validate position is not over rule rhs

require "forwardable"

module Lrama
class States
class Item < Struct.new(:rule, :position, keyword_init: true)
extend Forwardable

def_delegators "rule", :lhs, :rhs

# Optimization for States#setup_state
def hash
[rule_id, position].hash
Expand All @@ -20,14 +26,6 @@ def number_of_rest_symbols
rhs.count - position
end

def lhs
rule.lhs
end

def rhs
rule.rhs
end

def next_sym
rhs[position]
end
Expand Down