Skip to content

Commit 208a0d5

Browse files
committed
[GR-20955] Fix python try grammar
PullRequest: graalpython/883
2 parents 06170ef + bc647d0 commit 208a0d5

File tree

4 files changed

+735
-714
lines changed

4 files changed

+735
-714
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/grammar/TryTests.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates.
33
* Copyright (c) 2013, Regents of the University of California
44
*
55
* All rights reserved.
@@ -27,6 +27,7 @@
2727

2828
import org.junit.Test;
2929

30+
import static com.oracle.graal.python.test.PythonTests.assertLastLineErrorContains;
3031
import static com.oracle.graal.python.test.PythonTests.assertPrints;
3132

3233
public class TryTests {
@@ -185,4 +186,10 @@ public void tupleExceptTypes() {
185186

186187
assertPrints("", source);
187188
}
189+
190+
@Test
191+
public void tryGrammarError() {
192+
assertLastLineErrorContains("SyntaxError", "try: 1+1\n");
193+
assertLastLineErrorContains("SyntaxError", "try:\n 1+1\n");
194+
}
188195
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017-2019, Oracle and/or its affiliates.
2+
* Copyright (c) 2017-2020, Oracle and/or its affiliates.
33
* Copyright (c) 2014 by Bart Kiers
44
*
55
* The MIT License (MIT)
@@ -887,11 +887,11 @@ try_stmt
887887
SSTNode finallyStatement = null;
888888
}
889889
(
890-
( except_clause
891-
{ push($except_clause.result); } )+
890+
( except_clause { push($except_clause.result); } )+
892891
( 'else' ':' suite { elseStatement = $suite.result; } )?
893-
)?
894-
( 'finally' ':' suite { finallyStatement = $suite.result; } )?
892+
( 'finally' ':' suite { finallyStatement = $suite.result; } )? |
893+
'finally' ':' suite { finallyStatement = $suite.result; }
894+
)
895895
{ push(new TrySSTNode($body.result, getArray(start, ExceptSSTNode[].class), elseStatement, finallyStatement, getStartIndex($ctx), getLastIndex($ctx))); }
896896
;
897897

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

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)