Package org.antlr.tool

Examples of org.antlr.tool.Grammar


        String expecting = " ";
        assertEquals(expecting, result);
    }

    @Test public void testCompleteBuffer() throws Exception {
        Grammar g = new Grammar(
            "lexer grammar t;\n"+
            "ID : 'a'..'z'+;\n" +
            "INT : '0'..'9'+;\n" +
            "SEMI : ';';\n" +
            "ASSIGN : '=';\n" +
View Full Code Here


        String expecting = "x = 3 * 0 + 2 * 0;";
        assertEquals(expecting, result);
    }

    @Test public void testCompleteBufferAfterConsuming() throws Exception {
        Grammar g = new Grammar(
            "lexer grammar t;\n"+
            "ID : 'a'..'z'+;\n" +
            "INT : '0'..'9'+;\n" +
            "SEMI : ';';\n" +
            "ASSIGN : '=';\n" +
View Full Code Here

        String expecting = "x = 3 * 0 + 2 * 0;";
        assertEquals(expecting, result);
    }

    @Test public void testLookback() throws Exception {
        Grammar g = new Grammar(
            "lexer grammar t;\n"+
            "ID : 'a'..'z'+;\n" +
            "INT : '0'..'9'+;\n" +
            "SEMI : ';';\n" +
            "ASSIGN : '=';\n" +
View Full Code Here

  @Test public void testMessageStringificationIsConsistent() throws Exception {
    String action = "$other.tree = null;";
    ErrorQueue equeue = new ErrorQueue();
    ErrorManager.setErrorListener(equeue);
    Grammar g = new Grammar(
      "grammar a;\n" +
      "options { output = AST;}" +
      "otherrule\n" +
      "    : 'y' ;" +
      "rule\n" +
      "    : other=otherrule {" + action +"}\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,
                                  "rule",
                                  new CommonToken(ANTLRParser.ACTION,action),1);
    String rawTranslation =
View Full Code Here

            "tree grammar TP;\n"+
            "options {output=AST;}\n" +
            "a : ^(. INT) \n" +
            "  ;\n";

        Grammar g = new Grammar(treeGrammar);
        Tool antlr = newTool();
        antlr.setOutputDirectory(null); // write to /dev/null
        CodeGenerator generator = new CodeGenerator(antlr, g, "Java");
        g.setCodeGenerator(generator);
        generator.genRecognizer();

        assertEquals("unexpected errors: "+equeue, 1, equeue.errors.size());

        int expectedMsgID = ErrorManager.MSG_WILDCARD_AS_ROOT;
View Full Code Here

    @Override
    protected void genRecognizerFile(Tool tool, CodeGenerator generator, Grammar grammar, ST outputFileST) throws IOException
    {
        if (!grammar.getGrammarIsRoot())
        {
            Grammar rootGrammar = grammar.composite.getRootGrammar();
            String actionScope = grammar.getDefaultActionScope(grammar.type);
            Map<String, Object> actions = rootGrammar.getActions().get(actionScope);
            Object rootNamespace = actions != null ? actions.get("namespace") : null;
            if (actions != null && rootNamespace != null)
            {
                actions = grammar.getActions().get(actionScope);
                if (actions == null)
View Full Code Here

    /** Public default constructor used by TestRig */
    public TestInterpretedLexing() {
    }

  @Test public void testSimpleAltCharTest() throws Exception {
        Grammar g = new Grammar(
                "lexer grammar t;\n"+
                "A : 'a' | 'b' | 'c';");
    final int Atype = g.getTokenType("A");
        Interpreter engine = new Interpreter(g, new ANTLRStringStream("a"));
        engine = new Interpreter(g, new ANTLRStringStream("b"));
    Token result = engine.scan("A");
    assertEquals(result.getType(), Atype);
        engine = new Interpreter(g, new ANTLRStringStream("c"));
View Full Code Here

    result = engine.scan("A");
    assertEquals(result.getType(), Atype);
    }

    @Test public void testSingleRuleRef() throws Exception {
        Grammar g = new Grammar(
                "lexer grammar t;\n"+
                "A : 'a' B 'c' ;\n" +
                "B : 'b' ;\n");
    final int Atype = g.getTokenType("A");
    Interpreter engine = new Interpreter(g, new ANTLRStringStream("abc")); // should ignore the x
    Token result = engine.scan("A");
    assertEquals(result.getType(), Atype);
    }
View Full Code Here

    Token result = engine.scan("A");
    assertEquals(result.getType(), Atype);
    }

    @Test public void testSimpleLoop() throws Exception {
        Grammar g = new Grammar(
                "lexer grammar t;\n"+
                "INT : (DIGIT)+ ;\n"+
        "fragment DIGIT : '0'..'9';\n");
    final int INTtype = g.getTokenType("INT");
    Interpreter engine = new Interpreter(g, new ANTLRStringStream("12x")); // should ignore the x
    Token result = engine.scan("INT");
    assertEquals(result.getType(), INTtype);
    engine = new Interpreter(g, new ANTLRStringStream("1234"));
    result = engine.scan("INT");
View Full Code Here

    result = engine.scan("INT");
    assertEquals(result.getType(), INTtype);
    }

    @Test public void testMultAltLoop() throws Exception {
    Grammar g = new Grammar(
                "lexer grammar t;\n"+
                "A : ('0'..'9'|'a'|'b')+ ;\n");
    final int Atype = g.getTokenType("A");
    Interpreter engine = new Interpreter(g, new ANTLRStringStream("a"));
    Token result = engine.scan("A");
        engine = new Interpreter(g, new ANTLRStringStream("a"));
    result = engine.scan("A");
    assertEquals(result.getType(), Atype);
View Full Code Here

TOP

Related Classes of org.antlr.tool.Grammar

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.