Package org.antlr.v4.codegen.model

Examples of org.antlr.v4.codegen.model.Action


    if ( !recRuleTemplates.isDefined("recRule") ) {
      tool.errMgr.toolError(ErrorType.MISSING_CODE_GEN_TEMPLATES, "LeftRecursiveRules");
    }

    // use codegen to get correct language templates; that's it though
    CodeGenerator gen = new CodeGenerator(tool, null, language);
    codegenTemplates = gen.getTemplates();
  }
View Full Code Here


    blk.ops = ops;
    return blk;
  }

  @Override
  public List<SrcOp> action(ActionAST ast) { return list(new Action(this, ast)); }
View Full Code Here

        RuleSempredFunction rsf = parser.sempredFuncs.get(r);
        if ( rsf==null ) {
          rsf = new RuleSempredFunction(delegate, r, function.ctxType);
          parser.sempredFuncs.put(r, rsf);
        }
        rsf.actions.put(g.sempreds.get(p), new Action(delegate, p));
      }
    }

    popCurrentRule();
  }
View Full Code Here

    for (int i = 0; i < primaryAltsCode.size(); i++) {
      LeftRecursiveRuleAltInfo altInfo = r.recPrimaryAlts.get(i);
      if ( altInfo.altLabel==null ) continue;
      ST altActionST = codegenTemplates.getInstanceOf("recRuleReplaceContext");
      altActionST.add("ctxName", Utils.capitalize(altInfo.altLabel));
      Action altAction =
        new Action(delegate, function.altLabelCtxs.get(altInfo.altLabel), altActionST);
      CodeBlockForAlt alt = primaryAltsCode.get(i);
      alt.insertOp(0, altAction);
    }

    // Insert code to set ctx.stop after primary block and before op * loop
    ST setStopTokenAST = codegenTemplates.getInstanceOf("recRuleSetStopToken");
    Action setStopTokenAction = new Action(delegate, function.ruleCtx, setStopTokenAST);
    outerAlt.insertOp(1, setStopTokenAction);

    // Insert code to set _prevctx at start of * loop
    ST setPrevCtx = codegenTemplates.getInstanceOf("recRuleSetPrevCtx");
    Action setPrevCtxAction = new Action(delegate, function.ruleCtx, setPrevCtx);
    opAltStarBlock.addIterationOp(setPrevCtxAction);

    // Insert code in front of each op alt to create specialized ctx if there was an alt label
    for (int i = 0; i < opAltsCode.size(); i++) {
      ST altActionST;
      LeftRecursiveRuleAltInfo altInfo = r.recOpAlts.getElement(i);
      String templateName;
      if ( altInfo.altLabel!=null ) {
        templateName = "recRuleLabeledAltStartAction";
        altActionST = codegenTemplates.getInstanceOf(templateName);
        altActionST.add("currentAltLabel", altInfo.altLabel);
      }
      else {
        templateName = "recRuleAltStartAction";
        altActionST = codegenTemplates.getInstanceOf(templateName);
        altActionST.add("ctxName", Utils.capitalize(r.name));
      }
      altActionST.add("ruleName", r.name);
      // add label of any lr ref we deleted
      altActionST.add("label", altInfo.leftRecursiveRuleRefLabel);
      if (altActionST.impl.formalArguments.containsKey("isListLabel")) {
        altActionST.add("isListLabel", altInfo.isListLabel);
      }
      else if (altInfo.isListLabel) {
        delegate.getGenerator().tool.errMgr.toolError(ErrorType.CODE_TEMPLATE_ARG_ISSUE, templateName, "isListLabel");
      }
      Action altAction =
        new Action(delegate, function.altLabelCtxs.get(altInfo.altLabel), altActionST);
      CodeBlockForAlt alt = opAltsCode.get(i);
      alt.insertOp(0, altAction);
    }
  }
View Full Code Here

        RuleSempredFunction rsf = lexer.sempredFuncs.get(r);
        if ( rsf==null ) {
          rsf = new RuleSempredFunction(delegate, r, ctxType);
          lexer.sempredFuncs.put(r, rsf);
        }
        rsf.actions.put(g.sempreds.get(p), new Action(delegate, p));
      }
      else if ( a.getType()== ANTLRParser.ACTION ) {
        raf.actions.put(g.lexerActions.get(a), new Action(delegate, a));
      }
    }

    if (!raf.actions.isEmpty() && !lexer.actionFuncs.containsKey(r)) {
      // only add to lexer if the function actually contains actions
View Full Code Here

  @Override
  public List<SrcOp> ruleRef(GrammarAST ID, GrammarAST label, GrammarAST args) {
    InvokeRule invokeOp = new InvokeRule(this, ID, label);
    // If no manual label and action refs as token/rule not label, we need to define implicit label
    if ( controller.needsImplicitLabel(ID, invokeOp) ) defineImplicitLabel(ID, invokeOp);
    AddToLabelList listLabelOp = getAddToListOpIfListLabelPresent(invokeOp, label);
    return list(invokeOp, listLabelOp);
  }
View Full Code Here

//        TokenListDecl l = getTokenListLabelDecl(label);
//        getCurrentRuleFunction().addContextDecl(ID.getAltLabel(), l);
//      }
    }
    if ( controller.needsImplicitLabel(ID, matchOp) ) defineImplicitLabel(ID, matchOp);
    AddToLabelList listLabelOp = getAddToListOpIfListLabelPresent(matchOp, labelAST);
    return list(matchOp, listLabelOp);
  }
View Full Code Here

        matchOp.labels.add(d);
        rf.addContextDecl(setAST.getAltLabel(), d);
      }
    }
    if ( controller.needsImplicitLabel(setAST, matchOp) ) defineImplicitLabel(setAST, matchOp);
    AddToLabelList listLabelOp = getAddToListOpIfListLabelPresent(matchOp, labelAST);
    return list(matchOp, listLabelOp);
  }
View Full Code Here

        TokenListDecl l = getTokenListLabelDecl(label);
        getCurrentRuleFunction().addContextDecl(ast.getAltLabel(), l);
      }
    }
    if ( controller.needsImplicitLabel(ast, wild) ) defineImplicitLabel(ast, wild);
    AddToLabelList listLabelOp = getAddToListOpIfListLabelPresent(wild, labelAST);
    return list(wild, listLabelOp);
  }
View Full Code Here

    // all labels must be in scope struct in case we exec action out of context
    getCurrentRuleFunction().addContextDecl(ast.getAltLabel(), d);
  }

  public AddToLabelList getAddToListOpIfListLabelPresent(LabeledOp op, GrammarAST label) {
    AddToLabelList labelOp = null;
    if ( label!=null && label.parent.getType()==ANTLRParser.PLUS_ASSIGN ) {
      String listLabel = gen.getTarget().getListLabel(label.getText());
      labelOp = new AddToLabelList(this, listLabel, op.getLabels().get(0));
    }
    return labelOp;
  }
View Full Code Here

TOP

Related Classes of org.antlr.v4.codegen.model.Action

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.