Class: ParserRuleContext
Instance Attribute Summary collapse
Attributes inherited from RuleContext
#invokingState, #parentCtx
Instance Method Summary
collapse
Methods inherited from RuleContext
EMPTY, #accept, #depth, #getPayload, #getRuleContext, #getRuleIndex, #getText, #isEmpty, #toString, #toStringTree
Constructor Details
#initialize(parent = nil, invoking_state_number = nil) ⇒ ParserRuleContext
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/antlr4/ParserRuleContext.rb', line 29
def initialize(parent= nil, invoking_state_number= nil)
super(parent, invoking_state_number)
@children = Array.new
@start = nil
@stop = nil
@exception =nil
end
|
Instance Attribute Details
Returns the value of attribute children.
27
28
29
|
# File 'lib/antlr4/ParserRuleContext.rb', line 27
def children
@children
end
|
#exception ⇒ Object
Returns the value of attribute exception.
27
28
29
|
# File 'lib/antlr4/ParserRuleContext.rb', line 27
def exception
@exception
end
|
Returns the value of attribute parser.
28
29
30
|
# File 'lib/antlr4/ParserRuleContext.rb', line 28
def parser
@parser
end
|
Returns the value of attribute start.
27
28
29
|
# File 'lib/antlr4/ParserRuleContext.rb', line 27
def start
@start
end
|
Returns the value of attribute stop.
27
28
29
|
# File 'lib/antlr4/ParserRuleContext.rb', line 27
def stop
@stop
end
|
Instance Method Details
#addChild(child) ⇒ Object
62
63
64
65
|
# File 'lib/antlr4/ParserRuleContext.rb', line 62
def addChild(child)
self.children.push(child)
return child
end
|
#addErrorNode(badToken) ⇒ Object
80
81
82
83
84
85
|
# File 'lib/antlr4/ParserRuleContext.rb', line 80
def addErrorNode(badToken)
node = ErrorNodeImpl.new(badToken)
self.addChild(node)
node.parentCtx = self
return node
end
|
#addTokenNode(token) ⇒ Object
73
74
75
76
77
78
|
# File 'lib/antlr4/ParserRuleContext.rb', line 73
def addTokenNode(token)
node = TerminalNodeImpl.new(token)
self.addChild(node)
node.parentCtx = self
return node
end
|
#copyFrom(ctx) ⇒ Object
46
47
48
49
50
51
52
53
|
# File 'lib/antlr4/ParserRuleContext.rb', line 46
def copyFrom(ctx)
self.parentCtx = ctx.parentCtx
self.invokingState = ctx.invokingState
self.children = Array.new
self.start = ctx.start
self.stop = ctx.stop
end
|
#enterRule(listener) ⇒ Object
Double dispatch methods for listeners
56
57
|
# File 'lib/antlr4/ParserRuleContext.rb', line 56
def enterRule(listener)
end
|
#exitRule(listener) ⇒ Object
58
59
|
# File 'lib/antlr4/ParserRuleContext.rb', line 58
def exitRule(listener)
end
|
#getChild(i, type = nil) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/antlr4/ParserRuleContext.rb', line 87
def getChild(i, type=nil )
if type.nil?
if self.children.length >= i then
return self.children[i]
end
else
for child in self.getChildren() do
next if not child.kind_of? type
return child if i==0
i = i - 1
end
end
return nil
end
|
#getChildCount ⇒ Object
133
134
135
|
# File 'lib/antlr4/ParserRuleContext.rb', line 133
def getChildCount
return self.children.length
end
|
#getChildren ⇒ Object
101
102
103
|
# File 'lib/antlr4/ParserRuleContext.rb', line 101
def getChildren
@children
end
|
#getSourceInterval ⇒ Object
137
138
139
140
141
142
143
|
# File 'lib/antlr4/ParserRuleContext.rb', line 137
def getSourceInterval
if self.start.nil? or self.stop.nil? then
return Antlr4::INVALID_INTERVAL
else
return [self.start.tokenIndex, self.stop.tokenIndex]
end
end
|
#getToken(ttype, i) ⇒ Object
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/antlr4/ParserRuleContext.rb', line 104
def getToken(ttype, i)
self.getChildren().each do |child|
next if not child.kind_of? TerminalNode
next if child.symbol.type != ttype
return child if i==0
i -= 1
i = i - 1
end
return nil
end
|
#getTokens(ttype) ⇒ Object
114
115
116
117
118
119
120
121
|
# File 'lib/antlr4/ParserRuleContext.rb', line 114
def getTokens(ttype)
return Array.new if self.getChildren().empty?
self.getChildren().map do |child|
next if not child.kind_of? TerminalNode
next if child.symbol.type != ttype
child
end.compact
end
|
#getTypedRuleContext(ctxType, i) ⇒ Object
123
124
125
|
# File 'lib/antlr4/ParserRuleContext.rb', line 123
def getTypedRuleContext(ctxType, i)
return self.getChild(i, ctxType)
end
|
#getTypedRuleContexts(ctxType) ⇒ Object
126
127
128
129
130
131
132
|
# File 'lib/antlr4/ParserRuleContext.rb', line 126
def getTypedRuleContexts(ctxType)
return Array.new if self.getChildren().empty?
self.getChildren.map do |child|
next if not child.kind_of? ctxType
child
end.compact
end
|
#removeLastChild ⇒ Object
we entered a rule. If we have
generic ruleContext object.
/
70
71
72
|
# File 'lib/antlr4/ParserRuleContext.rb', line 70
def removeLastChild()
self.children.delete_at(-1)
end
|
144
145
146
147
148
149
150
|
# File 'lib/antlr4/ParserRuleContext.rb', line 144
def to_s
p = nil
if parentCtx then
p = parentCtx.to_s
end
"#{self.class}:[#{invokingState}]#{p}"
end
|