diff --git a/runtime/Java/src/org/antlr/v4/runtime/IntStream.java b/runtime/Java/src/org/antlr/v4/runtime/IntStream.java index 0b0ca6ff8..53166ee2b 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/IntStream.java +++ b/runtime/Java/src/org/antlr/v4/runtime/IntStream.java @@ -79,9 +79,9 @@ public interface IntStream { * filtering streams (e.g. {@link CommonTokenStream} which distinguishes * between "on-channel" and "off-channel" tokens). * - * @throws IllegalStateException if an attempt is made to consume the the - * end of the stream (i.e. if {@code LA(1)==}{@link #EOF EOF} before calling - * {@code consume}). + * @throws IllegalStateException if an attempt is made to consume past + * end of the stream (i.e. if last char == {@link #EOF EOF} before calling + * {@code consume}). Sometimes need to match EOF during prediction. */ void consume(); diff --git a/runtime/Java/src/org/antlr/v4/runtime/UnbufferedCharStream.java b/runtime/Java/src/org/antlr/v4/runtime/UnbufferedCharStream.java index 5f6193b1a..1e98389b2 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/UnbufferedCharStream.java +++ b/runtime/Java/src/org/antlr/v4/runtime/UnbufferedCharStream.java @@ -75,7 +75,7 @@ public class UnbufferedCharStream implements CharStream { /** * This is the {@code LA(-1)} character for the current position. */ - protected int lastChar = -1; + protected int lastChar = -2; // can't be -1 (EOF) /** * When {@code numMarkers > 0}, this is the {@code LA(-1)} character for the @@ -129,7 +129,7 @@ public class UnbufferedCharStream implements CharStream { @Override public void consume() { - if (LA(1) == CharStream.EOF) { + if ( lastChar == CharStream.EOF ) { throw new IllegalStateException("cannot consume EOF"); }