Search in sources :

Example 6 with Vocabulary

use of org.antlr.v4.runtime.Vocabulary in project antlr4 by antlr.

the class TestIntervalSet method testNotSetEdgeElement.

@Test
public void testNotSetEdgeElement() throws Exception {
    IntervalSet vocabulary = IntervalSet.of(1, 2);
    IntervalSet s = IntervalSet.of(1);
    String expecting = "2";
    String result = (s.complement(vocabulary)).toString();
    assertEquals(expecting, result);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Test(org.junit.Test)

Example 7 with Vocabulary

use of org.antlr.v4.runtime.Vocabulary in project antlr4 by antlr.

the class TestVocabulary method testVocabularyFromTokenNames.

@Test
public void testVocabularyFromTokenNames() {
    String[] tokenNames = { "<INVALID>", "TOKEN_REF", "RULE_REF", "'//'", "'/'", "'*'", "'!'", "ID", "STRING" };
    Vocabulary vocabulary = VocabularyImpl.fromTokenNames(tokenNames);
    Assert.assertNotNull(vocabulary);
    Assert.assertEquals("EOF", vocabulary.getSymbolicName(Token.EOF));
    for (int i = 0; i < tokenNames.length; i++) {
        Assert.assertEquals(tokenNames[i], vocabulary.getDisplayName(i));
        if (tokenNames[i].startsWith("'")) {
            Assert.assertEquals(tokenNames[i], vocabulary.getLiteralName(i));
            Assert.assertNull(vocabulary.getSymbolicName(i));
        } else if (Character.isUpperCase(tokenNames[i].charAt(0))) {
            Assert.assertNull(vocabulary.getLiteralName(i));
            Assert.assertEquals(tokenNames[i], vocabulary.getSymbolicName(i));
        } else {
            Assert.assertNull(vocabulary.getLiteralName(i));
            Assert.assertNull(vocabulary.getSymbolicName(i));
        }
    }
}
Also used : Vocabulary(org.antlr.v4.runtime.Vocabulary) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 IntervalSet (org.antlr.v4.runtime.misc.IntervalSet)5 Vocabulary (org.antlr.v4.runtime.Vocabulary)2