Search in sources :

Example 1 with UnbufferedCharStream

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

the class TestUnbufferedCharStream method testLastChar.

@Test
public void testLastChar() {
    CharStream input = createStream("abcdef");
    input.consume();
    assertEquals('a', input.LA(-1));
    int m1 = input.mark();
    input.consume();
    input.consume();
    input.consume();
    assertEquals('d', input.LA(-1));
    input.seek(2);
    assertEquals('b', input.LA(-1));
    input.release(m1);
    input.seek(3);
    assertEquals('c', input.LA(-1));
    // this special case is not required by the IntStream interface, but
    // UnbufferedCharStream allows it so we have to make sure the resulting
    // state is consistent
    input.seek(2);
    assertEquals('b', input.LA(-1));
}
Also used : CharStream(org.antlr.v4.runtime.CharStream) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) Test(org.junit.Test)

Example 2 with UnbufferedCharStream

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

the class TestUnbufferedCharStream method testNestedMarkReleasedTwice.

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

Example 3 with UnbufferedCharStream

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

the class TestUnbufferedCharStream method testMarkPassedToSeek.

/**
	 * It is not valid to pass a mark to {@link IntStream#seek}, but
	 * {@link UnbufferedCharStream} creates marks in such a way that this
	 * invalid usage results in an {@link IllegalArgumentException}.
	 */
@Test(expected = IllegalArgumentException.class)
public void testMarkPassedToSeek() {
    CharStream input = createStream("");
    int m1 = input.mark();
    input.seek(m1);
}
Also used : CharStream(org.antlr.v4.runtime.CharStream) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) Test(org.junit.Test)

Example 4 with UnbufferedCharStream

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

the class TestUnbufferedCharStream method testConsumeEOF.

/**
	 * The {@link IntStream} interface does not specify the behavior when the
	 * EOF symbol is consumed, but {@link UnbufferedCharStream} handles this
	 * particular case by throwing an {@link IllegalStateException}.
	 */
@Test(expected = IllegalStateException.class)
public void testConsumeEOF() throws Exception {
    CharStream input = createStream("");
    assertEquals(IntStream.EOF, input.LA(1));
    input.consume();
    input.consume();
}
Also used : CharStream(org.antlr.v4.runtime.CharStream) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) Test(org.junit.Test)

Example 5 with UnbufferedCharStream

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

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)

Aggregations

CharStream (org.antlr.v4.runtime.CharStream)6 UnbufferedCharStream (org.antlr.v4.runtime.UnbufferedCharStream)6 Test (org.junit.Test)6 ASPCore2Lexer (at.ac.tuwien.kr.alpha.antlr.ASPCore2Lexer)1 ASPCore2Parser (at.ac.tuwien.kr.alpha.antlr.ASPCore2Parser)1 ParsedProgram (at.ac.tuwien.kr.alpha.grounder.parser.ParsedProgram)1 ParsedTreeVisitor (at.ac.tuwien.kr.alpha.grounder.parser.ParsedTreeVisitor)1 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)1