Skip to content

Commit 0931f2e

Browse files
committed
enhance the grammar of invalid_replacement_field
1 parent 4d91ff9 commit 0931f2e

File tree

4 files changed

+1080
-404
lines changed

4 files changed

+1080
-404
lines changed

Grammar/python.gram

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,10 +1362,18 @@ invalid_replacement_field:
13621362
| '{' a=':' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "f-string: expression required before ':'") }
13631363
| '{' a='!' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "f-string: expression required before '!'") }
13641364
| '{' a='}' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "f-string: empty expression not allowed") }
1365-
| '{' (yield_expr | star_expressions) "="? invalid_conversion_character
1366-
| '{' (yield_expr | star_expressions) "="? [ "!" NAME ] [ ':' fstring_format_spec* ] !'}' {
1367-
RAISE_SYNTAX_ERROR("f-string: expecting '}'")
1368-
}
1365+
| '{' (yield_expr | star_expressions) !('=' | '!' | ':' | '}') {
1366+
PyErr_Occurred() ? NULL : RAISE_SYNTAX_ERROR_ON_NEXT_TOKEN("f-string: expecting '=', or '!', or ':', or '}'") }
1367+
| '{' (yield_expr | star_expressions) '=' !('!' | ':' | '}') {
1368+
PyErr_Occurred() ? NULL : RAISE_SYNTAX_ERROR_ON_NEXT_TOKEN("f-string: expecting '!', or ':', or '}'") }
1369+
| '{' (yield_expr | star_expressions) '='? invalid_conversion_character
1370+
| '{' (yield_expr | star_expressions) '='? ['!' NAME] !(':' | '}') {
1371+
PyErr_Occurred() ? NULL : RAISE_SYNTAX_ERROR_ON_NEXT_TOKEN("f-string: expecting ':' or '}'") }
1372+
| '{' (yield_expr | star_expressions) '='? ['!' NAME] ':' fstring_format_spec* !'}' {
1373+
PyErr_Occurred() ? NULL : RAISE_SYNTAX_ERROR_ON_NEXT_TOKEN("f-string: expecting '}', or format specs") }
1374+
| '{' (yield_expr | star_expressions) '='? ['!' NAME] !'}' {
1375+
PyErr_Occurred() ? NULL : RAISE_SYNTAX_ERROR_ON_NEXT_TOKEN("f-string: expecting '}'") }
1376+
13691377
invalid_conversion_character:
1370-
| a="!" &(':'|'}') { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "f-string: missed conversion character") }
1371-
| a="!" !NAME { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "f-string: invalid conversion character") }
1378+
| '!' &(':' | '}') { RAISE_SYNTAX_ERROR_ON_NEXT_TOKEN("f-string: missing conversion character") }
1379+
| '!' !NAME { RAISE_SYNTAX_ERROR_ON_NEXT_TOKEN("f-string: invalid conversion character") }

0 commit comments

Comments
 (0)