Package org.antlr.grammar.v3

Examples of org.antlr.grammar.v3.ANTLRParser


        processArgs(args);
        CharStream input;
        if ( filename!=null ) input = new ANTLRFileStream(filename);
        else input = new ANTLRInputStream(System.in);
        // BUILD AST
        ANTLRv3Lexer lex = new ANTLRv3Lexer(input);
        tokens = new TokenRewriteStream(lex);
        ANTLRv3Parser g = new ANTLRv3Parser(tokens);
        ANTLRv3Parser.grammarDef_return r = g.grammarDef();
        CommonTree t = r.getTree();
        if (tree_option) System.out.println(t.toStringTree());
View Full Code Here


        if ( filename!=null ) input = new ANTLRFileStream(filename);
        else input = new ANTLRInputStream(System.in);
        // BUILD AST
        ANTLRv3Lexer lex = new ANTLRv3Lexer(input);
        tokens = new TokenRewriteStream(lex);
        ANTLRv3Parser g = new ANTLRv3Parser(tokens);
        ANTLRv3Parser.grammarDef_return r = g.grammarDef();
        CommonTree t = r.getTree();
        if (tree_option) System.out.println(t.toStringTree());
        rewrite(g.getTreeAdaptor(),t,g.getTokenNames());
    }
View Full Code Here

    for (Rule r : rules) {
      // walk all actions within the rule elements, args, and exceptions
      List<GrammarAST> actions = r.getInlineActions();
      for (int i = 0; i < actions.size(); i++) {
        GrammarAST actionAST = actions.get(i);
        ActionAnalysis sniffer =
          new ActionAnalysis(this, r.name, actionAST);
        sniffer.analyze();
      }
      // walk any named actions like @init, @after
      Collection<? extends Object> namedActions = r.getActions().values();
      for (Object namedAction : namedActions) {
        GrammarAST actionAST = (GrammarAST)namedAction;
        ActionAnalysis sniffer =
          new ActionAnalysis(this, r.name, actionAST);
        sniffer.analyze();
      }
    }
  }
View Full Code Here

      "    ;");
    Tool antlr = newTool();
    CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
    g.setCodeGenerator(generator);
    generator.genRecognizer(); // forces load of templates
    ActionTranslator translator = new ActionTranslator(generator,
                                  "rule",
                                  new CommonToken(ANTLRParser.ACTION,action),1);
    String rawTranslation =
      translator.translate();

    int expectedMsgID = ErrorManager.MSG_WRITE_TO_READONLY_ATTR;
    Object expectedArg = "other";
    Object expectedArg2 = "tree";
    GrammarSemanticsMessage expectedMessage =
View Full Code Here

                GrammarAST actionTree)
  {
    if ( actionTree.getType()==ANTLRParser.ARG_ACTION ) {
      return translateArgAction(ruleName, actionTree);
    }
    ActionTranslator translator = new ActionTranslator(this,ruleName,actionTree);
    List<Object> chunks = translator.translateToChunks();
    chunks = target.postProcessAction(chunks, actionTree.token);
    return chunks;
  }
View Full Code Here

    List<ST> translatedArgs = new ArrayList<ST>();
    for (String arg : args) {
      if ( arg!=null ) {
        Token actionToken =
          new CommonToken(ANTLRParser.ACTION,arg);
        ActionTranslator translator =
          new ActionTranslator(this,ruleName,
                        actionToken,
                        actionTree.outerAltNum);
        List<Object> chunks = translator.translateToChunks();
        chunks = target.postProcessAction(chunks, actionToken);
        ST catST = new ST(templates, "<chunks>");
        catST.add("chunks", chunks);
        translatedArgs.add(catST);
      }
View Full Code Here

  @Test public void testEscapedLessThanInAction() throws Exception {
    Grammar g = new Grammar();
    Tool antlr = newTool();
    CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
    String action = "i<3; '<xmltag>'";
    ActionTranslator translator = new ActionTranslator(generator,"a",
      new CommonToken(ANTLRParser.ACTION,action),0);
    String expecting = action;
    String rawTranslation =
      translator.translate();
    STGroup templates =
      new STGroup();
    ST actionST = new ST(templates, "<action>");
    actionST.add("action", rawTranslation);
    String found = actionST.render();
View Full Code Here

        "        ;");
    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),0);
    String found = translator.translate();    assertEquals(expecting, found);
  }
View Full Code Here

        "        ;");
    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

        "        ;");
    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 rawTranslation =  translator.translate();
    assertEquals(expecting, rawTranslation);

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

TOP

Related Classes of org.antlr.grammar.v3.ANTLRParser

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.