Exemple #1
0
  /**
   * 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
    }
  }
Exemple #2
0
  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);
    }
  }