MCPcopy
hub / github.com/antlr/antlr4 / consume

Method consume

runtime/JavaScript/src/antlr4/Parser.js:342–367  ·  view source on GitHub ↗

* Consume and return the plain //getCurrentToken current symbol. * * E.g., given the following input with A being the current * lookahead symbol, this function moves the cursor to B and returns * A. * * * A B * ^

()

Source from the content-addressed store, hash-verified

340 * listeners.
341 */
342 consume() {
343 const o = this.getCurrentToken();
344 if (o.type !== Token.EOF) {
345 this.getInputStream().consume();
346 }
347 const hasListener = this._parseListeners !== null && this._parseListeners.length > 0;
348 if (this.buildParseTrees || hasListener) {
349 let node;
350 if (this._errHandler.inErrorRecoveryMode(this)) {
351 node = this._ctx.addErrorNode(o);
352 } else {
353 node = this._ctx.addTokenNode(o);
354 }
355 node.invokingState = this.state;
356 if (hasListener) {
357 this._parseListeners.forEach(function (listener) {
358 if (node instanceof ErrorNode || (node.isErrorNode !== undefined && node.isErrorNode())) {
359 listener.visitErrorNode(node);
360 } else if (node instanceof TerminalNode) {
361 listener.visitTerminal(node);
362 }
363 });
364 }
365 }
366 return o;
367 }
368
369 addContextToParseTree() {
370 // add current context to parent if we have a parent

Callers 2

matchMethod · 0.95
matchWildcardMethod · 0.95

Calls 9

getCurrentTokenMethod · 0.95
getInputStreamMethod · 0.95
isErrorNodeMethod · 0.80
consumeMethod · 0.65
inErrorRecoveryModeMethod · 0.65
visitErrorNodeMethod · 0.65
visitTerminalMethod · 0.65
addErrorNodeMethod · 0.45
addTokenNodeMethod · 0.45

Tested by

no test coverage detected