Class: Rley::Parser::ParseState

Inherits:
Object
  • Object
show all
Defined in:
lib/rley/parser/parse_state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aDottedRule, theOrigin) ⇒ 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_ruleObject (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

#originObject (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
24
25
# File 'lib/rley/parser/parse_state.rb', line 18

def ==(other)
  return true if equal?(other)

  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.



29
30
31
# File 'lib/rley/parser/parse_state.rb', line 29

def complete?()
  return dotted_rule.reduce_item?
end

#next_symbolObject

Next expected symbol in the production



39
40
41
# File 'lib/rley/parser/parse_state.rb', line 39

def next_symbol()
  return dotted_rule.next_symbol
end

#precedes?(other) ⇒ Boolean

Does this parse state have the 'other' as successor?



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rley/parser/parse_state.rb', line 44

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
  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.



34
35
36
# File 'lib/rley/parser/parse_state.rb', line 34

def predicted?()
  return dotted_rule.predicted_item?
end

#to_sString

Give a String representation of itself. The format of the text representation is "format of dotted rule" + " | " + origin



66
67
68
# File 'lib/rley/parser/parse_state.rb', line 66

def to_s()
  return dotted_rule.to_s + " | #{origin}"
end