Search in sources :

Example 6 with Result

use of org.antlr.v4.misc.EscapeSequenceParsing.Result in project antlr4 by antlr.

the class TestParseTreeMatcher method testInvertedTags.

@Test
public void testInvertedTags() throws Exception {
    ParseTreePatternMatcher m = new ParseTreePatternMatcher(null, null);
    String result = null;
    try {
        m.split(">expr<");
    } catch (IllegalArgumentException iae) {
        result = iae.getMessage();
    }
    String expected = "tag delimiters out of order in pattern: >expr<";
    assertEquals(expected, result);
}
Also used : ParseTreePatternMatcher(org.antlr.v4.runtime.tree.pattern.ParseTreePatternMatcher) Test(org.junit.Test)

Example 7 with Result

use of org.antlr.v4.misc.EscapeSequenceParsing.Result in project antlr4 by antlr.

the class TestParseTreeMatcher method testDelimiters.

@Test
public void testDelimiters() throws Exception {
    ParseTreePatternMatcher m = new ParseTreePatternMatcher(null, null);
    m.setDelimiters("<<", ">>", "$");
    String result = m.split("<<ID>> = <<expr>> ;$<< ick $>>").toString();
    assertEquals("[ID, ' = ', expr, ' ;<< ick >>']", result);
}
Also used : ParseTreePatternMatcher(org.antlr.v4.runtime.tree.pattern.ParseTreePatternMatcher) Test(org.junit.Test)

Example 8 with Result

use of org.antlr.v4.misc.EscapeSequenceParsing.Result in project antlr4 by antlr.

the class TestParseTreeMatcher method checkPatternMatch.

public ParseTreeMatch checkPatternMatch(String grammar, String startRule, String input, String pattern, String grammarName, boolean invertMatch) throws Exception {
    String grammarFileName = grammarName + ".g4";
    String parserName = grammarName + "Parser";
    String lexerName = grammarName + "Lexer";
    boolean ok = rawGenerateAndBuildRecognizer(grammarFileName, grammar, parserName, lexerName, false);
    assertTrue(ok);
    ParseTree result = execParser(startRule, input, parserName, lexerName);
    ParseTreePattern p = getPattern(grammarName, pattern, startRule);
    ParseTreeMatch match = p.match(result);
    boolean matched = match.succeeded();
    if (invertMatch)
        assertFalse(matched);
    else
        assertTrue(matched);
    return match;
}
Also used : ParseTreePattern(org.antlr.v4.runtime.tree.pattern.ParseTreePattern) ParseTree(org.antlr.v4.runtime.tree.ParseTree) ParseTreeMatch(org.antlr.v4.runtime.tree.pattern.ParseTreeMatch)

Example 9 with Result

use of org.antlr.v4.misc.EscapeSequenceParsing.Result in project antlr4 by antlr.

the class TestParseTreeMatcher method testUnclosedTag.

@Test
public void testUnclosedTag() throws Exception {
    ParseTreePatternMatcher m = new ParseTreePatternMatcher(null, null);
    String result = null;
    try {
        m.split("<expr hi mom");
    } catch (IllegalArgumentException iae) {
        result = iae.getMessage();
    }
    String expected = "unterminated tag in pattern: <expr hi mom";
    assertEquals(expected, result);
}
Also used : ParseTreePatternMatcher(org.antlr.v4.runtime.tree.pattern.ParseTreePatternMatcher) Test(org.junit.Test)

Example 10 with Result

use of org.antlr.v4.misc.EscapeSequenceParsing.Result 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)

Aggregations

Test (org.junit.Test)131 LexerGrammar (org.antlr.v4.tool.LexerGrammar)78 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)52 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)49 LexerInterpreter (org.antlr.v4.runtime.LexerInterpreter)44 ATN (org.antlr.v4.runtime.atn.ATN)44 TokenStreamRewriter (org.antlr.v4.runtime.TokenStreamRewriter)38 IntervalSet (org.antlr.v4.runtime.misc.IntervalSet)38 BaseJavaTest (org.antlr.v4.test.runtime.java.BaseJavaTest)38 ParseTree (org.antlr.v4.runtime.tree.ParseTree)29 ATNState (org.antlr.v4.runtime.atn.ATNState)11 Grammar (org.antlr.v4.tool.Grammar)10 STGroupString (org.stringtemplate.v4.STGroupString)10 ByteBuffer (java.nio.ByteBuffer)8 IntBuffer (java.nio.IntBuffer)8 UTF8CodePointDecoder (org.antlr.v4.runtime.UTF8CodePointDecoder)8 BaseRuntimeTest.antlrOnString (org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString)8 DOTGenerator (org.antlr.v4.tool.DOTGenerator)8 ParserATNFactory (org.antlr.v4.automata.ParserATNFactory)7 Rule (org.antlr.v4.tool.Rule)7