Start on Item and ItemSet
This commit is contained in:
1 parent
6ce94e15af
commit
2e16b0bd6e
5 files changed
+86
No files matched your search
@@ -0,0 +1,33 @@
|
||||
class Imbecile
|
||||
class Parser
|
||||
|
||||
class Item
|
||||
|
||||
attr_reader :rule
|
||||
attr_reader :position
|
||||
|
||||
def initialize(rule, position)
|
||||
@rule = rule
|
||||
@position = position
|
||||
end
|
||||
|
||||
def next_component
|
||||
@rule.components[@position]
|
||||
end
|
||||
|
||||
def hash
|
||||
[@rule, @position].hash
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
@rule == other.rule && @position == other.position
|
||||
end
|
||||
|
||||
def eql?(other)
|
||||
self == other
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,26 @@
|
||||
class Imbecile
|
||||
class Parser
|
||||
|
||||
class ItemSet
|
||||
|
||||
def initialize(items)
|
||||
@items = Set.new(items)
|
||||
end
|
||||
|
||||
def close!
|
||||
eval_items = @items
|
||||
while eval_items.size > 0
|
||||
this_eval_items = eval_items
|
||||
eval_items = Set.new
|
||||
this_eval_items.each do |item|
|
||||
if item.next_component.is_a?(Rule)
|
||||
end
|
||||
end
|
||||
@items += eval_items
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user