Class: Antlr4::Runtime::ATN

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

Constant Summary collapse

INVALID_ALT_NUMBER =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(grammar_type, max_token_type) ⇒ ATN

Returns a new instance of ATN


20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/antlr4/runtime/atn.rb', line 20

def initialize(grammar_type, max_token_type)
  @states = []
  @decision_to_state = []
  @rule_to_start_state = []
  @rule_to_stop_state = []
  @mode_name_to_start_state = {}
  @grammar_type = grammar_type
  @max_token_type = max_token_type
  @rule_to_token_type = []
  @_a = []
  @mode_to_start_state = []
end

Instance Attribute Details

#_aObject

Returns the value of attribute _a


17
18
19
# File 'lib/antlr4/runtime/atn.rb', line 17

def _a
  @_a
end

#decision_to_stateObject

Returns the value of attribute decision_to_state


16
17
18
# File 'lib/antlr4/runtime/atn.rb', line 16

def decision_to_state
  @decision_to_state
end

#grammar_typeObject

Returns the value of attribute grammar_type


10
11
12
# File 'lib/antlr4/runtime/atn.rb', line 10

def grammar_type
  @grammar_type
end

#max_token_typeObject

Returns the value of attribute max_token_type


18
19
20
# File 'lib/antlr4/runtime/atn.rb', line 18

def max_token_type
  @max_token_type
end

#mode_name_to_start_stateObject

Returns the value of attribute mode_name_to_start_state


14
15
16
# File 'lib/antlr4/runtime/atn.rb', line 14

def mode_name_to_start_state
  @mode_name_to_start_state
end

#mode_to_start_stateObject

Returns the value of attribute mode_to_start_state


15
16
17
# File 'lib/antlr4/runtime/atn.rb', line 15

def mode_to_start_state
  @mode_to_start_state
end

#rule_to_start_stateObject

Returns the value of attribute rule_to_start_state


12
13
14
# File 'lib/antlr4/runtime/atn.rb', line 12

def rule_to_start_state
  @rule_to_start_state
end

#rule_to_stop_stateObject

Returns the value of attribute rule_to_stop_state


13
14
15
# File 'lib/antlr4/runtime/atn.rb', line 13

def rule_to_stop_state
  @rule_to_stop_state
end

#rule_to_token_typeObject

Returns the value of attribute rule_to_token_type


11
12
13
# File 'lib/antlr4/runtime/atn.rb', line 11

def rule_to_token_type
  @rule_to_token_type
end

#statesObject

Returns the value of attribute states


9
10
11
# File 'lib/antlr4/runtime/atn.rb', line 9

def states
  @states
end

Instance Method Details

#add_state(state) ⇒ Object


45
46
47
48
49
50
51
52
# File 'lib/antlr4/runtime/atn.rb', line 45

def add_state(state)
  unless state.nil?
    state.atn = self
    state.state_number = @states.length
  end

  @states << state
end

#decision_state(decision) ⇒ Object


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

def decision_state(decision)
  @decision_to_state[decision] unless @decision_to_state.empty?
end

#define_decision_state(s) ⇒ Object


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

def define_decision_state(s)
  @decision_to_state << s
  s.decision = @decision_to_state.length - 1
end

#expected_tokens(state_number, context) ⇒ Object


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.rb', line 71

def expected_tokens(state_number, context)
  if state_number < 0 || state_number >= @states.length
    raise IllegalArgumentException, 'Invalid state number.'
  end

  ctx = context
  s = @states[state_number]
  following = next_tokens(s)
  return following unless following.contains(Token::EPSILON)

  expected = IntervalSet.new
  expected.add_all(following)
  expected.remove(Token::EPSILON)
  while !ctx.nil? && ctx.invoking_state >= 0 && following.contains(Token::EPSILON)
    invoking_state = @states[ctx.invoking_state]
    rt = invoking_state.transition(0)
    following = next_tokens(rt.follow_state)
    expected.add_all(following)
    expected.remove(Token::EPSILON)
    ctx = ctx.parent
  end

  expected << Token::EOF if following.contains(Token::EPSILON)

  expected
end

#next_tokens(s) ⇒ Object


37
38
39
40
41
42
43
# File 'lib/antlr4/runtime/atn.rb', line 37

def next_tokens(s)
  return s.next_token_within_rule unless s.next_token_within_rule.nil?

  s.next_token_within_rule = next_tokens_ctx(s, nil)
  s.next_token_within_rule.readonly(true)
  s.next_token_within_rule
end

#next_tokens_ctx(s, ctx) ⇒ Object


33
34
35
# File 'lib/antlr4/runtime/atn.rb', line 33

def next_tokens_ctx(s, ctx)
  LL1Analyzer.new(self).look(s, nil, ctx)
end

#number_of_decisionsObject


67
68
69
# File 'lib/antlr4/runtime/atn.rb', line 67

def number_of_decisions
  @decision_to_state.length
end

#remove_state(state) ⇒ Object


54
55
56
# File 'lib/antlr4/runtime/atn.rb', line 54

def remove_state(state)
  @states[state.state_number] = nil
end