Skip to content

Commit 0148f1c

Browse files
otethaltomasstupka
authored andcommitted
Fix docstring parsing
1 parent 02da3b3 commit 0148f1c

File tree

1 file changed

+11
-1
lines changed
  • graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser

1 file changed

+11
-1
lines changed

graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/AbstractParser.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ public enum TargetsType {
9191
protected int level = 0;
9292
protected boolean callInvalidRules = false;
9393

94+
private boolean isInteractive;
95+
private boolean parsingStarted;
96+
9497
/**
9598
* Indicates, whether there was found an error
9699
*/
@@ -140,6 +143,7 @@ public ErrorCallback getErrorCallback() {
140143
}
141144

142145
public SSTNode parse(InputType inputType) {
146+
isInteractive = inputType == InputType.SINGLE;
143147
SSTNode res = runParser(inputType);
144148
if (res == null) {
145149
resetParserState();
@@ -265,7 +269,13 @@ public Token getAndInitializeToken() {
265269
}
266270
reset(pos);
267271

268-
// TODO: handle reaching end in single_input mode
272+
if (isInteractive && token.type == Token.Kind.ENDMARKER && parsingStarted) {
273+
token.type = Token.Kind.NEWLINE;
274+
parsingStarted = false;
275+
// TODO: handle implicit DEDENT (PyPARSE_DONT_IMPLY_DEDENT)
276+
} else {
277+
parsingStarted = true;
278+
}
269279
return initializeToken(token);
270280
}
271281

0 commit comments

Comments
 (0)