Class: Rley::Parser::ParseState
- Inherits:
-
Object
- Object
- Rley::Parser::ParseState
- Defined in:
- lib/rley/parser/parse_state.rb
Instance Attribute Summary collapse
-
#dotted_rule ⇒ Object
readonly
Returns the value of attribute dotted_rule.
-
#origin ⇒ Object
readonly
the position in the input that matches the beginning of the rhs of the production.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Equality comparison.
-
#complete? ⇒ Boolean
Returns true if the dot is at the end of the rhs of the production.
-
#initialize(aDottedRule, theOrigin) ⇒ ParseState
constructor
A new instance of ParseState.
-
#next_symbol ⇒ Object
Next expected symbol in the production.
-
#precedes?(other) ⇒ Boolean
Does this parse state have the 'other' as successor?.
-
#predicted? ⇒ Boolean
Returns true if the dot is at the start of the rhs of the production.
-
#to_s ⇒ String
Give a String representation of itself.
Constructor Details
#initialize(aDottedRule, theOrigin) ⇒ ParseState
Returns a new instance of ParseState.
10 11 12 13 |
# File 'lib/rley/parser/parse_state.rb', line 10 def initialize(aDottedRule, theOrigin) @dotted_rule = valid_dotted_rule(aDottedRule) @origin = theOrigin end |
Instance Attribute Details
#dotted_rule ⇒ Object (readonly)
Returns the value of attribute dotted_rule.
4 5 6 |
# File 'lib/rley/parser/parse_state.rb', line 4 def dotted_rule @dotted_rule end |
#origin ⇒ Object (readonly)
the position in the input that matches the beginning of the rhs of the production.
8 9 10 |
# File 'lib/rley/parser/parse_state.rb', line 8 def origin @origin end |
Instance Method Details
#==(other) ⇒ Object
Equality comparison. A parse state behaves as a value object.
16 17 18 19 20 21 22 23 |
# File 'lib/rley/parser/parse_state.rb', line 16 def ==(other) return true if object_id == other.object_id result = (dotted_rule == other.dotted_rule) && (origin == other.origin) return result end |
#complete? ⇒ Boolean
Returns true if the dot is at the end of the rhs of the production. In other words, the complete rhs matches the input.
27 28 29 |
# File 'lib/rley/parser/parse_state.rb', line 27 def complete?() return dotted_rule.reduce_item? end |
#next_symbol ⇒ Object
Next expected symbol in the production
37 38 39 |
# File 'lib/rley/parser/parse_state.rb', line 37 def next_symbol() return dotted_rule.next_symbol end |
#precedes?(other) ⇒ Boolean
Does this parse state have the 'other' as successor?
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rley/parser/parse_state.rb', line 42 def precedes?(other) return false if self == other return false unless origin == other.origin other_production = other.dotted_rule.production return false unless dotted_rule.production == other_production prev_position = other.dotted_rule.prev_position result = if prev_position.nil? false else dotted_rule.position == prev_position end return result end |
#predicted? ⇒ Boolean
Returns true if the dot is at the start of the rhs of the production.
32 33 34 |
# File 'lib/rley/parser/parse_state.rb', line 32 def predicted?() return dotted_rule.predicted_item? end |
#to_s ⇒ String
Give a String representation of itself. The format of the text representation is "format of dotted rule" + " | " + origin
63 64 65 |
# File 'lib/rley/parser/parse_state.rb', line 63 def to_s() return dotted_rule.to_s + " | #{origin}" end |