Examples of CodeGenerator


Examples of org.antlr.codegen.CodeGenerator

        "scope {\n" +
        "  int n;\n" +
        "} : '(' b ')' {"+action+"}\n" + // refers to current invocation's n
        "  ;\n");
    Tool antlr = newTool();
    CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
    g.setCodeGenerator(generator);
    generator.genRecognizer(); // forces load of templates
    ActionTranslator translator = new ActionTranslator(generator, "b",
      new CommonToken(ANTLRParser.ACTION,action),1);
    String found = translator.translate();    assertEquals(expecting, found);

    assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
View Full Code Here

Examples of org.antlr.codegen.CodeGenerator

      "parser grammar t;\n" +
        "options {output=template;}\n"+
        "a : {"+action+"}\n" +
        "  ;\n");
    Tool antlr = newTool();
    CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
    g.setCodeGenerator(generator);
    generator.genRecognizer(); // forces load of templates
    ActionTranslator translator = new ActionTranslator(generator,"a",
      new CommonToken(ANTLRParser.ACTION,action),1);
    String found = translator.translate();    assertEquals(expecting, found);

    assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
View Full Code Here

Examples of org.antlr.codegen.CodeGenerator

      "parser grammar t;\n" +
        "options {output=template;}\n"+
        "a : {###"+action+"!!!}\n" +
        "  ;\n");
    Tool antlr = newTool();
    CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
    g.setCodeGenerator(generator);
    generator.genRecognizer(); // codegen phase sets some vars we need
    ST codeST = generator.getRecognizerST();
    String code = codeST.render();
    String found = code.substring(code.indexOf("###")+3,code.indexOf("!!!"));
    assertEquals(expecting, found);

    assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
View Full Code Here

Examples of org.antlr.codegen.CodeGenerator

    Grammar g = new Grammar(
      "parser grammar t;\n" +
        "a : {###"+action+"!!!}\n" +
        "  ;\n");
    Tool antlr = newTool();
    CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
    g.setCodeGenerator(generator);
    generator.genRecognizer(); // forces load of templates
    ActionTranslator translator = new ActionTranslator(generator,"a",
      new CommonToken(ANTLRParser.ACTION,action),1);
    ST codeST = generator.getRecognizerST();
    String code = codeST.render();
    String found = code.substring(code.indexOf("###")+3,code.indexOf("!!!"));
    assertEquals(expecting, found);

    assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
View Full Code Here

Examples of org.antlr.codegen.CodeGenerator

        "  | INT {"+action2+"}\n" +
        "  ;\n" +
        "ID : 'a';\n" +
        "INT : '0';\n");
    Tool antlr = newTool();
    CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
    g.setCodeGenerator(generator);
    generator.genRecognizer(); // forces load of templates
    ActionTranslator translator = new ActionTranslator(generator,"a",
      new CommonToken(ANTLRParser.ACTION,action),1);
    String found = translator.translate();    assertEquals(expecting, found);

    assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
View Full Code Here

Examples of org.antlr.v4.codegen.CodeGenerator

    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

Examples of org.antlr.v4.codegen.CodeGenerator

  public LexerATNFactory(LexerGrammar g) {
    super(g);
    // use codegen to get correct language templates for lexer commands
    String language = g.getOptionString("language");
    CodeGenerator gen = new CodeGenerator(g.tool, null, language);
    codegenTemplates = gen.getTemplates();
  }
View Full Code Here

Examples of org.antlr.v4.codegen.CodeGenerator

      ATNFactory factory = new ParserATNFactory(g);
      if (g.isLexer()) factory = new LexerATNFactory((LexerGrammar) g);
      g.atn = factory.createATN();

      CodeGenerator gen = new CodeGenerator(g);
      ST outputFileST = gen.generateParser();

//      STViz viz = outputFileST.inspect();
//      try {
//        viz.waitForClose();
//      }
View Full Code Here

Examples of org.antlr.v4.codegen.CodeGenerator

  public List<Decl> labels = new ArrayList<Decl>();

  public MatchToken(OutputModelFactory factory, TerminalAST ast) {
    super(factory, ast);
    Grammar g = factory.getGrammar();
    CodeGenerator gen = factory.getGenerator();
    ttype = g.getTokenType(ast.getText());
    name = gen.getTarget().getTokenTypeAsTargetLabel(g, ttype);
  }
View Full Code Here

Examples of org.antlr.v4.codegen.CodeGenerator

      RuleTransition ruleTrans = (RuleTransition)ast.atnState.transition(0);
      stateNumber = ast.atnState.stateNumber;
    }

    this.name = ast.getText();
    CodeGenerator gen = factory.getGenerator();
    Rule r = factory.getGrammar().getRule(name);
    ctxName = gen.getTarget().getRuleFunctionContextStructName(r);

    // TODO: move to factory
    RuleFunction rf = factory.getCurrentRuleFunction();
    if ( labelAST!=null ) {
      // for x=r, define <rule-context-type> x and list_x
      String label = labelAST.getText();
      if ( labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN  ) {
        factory.defineImplicitLabel(ast, this);
        String listLabel = gen.getTarget().getListLabel(label);
        RuleContextListDecl l = new RuleContextListDecl(factory, listLabel, ctxName);
        rf.addContextDecl(ast.getAltLabel(), l);
      }
      else {
        RuleContextDecl d = new RuleContextDecl(factory,label,ctxName);
        labels.add(d);
        rf.addContextDecl(ast.getAltLabel(), d);
      }
    }

    ActionAST arg = (ActionAST)ast.getFirstChildWithType(ANTLRParser.ARG_ACTION);
    if ( arg != null ) {
      argExprsChunks = ActionTranslator.translateAction(factory, rf, arg.token, arg);
    }

    // If action refs rule as rulename not label, we need to define implicit label
    if ( factory.getCurrentOuterMostAlt().ruleRefsInActions.containsKey(ast.getText()) ) {
      String label = gen.getTarget().getImplicitRuleLabel(ast.getText());
      RuleContextDecl d = new RuleContextDecl(factory,label,ctxName);
      labels.add(d);
      rf.addContextDecl(ast.getAltLabel(), d);
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.