Skip to content
Permalink
Browse files
Remove unnecessary 'invalid_primary' rule in the parser (GH-27186)
  • Loading branch information
pablogsal committed Jul 16, 2021
1 parent 000e70a commit a283ef116ba909f133a8e16bb8d17d9e613831d8
Showing with 239 additions and 309 deletions.
  1. +0 βˆ’3 Grammar/python.gram
  2. +1 βˆ’1 Lib/test/test_exceptions.py
  3. +1 βˆ’1 Lib/test/test_syntax.py
  4. +237 βˆ’304 Parser/parser.c
@@ -666,7 +666,6 @@ await_primary[expr_ty] (memo):
| AWAIT a=primary { CHECK_VERSION(expr_ty, 5, "Await expressions are", _PyAST_Await(a, EXTRA)) }
| primary
primary[expr_ty]:
| invalid_primary # must be before 'primay genexp' because of invalid_genexp
| a=primary '.' b=NAME { _PyAST_Attribute(a, b->v.Name.id, Load, EXTRA) }
| a=primary b=genexp { _PyAST_Call(a, CHECK(asdl_expr_seq*, (asdl_expr_seq*)_PyPegen_singleton_seq(p, b)), NULL, EXTRA) }
| a=primary '(' b=[arguments] ')' {
@@ -893,8 +892,6 @@ invalid_del_stmt:
RAISE_SYNTAX_ERROR_INVALID_TARGET(DEL_TARGETS, a) }
invalid_block:
| NEWLINE !INDENT { RAISE_INDENTATION_ERROR("expected an indented block") }
invalid_primary:
| primary a='{' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "invalid syntax") }
invalid_comprehension:
| ('[' | '(' | '{') a=starred_expression for_if_clauses {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "iterable unpacking cannot be used in comprehension") }
@@ -209,7 +209,7 @@ def testSyntaxErrorOffset(self):
check(b'Python = "\xcf\xb3\xf2\xee\xed" +', 1, 18)
check('x = "a', 1, 5)
check('lambda x: x = 2', 1, 1)
check('f{a + b + c}', 1, 2)
check('f{a + b + c}', 1, 1)
check('[file for str(file) in []\n])', 2, 2)
check('a = Β« hello Β» Β« world Β»', 1, 5)
check('[\nfile\nfor str(file)\nin\n[]\n]', 3, 5)
@@ -1305,7 +1305,7 @@ def test_expression_with_assignment(self):
)

def test_curly_brace_after_primary_raises_immediately(self):
self._check_error("f{", "invalid syntax", mode="single")
self._check_error("f{}", "invalid syntax", mode="single")

def test_assign_call(self):
self._check_error("f() = 1", "assign")

0 comments on commit a283ef1

Please sign in to comment.