Package org.antlr.tool

Examples of org.antlr.tool.Grammar


      "a : INT -> 'foo' ;\n" +
      "ID : 'a'..'z'+ ;\n" +
      "INT : '0'..'9'+;\n" +
      "WS : (' '|'\\n') {$channel=HIDDEN;} ;\n";

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

    int expectedMsgID = ErrorManager.MSG_UNDEFINED_TOKEN_REF_IN_REWRITE;
    Object expectedArg = "'foo'";
    Object expectedArg2 = null;
View Full Code Here


    String found = g.getRule("a").tree.toStringTree();
    assertEquals(expecting, found);
  }

  @Test public void testStringStarInLexer() throws Exception {
    Grammar g = new Grammar(
        "lexer grammar P;\n"+
        "B : 'while'*;");
    String expecting =
      "(rule B ARG RET scope (BLOCK (ALT (* (BLOCK (ALT 'while' <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
    String found = g.getRule("B").tree.toStringTree();
    assertEquals(expecting, found);
  }
View Full Code Here

    String found = g.getRule("B").tree.toStringTree();
    assertEquals(expecting, found);
  }

  @Test public void testCharPlus() throws Exception {
    Grammar g = new Grammar(
        "grammar P;\n"+
        "a : 'a'+;");
    String expecting =
      "(rule a ARG RET scope (BLOCK (ALT (+ (BLOCK (ALT 'a' <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
    String found = g.getRule("a").tree.toStringTree();
    assertEquals(expecting, found);
  }
View Full Code Here

    String found = g.getRule("a").tree.toStringTree();
    assertEquals(expecting, found);
  }

  @Test public void testCharPlusInLexer() throws Exception {
    Grammar g = new Grammar(
        "lexer grammar P;\n"+
        "B : 'b'+;");
    String expecting =
      "(rule B ARG RET scope (BLOCK (ALT (+ (BLOCK (ALT 'b' <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
    String found = g.getRule("B").tree.toStringTree();
    assertEquals(expecting, found);
  }
View Full Code Here

    String found = g.getRule("B").tree.toStringTree();
    assertEquals(expecting, found);
  }

  @Test public void testCharOptional() throws Exception {
    Grammar g = new Grammar(
        "grammar P;\n"+
        "a : 'a'?;");
    String expecting =
      "(rule a ARG RET scope (BLOCK (ALT (? (BLOCK (ALT 'a' <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
    String found = g.getRule("a").tree.toStringTree();
    assertEquals(expecting, found);
  }
View Full Code Here

    String found = g.getRule("a").tree.toStringTree();
    assertEquals(expecting, found);
  }

  @Test public void testCharOptionalInLexer() throws Exception {
    Grammar g = new Grammar(
        "lexer grammar P;\n"+
        "B : 'b'?;");
    String expecting =
      "(rule B ARG RET scope (BLOCK (ALT (? (BLOCK (ALT 'b' <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
    String found = g.getRule("B").tree.toStringTree();
    assertEquals(expecting, found);
  }
View Full Code Here

    String found = g.getRule("B").tree.toStringTree();
    assertEquals(expecting, found);
  }

  @Test public void testCharRangePlus() throws Exception {
    Grammar g = new Grammar(
        "lexer grammar P;\n"+
        "ID : 'a'..'z'+;");
    String expecting =
      "(rule ID ARG RET scope (BLOCK (ALT (+ (BLOCK (ALT (.. 'a' 'z') <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
    String found = g.getRule("ID").tree.toStringTree();
    assertEquals(expecting, found);
  }
View Full Code Here

    String found = g.getRule("ID").tree.toStringTree();
    assertEquals(expecting, found);
  }

  @Test public void testLabel() throws Exception {
    Grammar g = new Grammar(
        "grammar P;\n"+
        "a : x=ID;");
    String expecting =
      "(rule a ARG RET scope (BLOCK (ALT (= x ID) <end-of-alt>) <end-of-block>) <end-of-rule>)";
    String found = g.getRule("a").tree.toStringTree();
    assertEquals(expecting, found);
  }
View Full Code Here

    String found = g.getRule("a").tree.toStringTree();
    assertEquals(expecting, found);
  }

  @Test public void testLabelOfOptional() throws Exception {
    Grammar g = new Grammar(
        "grammar P;\n"+
        "a : x=ID?;");
    String expecting =
      "(rule a ARG RET scope (BLOCK (ALT (? (BLOCK (ALT (= x ID) <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
    String found = g.getRule("a").tree.toStringTree();
    assertEquals(expecting, found);
  }
View Full Code Here

    String found = g.getRule("a").tree.toStringTree();
    assertEquals(expecting, found);
  }

  @Test public void testLabelOfClosure() throws Exception {
    Grammar g = new Grammar(
        "grammar P;\n"+
        "a : x=ID*;");
    String expecting =
      "(rule a ARG RET scope (BLOCK (ALT (* (BLOCK (ALT (= x ID) <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
    String found = g.getRule("a").tree.toStringTree();
    assertEquals(expecting, found);
  }
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.