Search in sources :

Example 56 with CharStream

use of org.antlr.v4.runtime.CharStream in project antlr4 by tunnelvisionlabs.

the class TestUnbufferedCharStream method testGetTextBeforeBufferStart.

@Test(expected = UnsupportedOperationException.class)
public void testGetTextBeforeBufferStart() {
    CharStream input = createStream("xyz");
    input.consume();
    int m1 = input.mark();
    assertEquals(1, input.index());
    input.getText(new Interval(0, 1));
}
Also used : CharStream(org.antlr.v4.runtime.CharStream) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) Interval(org.antlr.v4.runtime.misc.Interval) Test(org.junit.Test)

Example 57 with CharStream

use of org.antlr.v4.runtime.CharStream in project antlr4 by tunnelvisionlabs.

the class TestUnbufferedCharStream method testNoChar.

@Test
public void testNoChar() throws Exception {
    CharStream input = createStream("");
    assertEquals(IntStream.EOF, input.LA(1));
    assertEquals(IntStream.EOF, input.LA(2));
}
Also used : CharStream(org.antlr.v4.runtime.CharStream) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) Test(org.junit.Test)

Example 58 with CharStream

use of org.antlr.v4.runtime.CharStream in project antlr4 by tunnelvisionlabs.

the class TestUnbufferedCharStream method testBufferWrapSize1.

@Test
public void testBufferWrapSize1() throws Exception {
    CharStream input = createStream("01234", 1);
    assertEquals('0', input.LA(1));
    input.consume();
    assertEquals('1', input.LA(1));
    input.consume();
    assertEquals('2', input.LA(1));
    input.consume();
    assertEquals('3', input.LA(1));
    input.consume();
    assertEquals('4', input.LA(1));
    input.consume();
    assertEquals(IntStream.EOF, input.LA(1));
}
Also used : CharStream(org.antlr.v4.runtime.CharStream) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) Test(org.junit.Test)

Example 59 with CharStream

use of org.antlr.v4.runtime.CharStream in project antlr4 by tunnelvisionlabs.

the class TestUnbufferedCharStream method testMarkReleaseOutOfOrder.

/**
 * The {@link IntStream} interface does not specify the behavior when marks
 * are not released in the reversed order they were created, but
 * {@link UnbufferedCharStream} handles this case by throwing an
 * {@link IllegalStateException}.
 */
@Test(expected = IllegalStateException.class)
public void testMarkReleaseOutOfOrder() {
    CharStream input = createStream("");
    int m1 = input.mark();
    int m2 = input.mark();
    input.release(m1);
}
Also used : CharStream(org.antlr.v4.runtime.CharStream) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) Test(org.junit.Test)

Example 60 with CharStream

use of org.antlr.v4.runtime.CharStream in project antlr4 by tunnelvisionlabs.

the class TestUnbufferedCharStream method test2CharAhead.

@Test
public void test2CharAhead() throws Exception {
    CharStream input = createStream("xy");
    assertEquals('x', input.LA(1));
    assertEquals('y', input.LA(2));
    assertEquals(IntStream.EOF, input.LA(3));
}
Also used : CharStream(org.antlr.v4.runtime.CharStream) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) Test(org.junit.Test)

Aggregations

CharStream (org.antlr.v4.runtime.CharStream)187 Test (org.junit.Test)93 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)85 UnbufferedCharStream (org.antlr.v4.runtime.UnbufferedCharStream)46 ParseTree (org.antlr.v4.runtime.tree.ParseTree)38 ParseTreeWalker (org.antlr.v4.runtime.tree.ParseTreeWalker)30 IOException (java.io.IOException)28 InputStream (java.io.InputStream)23 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)23 LexerInterpreter (org.antlr.v4.runtime.LexerInterpreter)22 File (java.io.File)21 TokenStream (org.antlr.v4.runtime.TokenStream)21 StringReader (java.io.StringReader)20 CancellationException (java.util.concurrent.CancellationException)20 ConsoleErrorListener (org.antlr.v4.runtime.ConsoleErrorListener)20 CommonTokenFactory (org.antlr.v4.runtime.CommonTokenFactory)18 Token (org.antlr.v4.runtime.Token)18 LexerGrammar (org.antlr.v4.tool.LexerGrammar)18 Utils.toCharStream (clawfc.Utils.toCharStream)15 Path (java.nio.file.Path)14