@Override public void exitNonReserved(SqlBaseParser.NonReservedContext context) { // we can't modify the tree during rule enter/exit event handling unless we're dealing with a terminal. // Otherwise, ANTLR gets confused an fires spurious notifications. if (!(context.getChild(0) instanceof TerminalNode)) { int rule = ((ParserRuleContext) context.getChild(0)).getRuleIndex(); throw new AssertionError("nonReserved can only contain tokens. Found nested rule: " + ruleNames.get(rule)); } // replace nonReserved words with IDENT tokens context.getParent().removeLastChild(); Token token = (Token) context.getChild(0).getPayload(); context.getParent().addChild(new CommonToken( new Pair<>(token.getTokenSource(), token.getInputStream()), SqlBaseLexer.IDENTIFIER, token.getChannel(), token.getStartIndex(), token.getStopIndex())); } }
protected void addContextToParseTree() { ParserRuleContext parent = (ParserRuleContext)_ctx.parent; // add current context to parent if we have a parent if ( parent!=null ) { parent.addChild(_ctx); } }
/** COPY a ctx (I'm deliberately not using copy constructor) to avoid * confusion with creating node with parent. Does not copy children * (except error leaves). * * This is used in the generated parser code to flip a generic XContext * node for rule X to a YContext for alt label Y. In that sense, it is * not really a generic copy function. * * If we do an error sync() at start of a rule, we might add error nodes * to the generic XContext so this function must copy those nodes to * the YContext as well else they are lost! */ public void copyFrom(ParserRuleContext ctx) { this.parent = ctx.parent; this.invokingState = ctx.invokingState; this.start = ctx.start; this.stop = ctx.stop; // copy any error nodes to alt label node if ( ctx.children!=null ) { this.children = new ArrayList<>(); // reset parent pointer for any error nodes for (ParseTree child : ctx.children) { if ( child instanceof ErrorNode ) { addChild((ErrorNode)child); } } } }
public void enterOuterAlt(ParserRuleContext localctx, int altNum) { localctx.setAltNumber(altNum); // if we have new localctx, make sure we replace existing ctx // that is previous child of parse tree if ( _buildParseTrees && _ctx != localctx ) { ParserRuleContext parent = (ParserRuleContext)_ctx.parent; if ( parent!=null ) { parent.removeLastChild(); parent.addChild(localctx); } } _ctx = localctx; }
/** Like {@link #enterRule} but for recursive rules. * Make the current context the child of the incoming localctx. */ public void pushNewRecursionContext(ParserRuleContext localctx, int state, int ruleIndex) { ParserRuleContext previous = _ctx; previous.parent = localctx; previous.invokingState = state; previous.stop = _input.LT(-1); _ctx = localctx; _ctx.start = previous.start; if (_buildParseTrees) { _ctx.addChild(previous); } if ( _parseListeners != null ) { triggerEnterRuleEvent(); // simulates rule entry for left-recursive rules } }
public void unrollRecursionContexts(ParserRuleContext _parentctx) { _precedenceStack.pop(); _ctx.stop = _input.LT(-1); ParserRuleContext retctx = _ctx; // save current ctx (return value) // unroll so _ctx is as it was before call to recursive method if ( _parseListeners != null ) { while ( _ctx != _parentctx ) { triggerExitRuleEvent(); _ctx = (ParserRuleContext)_ctx.parent; } } else { _ctx = _parentctx; } // hook into tree retctx.parent = _parentctx; if (_buildParseTrees && _parentctx != null) { // add return ctx into invoking rule's tree _parentctx.addChild(retctx); } }
protected void addContextToParseTree() { ParserRuleContext parent = (ParserRuleContext)_ctx.parent; // add current context to parent if we have a parent if ( parent!=null ) { parent.addChild(_ctx); } }
protected void addContextToParseTree() { ParserRuleContext parent = (ParserRuleContext)_ctx.parent; // add current context to parent if we have a parent if ( parent!=null ) { parent.addChild(_ctx); } }
protected void addContextToParseTree() { ParserRuleContext parent = (ParserRuleContext)_ctx.parent; // add current context to parent if we have a parent if ( parent!=null ) { parent.addChild(_ctx); } }
protected void addContextToParseTree() { ParserRuleContext parent = (ParserRuleContext)_ctx.parent; // add current context to parent if we have a parent if ( parent!=null ) { parent.addChild(_ctx); } }
TerminalNode node = _ctx.addChild(createTerminalNode(_ctx,o)); if (_parseListeners != null) { for (ParseTreeListener listener : _parseListeners) {
public TerminalNode addChild(Token matchedToken) { TerminalNodeImpl t = new TerminalNodeImpl(matchedToken); addChild(t); t.parent = this; return t; }
public TerminalNode addChild(Token matchedToken) { TerminalNodeImpl t = new TerminalNodeImpl(matchedToken); addChild(t); t.parent = this; return t; }
public ErrorNode addErrorNode(Token badToken) { ErrorNodeImpl t = new ErrorNodeImpl(badToken); addChild(t); t.parent = this; return t; }
public ErrorNode addErrorNode(Token badToken) { ErrorNodeImpl t = new ErrorNodeImpl(badToken); addChild(t); t.parent = this; return t; }
public void enterOuterAlt(ParserRuleContext localctx, int altNum) { // if we have new localctx, make sure we replace existing ctx // that is previous child of parse tree if ( _buildParseTrees && _ctx != localctx ) { ParserRuleContext parent = (ParserRuleContext)_ctx.parent; if ( parent!=null ) { parent.removeLastChild(); parent.addChild(localctx); } } _ctx = localctx; }
public void enterOuterAlt(ParserRuleContext localctx, int altNum) { localctx.setAltNumber(altNum); // if we have new localctx, make sure we replace existing ctx // that is previous child of parse tree if ( _buildParseTrees && _ctx != localctx ) { ParserRuleContext parent = (ParserRuleContext)_ctx.parent; if ( parent!=null ) { parent.removeLastChild(); parent.addChild(localctx); } } _ctx = localctx; }
public void enterOuterAlt(ParserRuleContext localctx, int altNum) { localctx.setAltNumber(altNum); // if we have new localctx, make sure we replace existing ctx // that is previous child of parse tree if ( _buildParseTrees && _ctx != localctx ) { ParserRuleContext parent = (ParserRuleContext)_ctx.parent; if ( parent!=null ) { parent.removeLastChild(); parent.addChild(localctx); } } _ctx = localctx; }
public void enterOuterAlt(ParserRuleContext localctx, int altNum) { localctx.setAltNumber(altNum); // if we have new localctx, make sure we replace existing ctx // that is previous child of parse tree if ( _buildParseTrees && _ctx != localctx ) { ParserRuleContext parent = (ParserRuleContext)_ctx.parent; if ( parent!=null ) { parent.removeLastChild(); parent.addChild(localctx); } } _ctx = localctx; }
@Override public void exitQuotedIdentifier(SqlBaseParser.QuotedIdentifierContext context) { // Remove quotes context.getParent().removeLastChild(); Token token = (Token) context.getChild(0).getPayload(); context.getParent().addChild(new CommonToken( new Pair<>(token.getTokenSource(), token.getInputStream()), SqlBaseLexer.IDENTIFIER, token.getChannel(), token.getStartIndex() + 1, token.getStopIndex() - 1)); }