// simulates rule entry for left-recursive rules public virtual void UnrollRecursionContexts(ParserRuleContext _parentctx) { _precedenceStack.RemoveAt(_precedenceStack.Count - 1); _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 internal virtual void AddContextToParseTree() { ParserRuleContext parent = (ParserRuleContext)_ctx.Parent; // add current context to parent if we have a parent if (parent != null) { parent.AddChild(_ctx); } }
public virtual 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; }
// simulates rule entry for left-recursive rules /// <summary> /// Like /// <see cref="EnterRule(ParserRuleContext, int, int)"/> /// but for recursive rules. /// </summary> public virtual 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(); } }
public virtual void EnterLeftFactoredRule(ParserRuleContext localctx, int state, int ruleIndex) { State = state; if (_buildParseTrees) { ParserRuleContext factoredContext = (ParserRuleContext)_ctx.GetChild(_ctx.ChildCount - 1); _ctx.RemoveLastChild(); factoredContext.Parent = localctx; localctx.AddChild(factoredContext); } _ctx = localctx; _ctx.Start = _input.LT(1); if (_buildParseTrees) { AddContextToParseTree(); } if (_parseListeners != null) { TriggerEnterRuleEvent(); } }
/// <summary> /// Consume and return the /// <linkplain> /// #getCurrentToken /// current symbol /// </linkplain> /// . /// <p>E.g., given the following input with /// <c>A</c> /// being the current /// lookahead symbol, this function moves the cursor to /// <c>B</c> /// and returns /// <c>A</c> /// .</p> /// <pre> /// A B /// ^ /// </pre> /// If the parser is not in error recovery mode, the consumed symbol is added /// to the parse tree using /// <see cref="ParserRuleContext.AddChild(IToken)"/> /// , and /// <see cref="erl.Oracle.TnsNames.Antlr4.Runtime.Tree.IParseTreeListener.VisitTerminal(erl.Oracle.TnsNames.Antlr4.Runtime.Tree.ITerminalNode)"/> /// is called on any parse listeners. /// If the parser <em>is</em> in error recovery mode, the consumed symbol is /// added to the parse tree using /// <see cref="ParserRuleContext.AddErrorNode(IToken)"/> /// , and /// <see cref="erl.Oracle.TnsNames.Antlr4.Runtime.Tree.IParseTreeListener.VisitErrorNode(erl.Oracle.TnsNames.Antlr4.Runtime.Tree.IErrorNode)"/> /// is called on any parse /// listeners. /// </summary> public virtual IToken Consume() { IToken o = CurrentToken; if (o.Type != Eof) { ((ITokenStream)InputStream).Consume(); } bool hasListener = _parseListeners != null && _parseListeners.Count != 0; if (_buildParseTrees || hasListener) { if (_errHandler.InErrorRecoveryMode(this)) { IErrorNode node = _ctx.AddErrorNode(o); if (_parseListeners != null) { foreach (IParseTreeListener listener in _parseListeners) { listener.VisitErrorNode(node); } } } else { ITerminalNode node = _ctx.AddChild(o); if (_parseListeners != null) { foreach (IParseTreeListener listener in _parseListeners) { listener.VisitTerminal(node); } } } } return(o); }