Class: Rley::Parser::ParseStateTracker

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

Overview

Helper class that keeps track of the parse states used while a Parsing instance is constructing a parse tree.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aStateSetIndex) ⇒ ParseStateTracker

Constructor. Refined variant of the inherited constructor.



18
19
20
# File 'lib/rley/parser/parse_state_tracker.rb', line 18

def initialize(aStateSetIndex)
  self.state_set_index = aStateSetIndex
end

Instance Attribute Details

#parse_stateObject

The current parse state



12
13
14
# File 'lib/rley/parser/parse_state_tracker.rb', line 12

def parse_state
  @parse_state
end

#processed_statesObject (readonly)

The already processed states from current state set



15
16
17
# File 'lib/rley/parser/parse_state_tracker.rb', line 15

def processed_states
  @processed_states
end

#state_set_indexObject

The index of the current state set



9
10
11
# File 'lib/rley/parser/parse_state_tracker.rb', line 9

def state_set_index
  @state_set_index
end

Instance Method Details

#curr_dotted_itemObject

The dotted item for the current parse state.



43
44
45
# File 'lib/rley/parser/parse_state_tracker.rb', line 43

def curr_dotted_item()
  parse_state.dotted_rule
end

#select_state(theStates) ⇒ Object

Take the first provided state that wasn't processed yet.



37
38
39
40
# File 'lib/rley/parser/parse_state_tracker.rb', line 37

def select_state(theStates)
  a_state = theStates.find { |st| !processed_states.include?(st) }
  self.parse_state = a_state
end

#symbol_on_leftObject



47
48
49
# File 'lib/rley/parser/parse_state_tracker.rb', line 47

def symbol_on_left()
  return curr_dotted_item.prev_symbol
end

#to_prev_state_setObject

Notification that one begins with the previous state set



52
53
54
# File 'lib/rley/parser/parse_state_tracker.rb', line 52

def to_prev_state_set()
  self.state_set_index = state_set_index - 1
end