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.
12 13 14 15 |
# File 'lib/rley/parser/parse_state.rb', line 12 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.
6 7 8 |
# File 'lib/rley/parser/parse_state.rb', line 6 def dotted_rule @dotted_rule end |
#origin ⇒ Object (readonly)
the position in the input that matches the beginning of the rhs of the production.
10 11 12 |
# File 'lib/rley/parser/parse_state.rb', line 10 def origin @origin end |
Instance Method Details
#==(other) ⇒ Object
Equality comparison. A parse state behaves as a value object.
18 19 20 21 22 23 |
# File 'lib/rley/parser/parse_state.rb', line 18 def ==(other) return true if equal?(other) (dotted_rule == other.dotted_rule) && (origin == other.origin) 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? 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 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 |
# File 'lib/rley/parser/parse_state.rb', line 42 def precedes?(other) return false if other == self 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 if prev_position.nil? false else dotted_rule.position == prev_position end 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? 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
62 63 64 |
# File 'lib/rley/parser/parse_state.rb', line 62 def to_s dotted_rule.to_s + " | #{origin}" end |