Search in sources :

Example 11 with BufferedTokenStream

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

the class TestTokenStream method testBufferedTokenStreamReuseAfterFill.

/**
 * This is a targeted regression test for antlr/antlr4#1584 ({@link BufferedTokenStream} cannot be reused after EOF).
 */
@Test
public void testBufferedTokenStreamReuseAfterFill() {
    CharStream firstInput = new ANTLRInputStream("A");
    BufferedTokenStream tokenStream = new BufferedTokenStream(new VisitorBasicLexer(firstInput));
    tokenStream.fill();
    Assert.assertEquals(2, tokenStream.size());
    Assert.assertEquals(VisitorBasicLexer.A, tokenStream.get(0).getType());
    Assert.assertEquals(Token.EOF, tokenStream.get(1).getType());
    CharStream secondInput = new ANTLRInputStream("AA");
    tokenStream.setTokenSource(new VisitorBasicLexer(secondInput));
    tokenStream.fill();
    Assert.assertEquals(3, tokenStream.size());
    Assert.assertEquals(VisitorBasicLexer.A, tokenStream.get(0).getType());
    Assert.assertEquals(VisitorBasicLexer.A, tokenStream.get(1).getType());
    Assert.assertEquals(Token.EOF, tokenStream.get(2).getType());
}
Also used : BufferedTokenStream(org.antlr.v4.runtime.BufferedTokenStream) CharStream(org.antlr.v4.runtime.CharStream) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) Test(org.junit.Test)

Aggregations

CharStream (org.antlr.v4.runtime.CharStream)8 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)6 UnbufferedCharStream (org.antlr.v4.runtime.UnbufferedCharStream)6 StringReader (java.io.StringReader)5 BufferedTokenStream (org.antlr.v4.runtime.BufferedTokenStream)5 CommonTokenFactory (org.antlr.v4.runtime.CommonTokenFactory)5 TitanListener (org.eclipse.titan.common.parsers.TitanListener)5 IOException (java.io.IOException)4 Reader (java.io.Reader)4 TITANMarker (org.eclipse.titan.common.parsers.TITANMarker)3 Location (org.eclipse.titan.designer.AST.Location)3 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)2 CommonToken (org.antlr.v4.runtime.CommonToken)2 Token (org.antlr.v4.runtime.Token)2 Test (org.junit.Test)2 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 ArrayDeque (java.util.ArrayDeque)1 ExecutionException (java.util.concurrent.ExecutionException)1