Compare commits
4 Commits
d6e5c4325d
...
0f1c00d1a6
Author | SHA1 | Date | |
---|---|---|---|
0f1c00d1a6 | |||
291509f005 | |||
c1769503a8 | |||
8b152abaa7 |
@ -72,6 +72,15 @@ class Propane
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Return whether the item is "complete", meaning that the parse position
|
||||||
|
# marker is at the end of the rule.
|
||||||
|
#
|
||||||
|
# @return [Boolean]
|
||||||
|
# Whether the item is "complete".
|
||||||
|
def complete?
|
||||||
|
@position == @rule.components.size
|
||||||
|
end
|
||||||
|
|
||||||
# Get the following symbol for the Item.
|
# Get the following symbol for the Item.
|
||||||
#
|
#
|
||||||
# That is, the symbol which follows the parse position marker in the
|
# That is, the symbol which follows the parse position marker in the
|
||||||
|
@ -17,8 +17,8 @@ class Propane
|
|||||||
# Maps a following symbol to its ItemSet.
|
# Maps a following symbol to its ItemSet.
|
||||||
attr_reader :following_item_set
|
attr_reader :following_item_set
|
||||||
|
|
||||||
# @return [Set]
|
# @return [Set<ItemSet>]
|
||||||
# Item sets leading to this item set.
|
# ItemSets leading to this item set.
|
||||||
attr_reader :in_sets
|
attr_reader :in_sets
|
||||||
|
|
||||||
# Build an ItemSet.
|
# Build an ItemSet.
|
||||||
@ -81,6 +81,18 @@ class Propane
|
|||||||
self == other
|
self == other
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Set of ItemSets that lead to this ItemSet.
|
||||||
|
#
|
||||||
|
# This set includes this ItemSet.
|
||||||
|
#
|
||||||
|
# @return [Set<ItemSet>]
|
||||||
|
# Set of all ItemSets that lead up to this ItemSet.
|
||||||
|
def leading_item_sets
|
||||||
|
@in_sets.reduce(Set[self]) do |result, item_set|
|
||||||
|
result + item_set.leading_item_sets
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Represent the ItemSet as a String.
|
# Represent the ItemSet as a String.
|
||||||
#
|
#
|
||||||
# @return [String]
|
# @return [String]
|
||||||
|
@ -42,6 +42,16 @@ class Propane
|
|||||||
@line_number = line_number
|
@line_number = line_number
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Return whether the Rule is empty.
|
||||||
|
#
|
||||||
|
# A Rule is empty if it has no components.
|
||||||
|
#
|
||||||
|
# @return [Boolean]
|
||||||
|
# Whether the Rule is empty.
|
||||||
|
def empty?
|
||||||
|
@components.empty?
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -2,17 +2,41 @@ class Propane
|
|||||||
|
|
||||||
class RuleSet
|
class RuleSet
|
||||||
|
|
||||||
|
# @return [String]
|
||||||
|
# Name of the RuleSet.
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
|
|
||||||
|
# @return [Array<Rule>]
|
||||||
|
# Rules in the RuleSet.
|
||||||
attr_reader :rules
|
attr_reader :rules
|
||||||
|
|
||||||
|
# Construct a RuleSet.
|
||||||
|
#
|
||||||
|
# @param name [String]
|
||||||
|
# Name of the RuleSet.
|
||||||
def initialize(name)
|
def initialize(name)
|
||||||
@name = name
|
@name = name
|
||||||
@rules = []
|
@rules = []
|
||||||
|
@could_be_empty = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Add a Rule to the RuleSet.
|
||||||
|
#
|
||||||
|
# @param rule [Rule]
|
||||||
|
# Rule to add.
|
||||||
def <<(rule)
|
def <<(rule)
|
||||||
@rules << rule
|
@rules << rule
|
||||||
|
if rule.empty?
|
||||||
|
@could_be_empty = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Return whether any Rule in the RuleSet is empty.
|
||||||
|
#
|
||||||
|
# @return [Boolean]
|
||||||
|
# Whether any rule in the RuleSet is empty.
|
||||||
|
def could_be_empty?
|
||||||
|
@could_be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user