Search in sources :

Example 16 with IntervalSet

use of org.antlr.v4.runtime.misc.IntervalSet in project antlr4 by antlr.

the class UnicodeDataTemplateController method addIntervalForCategory.

private static void addIntervalForCategory(Map<String, IntervalSet> categoryMap, String categoryName, int start, int finish) {
    IntervalSet intervalSet = categoryMap.get(categoryName);
    if (intervalSet == null) {
        intervalSet = new IntervalSet();
        categoryMap.put(categoryName, intervalSet);
    }
    intervalSet.add(start, finish);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet)

Example 17 with IntervalSet

use of org.antlr.v4.runtime.misc.IntervalSet in project antlr4 by antlr.

the class TestEscapeSequenceParsing method testParseUnicodePropertyInverted.

@Test
public void testParseUnicodePropertyInverted() {
    IntervalSet expected = IntervalSet.of(0, 66559);
    expected.add(66640, Character.MAX_CODE_POINT);
    assertEquals(new Result(Result.Type.PROPERTY, -1, expected, 11), EscapeSequenceParsing.parseEscape("\\P{Deseret}", 0));
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Result(org.antlr.v4.misc.EscapeSequenceParsing.Result) Test(org.junit.Test)

Example 18 with IntervalSet

use of org.antlr.v4.runtime.misc.IntervalSet in project antlr4 by antlr.

the class TestIntervalSet method testEmptyIntersectionSingleElements.

@Test
public void testEmptyIntersectionSingleElements() throws Exception {
    IntervalSet s = IntervalSet.of('a');
    IntervalSet s2 = IntervalSet.of('d');
    String expecting = "{}";
    String result = (s.and(s2)).toString();
    assertEquals(expecting, result);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Test(org.junit.Test)

Example 19 with IntervalSet

use of org.antlr.v4.runtime.misc.IntervalSet in project antlr4 by antlr.

the class TestIntervalSet method testNotRIntersectionNotT.

/** The following was broken:
	    {''..'s', 'u'..'￾'} & {''..'q', 's'..'￾'}=
	    {''..'q', 's'}!!!! broken...
	 	'q' is 113 ascii
	 	'u' is 117
	*/
@Test
public void testNotRIntersectionNotT() throws Exception {
    IntervalSet s = IntervalSet.of(0, 's');
    s.add('u', 200);
    IntervalSet s2 = IntervalSet.of(0, 'q');
    s2.add('s', 200);
    String expecting = "{0..113, 115, 117..200}";
    String result = (s.and(s2)).toString();
    assertEquals(expecting, result);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Test(org.junit.Test)

Example 20 with IntervalSet

use of org.antlr.v4.runtime.misc.IntervalSet in project antlr4 by antlr.

the class TestIntervalSet method testComplement3.

@Test
public void testComplement3() throws Exception {
    IntervalSet s = IntervalSet.of(1, 96);
    s.add(99, Lexer.MAX_CHAR_VALUE);
    String expecting = "{97..98}";
    String result = (s.complement(1, Lexer.MAX_CHAR_VALUE)).toString();
    assertEquals(expecting, result);
}
Also used : IntervalSet(org.antlr.v4.runtime.misc.IntervalSet) Test(org.junit.Test)

Aggregations

IntervalSet (org.antlr.v4.runtime.misc.IntervalSet)84 Test (org.junit.Test)48 ATNState (org.antlr.v4.runtime.atn.ATNState)11 GrammarAST (org.antlr.v4.tool.ast.GrammarAST)10 ATN (org.antlr.v4.runtime.atn.ATN)8 ArrayList (java.util.ArrayList)7 Grammar (org.antlr.v4.tool.Grammar)7 Interval (org.antlr.v4.runtime.misc.Interval)6 SetTransition (org.antlr.v4.runtime.atn.SetTransition)5 UnicodeSet (com.ibm.icu.text.UnicodeSet)4 HashMap (java.util.HashMap)4 Token (org.antlr.runtime.Token)4 NotSetTransition (org.antlr.v4.runtime.atn.NotSetTransition)4 BaseJavaTest (org.antlr.v4.test.runtime.java.BaseJavaTest)4 LinkedHashMap (java.util.LinkedHashMap)3 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)3 AtomTransition (org.antlr.v4.runtime.atn.AtomTransition)3 DecisionState (org.antlr.v4.runtime.atn.DecisionState)3 RuleTransition (org.antlr.v4.runtime.atn.RuleTransition)3 Transition (org.antlr.v4.runtime.atn.Transition)3