Method: Parser#consume
- Defined in:
- lib/antlr4/Parser.rb
#consume ⇒ Object
Consume and return the #getCurrentToken current symbol.
<p>E.g., given the following input with A being the current lookahead symbol, self function moves the cursor to B and returns A.</p>
<pre>
A B
^
</pre>
If the parser is not in error recovery mode, the consumed symbol is added to the parse tree using ParserRuleContext#addChild(Token), and ParseTreeListener#visitTerminal is called on any parse listeners. If the parser is in error recovery mode, the consumed symbol is added to the parse tree using ParserRuleContext#addErrorNode(Token), and ParseTreeListener#visitErrorNode is called on any parse listeners.
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/antlr4/Parser.rb', line 308 def consume() o = self.getCurrentToken() if o.type != Token::EOF then self.getInputStream().consume() end hasListener = ! self.parseListeners.empty? if self.buildParseTrees or hasListener then if self.errHandler.inErrorRecoveryMode(self) then node = self.ctx.addErrorNode(o) else node = self.ctx.addTokenNode(o) end self.parseListeners.each {|listener| listener.visitTerminal(node) } end return o end |