diff --git a/src/main/java/org/sablecc/sablecc/lexer/Lexer.java b/src/main/java/org/sablecc/sablecc/lexer/Lexer.java index f8787a26177974615f484c54a4ad8aede6f99fa4..438b84dc1eeb712f6086a4e75e3eaaa9f9a2588f 100644 --- a/src/main/java/org/sablecc/sablecc/lexer/Lexer.java +++ b/src/main/java/org/sablecc/sablecc/lexer/Lexer.java @@ -390,17 +390,17 @@ public class Lexer } /** - * @deprecated This method doesn't restore line/column info correctly in some cases - * (if a token begins in the middle of a CRLF newline pair). - * There is no planned replacement. * @param tok the token to push back onto the input * @throws IOException when thrown by {@link PushbackReader#unread(int)} */ - @Deprecated protected void unread(Token tok) throws IOException { String tokenText = tok.getText(); int length = tokenText.length(); + if(this.cr || (length > 0 && tokenText.charAt(0) == '\n')) + { + throw new IOException("Cannot unread a token containing a partial newline"); + } for(int i = length - 1; i >= 0; i--) { diff --git a/src/main/resources/org/sablecc/sablecc/lexer.txt b/src/main/resources/org/sablecc/sablecc/lexer.txt index d070d6e7502f9dd8496892798ce59bfeecc82f75..1577bea9cee383c6a0c78aba74cd632408dd48af 100644 --- a/src/main/resources/org/sablecc/sablecc/lexer.txt +++ b/src/main/resources/org/sablecc/sablecc/lexer.txt @@ -284,17 +284,17 @@ Macro:LexerBody } /** - * @deprecated This method doesn't restore line/column info correctly in some cases - * (if a token begins in the middle of a CRLF newline pair). - * There is no planned replacement. * @param tok the token to push back onto the input * @throws IOException when thrown by {@link PushbackReader#unread(int)} */ - @Deprecated protected void unread(Token tok) throws IOException { String tokenText = tok.getText(); int length = tokenText.length(); + if(this.cr || (length > 0 && tokenText.charAt(0) == '\n')) + { + throw new IOException("Cannot unread a token containing a partial newline"); + } for(int i = length - 1; i >= 0; i--) {