Skip to content

Commit 9bc98cf

Browse files
committed
spaces before EOF are skipped, so check the upcoming token rather than the upcoming char to finish lexing
1 parent 850ba83 commit 9bc98cf

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/antlr/Python3.g4

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ tokens { INDENT, DEDENT }
5757

5858
@Override
5959
public Token nextToken() {
60+
Token next = super.nextToken();
61+
6062
// Check if the end-of-file is ahead to insert any missing DEDENTS and a NEWLINE.
61-
if (_input.LA(1) == EOF && !expandedEOF) {
63+
if (next.getType() == EOF && !expandedEOF) {
6264
expandedEOF = true;
6365
6466
// Remove any trailing EOF tokens from our buffer.
@@ -78,10 +80,10 @@ tokens { INDENT, DEDENT }
7880
}
7981

8082
// Put the EOF back on the token stream.
81-
this.emit(commonToken(Python3Parser.EOF, "<EOF>"));
82-
}
83+
this.emit(next);
8384

84-
Token next = super.nextToken();
85+
next = super.nextToken();
86+
}
8587

8688
if (next.getChannel() == Token.DEFAULT_CHANNEL) {
8789
// Keep track of the last token on the default channel.

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/antlr/Python3Lexer.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,10 @@ public void emit(Token t) {
175175

176176
@Override
177177
public Token nextToken() {
178+
Token next = super.nextToken();
179+
178180
// Check if the end-of-file is ahead to insert any missing DEDENTS and a NEWLINE.
179-
if (_input.LA(1) == EOF && !expandedEOF) {
181+
if (next.getType() == EOF && !expandedEOF) {
180182
expandedEOF = true;
181183

182184
// Remove any trailing EOF tokens from our buffer.
@@ -196,10 +198,10 @@ public Token nextToken() {
196198
}
197199

198200
// Put the EOF back on the token stream.
199-
this.emit(commonToken(Python3Parser.EOF, "<EOF>"));
200-
}
201+
this.emit(next);
201202

202-
Token next = super.nextToken();
203+
next = super.nextToken();
204+
}
203205

204206
if (next.getChannel() == Token.DEFAULT_CHANNEL) {
205207
// Keep track of the last token on the default channel.

0 commit comments

Comments
 (0)