Search in sources :

Example 1 with Vocabulary

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

the class TestIntervalSet method testNotSingleElement.

@Test
public void testNotSingleElement() throws Exception {
    IntervalSet vocabulary = IntervalSet.of(1, 1000);
    vocabulary.add(2000, 3000);
    IntervalSet s = IntervalSet.of(50, 50);
    String expecting = "{1..49, 51..1000, 2000..3000}";
    String result = (s.complement(vocabulary)).toString();
    assertEquals(expecting, result);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Test(org.junit.Test)

Example 2 with Vocabulary

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

the class TestIntervalSet method testNotEqualSet.

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

Example 3 with Vocabulary

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

the class ParserATNSimulator method getTokenName.

public String getTokenName(int t) {
    if (t == Token.EOF) {
        return "EOF";
    }
    Vocabulary vocabulary = parser != null ? parser.getVocabulary() : VocabularyImpl.EMPTY_VOCABULARY;
    String displayName = vocabulary.getDisplayName(t);
    if (displayName.equals(Integer.toString(t))) {
        return displayName;
    }
    return displayName + "<" + t + ">";
}
Also used : Vocabulary(org.antlr.v4.runtime.Vocabulary)

Example 4 with Vocabulary

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

the class TestIntervalSet method testNotSetFragmentedVocabulary.

@Test
public void testNotSetFragmentedVocabulary() throws Exception {
    IntervalSet vocabulary = IntervalSet.of(1, 255);
    vocabulary.add(1000, 2000);
    vocabulary.add(9999);
    IntervalSet s = IntervalSet.of(50, 60);
    s.add(3);
    s.add(250, 300);
    // this is outside range of vocab and should be ignored
    s.add(10000);
    String expecting = "{1..2, 4..49, 61..249, 1000..2000, 9999}";
    String result = (s.complement(vocabulary)).toString();
    assertEquals(expecting, result);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Test(org.junit.Test)

Example 5 with Vocabulary

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

the class TestIntervalSet method testNotSet.

@Test
public void testNotSet() throws Exception {
    IntervalSet vocabulary = IntervalSet.of(1, 1000);
    IntervalSet s = IntervalSet.of(50, 60);
    s.add(5);
    s.add(250, 300);
    String expecting = "{1..4, 6..49, 61..249, 301..1000}";
    String result = (s.complement(vocabulary)).toString();
    assertEquals(expecting, result);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) 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