Package org.antlr.tool

Examples of org.antlr.tool.Grammar


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

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


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

  @Test public void testTokensRules() throws Exception {
    Grammar pg = new Grammar(
      "parser grammar p;\n"+
      "a : (INT|FLOAT|WS)+;\n");
    Grammar g = new Grammar();
    g.importTokenVocabulary(pg);
    g.setFileName("<string>");
    g.setGrammarContent(
      "lexer grammar t;\n"+
      "INT : (DIGIT)+ ;\n"+
      "FLOAT : (DIGIT)+ '.' (DIGIT)* ;\n"+
      "fragment DIGIT : '0'..'9';\n" +
      "WS : (' ')+ {channel=99;};\n");
View Full Code Here

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

  @Test public void testA() throws Exception {
    Grammar g = new Grammar(
        "parser grammar P;\n"+
        "a : A;");
    String expecting =
      "(rule a ARG RET scope (BLOCK (ALT A <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 testEmptyAlt() throws Exception {
    Grammar g = new Grammar(
        "parser grammar P;\n"+
        "a : ;");
    String expecting =
      "(rule a ARG RET scope (BLOCK (ALT epsilon <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 testNakeRulePlusInLexer() throws Exception {
    Grammar g = new Grammar(
        "lexer grammar P;\n"+
        "A : B+;\n" +
        "B : 'a';");
    String expecting =
      "(rule A 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("A").tree.toStringTree();
    assertEquals(expecting, found);
  }
View Full Code Here

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

  @Test public void testRulePlus() throws Exception {
    Grammar g = new Grammar(
        "parser grammar P;\n"+
        "a : (b)+;\n" +
        "b : B;");
    String expecting =
      "(rule a 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("a").tree.toStringTree();
    assertEquals(expecting, found);
  }
View Full Code Here

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

  @Test public void testNakedRulePlus() throws Exception {
    Grammar g = new Grammar(
        "parser grammar P;\n"+
        "a : b+;\n" +
        "b : B;");
    String expecting =
      "(rule a 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("a").tree.toStringTree();
    assertEquals(expecting, found);
  }
View Full Code Here

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

  @Test public void testRuleOptional() throws Exception {
    Grammar g = new Grammar(
        "parser grammar P;\n"+
        "a : (b)?;\n" +
        "b : B;");
    String expecting =
      "(rule a 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("a").tree.toStringTree();
    assertEquals(expecting, found);
  }
View Full Code Here

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

  @Test public void testNakedRuleOptional() throws Exception {
    Grammar g = new Grammar(
        "parser grammar P;\n"+
        "a : b?;\n" +
        "b : B;");
    String expecting =
      "(rule a 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("a").tree.toStringTree();
    assertEquals(expecting, found);
  }
View Full Code Here

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

  @Test public void testRuleStar() throws Exception {
    Grammar g = new Grammar(
        "parser grammar P;\n"+
        "a : (b)*;\n" +
        "b : B;");
    String expecting =
      "(rule a 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("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.