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

Add types to states #463

Merged
merged 3 commits into from
Jul 30, 2024
Merged
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
1 change: 1 addition & 0 deletions Steepfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ target :lib do
check "lib/lrama/lexer"
check "lib/lrama/report"
check "lib/lrama/state"
check "lib/lrama/states"
check "lib/lrama/bitmap.rb"
check "lib/lrama/digraph.rb"
check "lib/lrama/grammar.rb"
Expand Down
6 changes: 3 additions & 3 deletions lib/lrama/states/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ def new_by_next_position
Item.new(rule: rule, position: position + 1)
end

def symbols_before_dot
def symbols_before_dot # steep:ignore
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array#[] is nullable but symbols_before_dot and symbols_after_dot are not.
But I couldn't make Array#[] temporarily not null, so I added steep:ignore .

rhs[0...position]
end

def symbols_after_dot
def symbols_after_dot # steep:ignore
rhs[position..-1]
end

Expand All @@ -75,7 +75,7 @@ def display_name

# Right after position
def display_rest
r = rhs[position..-1].map(&:display_name).join(" ")
r = symbols_after_dot.map(&:display_name).join(" ")
". #{r} (rule #{rule_id})"
end
end
Expand Down
5 changes: 5 additions & 0 deletions sig/lrama/grammar/rule.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ module Lrama
def with_actions: -> String

def contains_at_reference?: -> bool

interface _DelegatedMethods
def lhs: -> Grammar::Symbol
def rhs: -> Array[Grammar::Symbol]
end
end
end
end
48 changes: 17 additions & 31 deletions sig/lrama/states/item.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,28 @@ module Lrama
class States
class Item
extend Forwardable
include Grammar::Rule::_DelegatedMethods

attr_accessor rule: untyped
attr_accessor rule: Grammar::Rule
attr_accessor position: Integer

# Optimization for States#setup_state
def hash: () -> untyped

def rule_id: () -> untyped

def empty_rule?: () -> untyped

def number_of_rest_symbols: () -> untyped

def next_sym: () -> untyped

def next_next_sym: () -> untyped

def previous_sym: () -> untyped

def end_of_rule?: () -> untyped

def beginning_of_rule?: () -> untyped

def start_item?: () -> untyped

def new_by_next_position: () -> untyped

def symbols_before_dot: () -> untyped

def symbols_after_dot: () -> untyped

def initialize: (?rule: Grammar::Rule, ?position: Integer) -> void

def hash: () -> Integer
def rule_id: () -> Integer
def empty_rule?: () -> bool
def number_of_rest_symbols: () -> Integer
def next_sym: () -> Grammar::Symbol
def next_next_sym: () -> Grammar::Symbol
def previous_sym: () -> Grammar::Symbol
def end_of_rule?: () -> bool
def beginning_of_rule?: () -> bool
def start_item?: () -> bool
def new_by_next_position: () -> States::Item
def symbols_before_dot: () -> Array[Grammar::Symbol]
def symbols_after_dot: () -> Array[Grammar::Symbol]
def to_s: () -> ::String

def display_name: () -> ::String

# Right after position
def display_rest: () -> ::String
end
end
Expand Down