Package org.antlr.tool

Examples of org.antlr.tool.Grammar


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

  @Test public void testRuleLabel() throws Exception {
    Grammar g = new Grammar(
        "grammar P;\n"+
        "a : x=b;\n" +
        "b : ID;\n");
    String expecting =
      "(rule a ARG RET scope (BLOCK (ALT (= x b) <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 testSetLabel() throws Exception {
    Grammar g = new Grammar(
        "grammar P;\n"+
        "a : x=(A|B);\n");
    String expecting =
      "(rule a ARG RET scope (BLOCK (ALT (= x (BLOCK (ALT A <end-of-alt>) (ALT B <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 testNotSetLabel() throws Exception {
    Grammar g = new Grammar(
        "grammar P;\n"+
        "a : x=~(A|B);\n");
    String expecting =
      "(rule a ARG RET scope (BLOCK (ALT (= x (~ (BLOCK (ALT A <end-of-alt>) (ALT B <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 testNotSetListLabel() throws Exception {
    Grammar g = new Grammar(
        "grammar P;\n"+
        "a : x+=~(A|B);\n");
    String expecting =
      "(rule a ARG RET scope (BLOCK (ALT (+= x (~ (BLOCK (ALT A <end-of-alt>) (ALT B <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 testNotSetListLabelInLoop() throws Exception {
    Grammar g = new Grammar(
        "grammar P;\n"+
        "a : x+=~(A|B)+;\n");
    String expecting =
      "(rule a ARG RET scope (BLOCK (ALT (+ (BLOCK (ALT (+= x (~ (BLOCK (ALT A <end-of-alt>) (ALT B <end-of-alt>) <end-of-block>))) <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 testRuleLabelOfPositiveClosure() throws Exception {
    Grammar g = new Grammar(
        "grammar P;\n"+
        "a : x=b+;\n" +
        "b : ID;\n");
    String expecting =
      "(rule a ARG RET scope (BLOCK (ALT (+ (BLOCK (ALT (= x b) <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 testListLabelOfClosure() 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 testListLabelOfClosure2() throws Exception {
    Grammar g = new Grammar(
        "grammar P;\n"+
        "a : x+='int'*;");
    String expecting =
      "(rule a ARG RET scope (BLOCK (ALT (* (BLOCK (ALT (+= x 'int') <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 testRuleListLabelOfPositiveClosure() throws Exception {
    Grammar g = new Grammar(
        "grammar P;\n" +
        "options {output=AST;}\n"+
        "a : x+=b+;\n" +
        "b : ID;\n");
    String expecting =
      "(rule a ARG RET scope (BLOCK (ALT (+ (BLOCK (ALT (+= x b) <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 testRootTokenInStarLoop() throws Exception {
    Grammar g = new Grammar(
        "grammar Expr;\n" +
        "options { output=AST; backtrack=true; }\n" +
        "a : ('*'^)* ;\n")// bug: the synpred had nothing in it
    String expecting =
      "(rule synpred1_Expr ARG RET scope (BLOCK (ALT '*' <end-of-alt>) <end-of-block>) <end-of-rule>)";
    String found = g.getRule("synpred1_Expr").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.