Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1890 Standalone CR should be recognized as line separator #2519

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion contributors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,5 @@ YYYY/MM/DD, github id, Full name, email
2019/09/10, marcospassos, Marcos Passos, [email protected]
2019/09/10, amorimjuliana, Juliana Amorim, [email protected]
2019/09/17, kaz, Kazuki Sawada, [email protected]
2019/09/28, lmy269, Mingyang Liu, [email protected]
2019/09/28, lmy269, Mingyang Liu, [email protected]
2019/03/24, nixel2007, Nikita Gryzlov, [email protected]
10 changes: 7 additions & 3 deletions runtime/Java/src/org/antlr/v4/runtime/atn/LexerATNSimulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ protected void reset() {
/** The index of the character relative to the beginning of the line 0..n-1 */
protected int charPositionInLine = 0;


public final DFA[] decisionToDFA;
protected int mode = Lexer.DEFAULT_MODE;

Expand Down Expand Up @@ -735,8 +734,13 @@ public void consume(CharStream input) {
if ( curChar=='\n' ) {
line++;
charPositionInLine=0;
}
else {
} else if ( curChar == '\r' ) {
int nextChar = input.LA(2);
if ( nextChar != '\n') {
line++;
charPositionInLine=0;
}
} else {
Comment on lines +737 to +743
Copy link
Member

@KvanTTT KvanTTT Jan 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to change to the following?

Suggested change
} else if ( curChar == '\r' ) {
int nextChar = input.LA(2);
if ( nextChar != '\n') {
line++;
charPositionInLine=0;
}
} else {
} else if ( curChar == '\r' ) {
if (input.LA(2) == '\n') {
input.consume();
}
line++;
charPositionInLine=0;
} else {

It looks more optimal since it does not require reading \n twice.

charPositionInLine++;
}
input.consume();
Expand Down