Class: Antlr4::Runtime::ATNState

Inherits:
Object
  • Object
show all
Defined in:
lib/antlr4/runtime/atn_state.rb

Constant Summary collapse

INITIAL_NUM_TRANSITIONS =
4
INVALID_TYPE =
0
BASIC =
1
RULE_START =
2
BLOCK_START =
3
PLUS_BLOCK_START =
4
STAR_BLOCK_START =
5
TOKEN_START =
6
RULE_STOP =
7
BLOCK_END =
8
STAR_LOOP_BACK =
9
STAR_LOOP_ENTRY =
10
PLUS_LOOP_BACK =
11
LOOP_END =
12
@@serialization_names =
%w[INVALID BASIC RULE_START BLOCK_START PLUS_BLOCK_START STAR_BLOCK_START TOKEN_START RULE_STOP BLOCK_END STAR_LOOP_BACK STAR_LOOP_ENTRY PLUS_LOOP_BACK LOOP_END]
@@invalid_state_number =
-1

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeATNState

Returns a new instance of ATNState.



32
33
34
35
36
37
38
39
# File 'lib/antlr4/runtime/atn_state.rb', line 32

def initialize
  @atn = nil
  @state_number = @@invalid_state_number
  @rule_index = 0
  @epsilon_only_transitions = false
  @transitions = []
  @next_token_within_rule = nil
end

Class Attribute Details

.invalid_state_numberObject

Returns the value of attribute invalid_state_number.



21
22
23
# File 'lib/antlr4/runtime/atn_state.rb', line 21

def invalid_state_number
  @invalid_state_number
end

Instance Attribute Details

#atnObject

Returns the value of attribute atn.



28
29
30
# File 'lib/antlr4/runtime/atn_state.rb', line 28

def atn
  @atn
end

#next_token_within_ruleObject

Returns the value of attribute next_token_within_rule.



27
28
29
# File 'lib/antlr4/runtime/atn_state.rb', line 27

def next_token_within_rule
  @next_token_within_rule
end

#rule_indexObject

Returns the value of attribute rule_index.



30
31
32
# File 'lib/antlr4/runtime/atn_state.rb', line 30

def rule_index
  @rule_index
end

#state_numberObject

Returns the value of attribute state_number.



29
30
31
# File 'lib/antlr4/runtime/atn_state.rb', line 29

def state_number
  @state_number
end

#transitionsObject (readonly)

Returns the value of attribute transitions.



57
58
59
# File 'lib/antlr4/runtime/atn_state.rb', line 57

def transitions
  @transitions
end

Instance Method Details

#add_transition(e) ⇒ Object



63
64
65
# File 'lib/antlr4/runtime/atn_state.rb', line 63

def add_transition(e)
  add_transition_at(@transitions.length, e)
end

#add_transition_at(index, e) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/antlr4/runtime/atn_state.rb', line 67

def add_transition_at(index, e)
  if @transitions.empty?

    @epsilon_only_transitions = e.epsilon?

  elsif @epsilon_only_transitions != e.epsilon?

    STDERR.puts format("ATN state %d has both epsilon and non-epsilon transitions.\n", state_number)
    @epsilon_only_transitions = false
  end
  already_present = false

  i = 0
  while i < @transitions.length
    t = @transitions[i]
    if t.target.state_number == e.target.state_number

      if !t.label.nil? && !e.label.nil? && t.label.eql?(e.label)
        already_present = true
        break
      elsif t.epsilon? && e.epsilon?
        already_present = true
        break
      end
    end
    i += 1
  end

  @transitions[index] = e unless already_present
end

#eql?(other_key) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/antlr4/runtime/atn_state.rb', line 45

def eql?(other_key)
  @state_number == other_key.state_number
end

#hashObject



41
42
43
# File 'lib/antlr4/runtime/atn_state.rb', line 41

def hash
  @state_number
end

#non_greedy_exit_state?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/antlr4/runtime/atn_state.rb', line 49

def non_greedy_exit_state?
  false
end

#number_of_transitionsObject



59
60
61
# File 'lib/antlr4/runtime/atn_state.rb', line 59

def number_of_transitions
  @transitions.length
end

#only_has_epsilon_transitionsObject



110
111
112
# File 'lib/antlr4/runtime/atn_state.rb', line 110

def only_has_epsilon_transitions
  @epsilon_only_transitions
end

#remove_transition(index) ⇒ Object



106
107
108
# File 'lib/antlr4/runtime/atn_state.rb', line 106

def remove_transition(index)
  @transitions.delete_at index
end

#set_rule_index(rule_index) ⇒ Object



114
115
116
# File 'lib/antlr4/runtime/atn_state.rb', line 114

def set_rule_index(rule_index)
  @rule_index = rule_index
end

#set_transition(i, e) ⇒ Object



102
103
104
# File 'lib/antlr4/runtime/atn_state.rb', line 102

def set_transition(i, e)
  @transitions[i] = e
end

#to_sObject



53
54
55
# File 'lib/antlr4/runtime/atn_state.rb', line 53

def to_s
  @state_number.to_s
end

#transition(i) ⇒ Object



98
99
100
# File 'lib/antlr4/runtime/atn_state.rb', line 98

def transition(i)
  @transitions[i]
end