Class: Antlr4::Runtime::RuleContext

Inherits:
RuleNode show all
Defined in:
lib/antlr4/runtime/rule_context.rb

Direct Known Subclasses

ParserRuleContext

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil, invoking_state = nil) ⇒ RuleContext

Returns a new instance of RuleContext


7
8
9
10
11
# File 'lib/antlr4/runtime/rule_context.rb', line 7

def initialize(parent = nil, invoking_state = nil)
  @invoking_state = -1
  @parent = parent
  @invoking_state = invoking_state
end

Instance Attribute Details

#invoking_stateObject

Returns the value of attribute invoking_state


5
6
7
# File 'lib/antlr4/runtime/rule_context.rb', line 5

def invoking_state
  @invoking_state
end

#parentObject

Returns the value of attribute parent


4
5
6
# File 'lib/antlr4/runtime/rule_context.rb', line 4

def parent
  @parent
end

Instance Method Details

#accept(visitor) ⇒ Object


73
74
75
# File 'lib/antlr4/runtime/rule_context.rb', line 73

def accept(visitor)
  visitor.visit_children(self)
end

#alt_numberObject


61
62
63
# File 'lib/antlr4/runtime/rule_context.rb', line 61

def alt_number
  ATN::INVALID_ALT_NUMBER
end

#child(_i) ⇒ Object


65
66
67
# File 'lib/antlr4/runtime/rule_context.rb', line 65

def child(_i)
  nil
end

#child_countObject


69
70
71
# File 'lib/antlr4/runtime/rule_context.rb', line 69

def child_count
  0
end

#depthObject


13
14
15
16
17
18
19
20
21
# File 'lib/antlr4/runtime/rule_context.rb', line 13

def depth
  n = 0
  p = self
  until p.nil?
    p = p.parent
    n += 1
  end
  n
end

#empty?Boolean

Returns:

  • (Boolean)

23
24
25
# File 'lib/antlr4/runtime/rule_context.rb', line 23

def empty?
  @invoking_state == -1
end

#payloadObject


37
38
39
# File 'lib/antlr4/runtime/rule_context.rb', line 37

def payload
  self
end

#rule_contextObject


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

def rule_context
  self
end

#rule_indexObject


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

def rule_index
  -1
end

#set_alt_number(_num) ⇒ Object


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

def set_alt_number(_num)
end

#source_intervalObject

satisfy the ParseTree / SyntaxTree interface


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

def source_interval
  Interval.invalid
end

#textObject


44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/antlr4/runtime/rule_context.rb', line 44

def text
  return '' if child_count == 0

  builder = ''
  i = 0
  while i < child_count
    builder << child_at(i).text
    i += 1
  end

  builder.to_s
end

#to_sObject


89
90
91
# File 'lib/antlr4/runtime/rule_context.rb', line 89

def to_s
  to_s_recog_ctx(nil, nil)
end

#to_s_list(rule_names) ⇒ Object


97
98
99
# File 'lib/antlr4/runtime/rule_context.rb', line 97

def to_s_list(rule_names)
  to_s_list_ctx(rule_names, nil)
end

#to_s_list_ctx(rule_names, stop) ⇒ Object


107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/antlr4/runtime/rule_context.rb', line 107

def to_s_list_ctx(rule_names, stop)
  buf = ''
  p = self
  buf << '['
  while !p.nil? && p != stop
    if rule_names.nil?
      buf << p.invoking_state unless p.empty?
    else
      rule_index = p.rule_index
      rule_name = rule_index >= 0 && rule_index < rule_names.size ? rule_names[rule_index] : rule_index
      buf << rule_name.to_s
    end

    buf << ' ' if !p.parent.nil? && (!rule_names.nil? || !p.parent.empty?)

    p = p.parent
  end

  buf << ']'
  buf
end

#to_s_recog(recog) ⇒ Object


93
94
95
# File 'lib/antlr4/runtime/rule_context.rb', line 93

def to_s_recog(recog)
  to_s_recog_ctx(recog, ParserRuleContext::EMPTY)
end

#to_s_recog_ctx(recog, stop) ⇒ Object


101
102
103
104
105
# File 'lib/antlr4/runtime/rule_context.rb', line 101

def to_s_recog_ctx(recog, stop)
  rule_names = !recog.nil? ? recog.rule_names : nil
  rule_names_list = !rule_names.nil? ? rule_names : nil
  to_s_list_ctx(rule_names_list, stop)
end

#to_string_treeObject


85
86
87
# File 'lib/antlr4/runtime/rule_context.rb', line 85

def to_string_tree
  to_string_tree_rulenames(nil)
end

#to_string_tree_recog(recog) ⇒ Object


77
78
79
# File 'lib/antlr4/runtime/rule_context.rb', line 77

def to_string_tree_recog(recog)
  Trees.to_sTree(self, recog)
end

#to_string_tree_rulenames(rule_names) ⇒ Object


81
82
83
# File 'lib/antlr4/runtime/rule_context.rb', line 81

def to_string_tree_rulenames(rule_names)
  Trees.to_sTree(self, rule_names)
end