diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2020-05-08 03:38:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-08 03:38:44 +0100 |
commit | db9163ceef31ba00ccb23226917f9c8e9142a0b8 (patch) | |
tree | db8ef3bf719774bf6d1f0aab96f1cf65403a77b7 | |
parent | b7a78ca74ab539943ab11b5c4c9cfab7f5b7ff5a (diff) | |
download | cpython-git-db9163ceef31ba00ccb23226917f9c8e9142a0b8.tar.gz |
bpo-40555: Check for p->error_indicator in loop rules after the main loop is done (GH-19986)
-rw-r--r-- | Lib/test/test_eof.py | 9 | ||||
-rw-r--r-- | Parser/pegen/parse.c | 54 | ||||
-rw-r--r-- | Tools/peg_generator/pegen/c_generator.py | 2 |
3 files changed, 37 insertions, 28 deletions
diff --git a/Lib/test/test_eof.py b/Lib/test/test_eof.py index 9ef8eb1187..bebad31061 100644 --- a/Lib/test/test_eof.py +++ b/Lib/test/test_eof.py @@ -26,6 +26,15 @@ class EOFTestCase(unittest.TestCase): else: raise support.TestFailed + def test_eof_with_line_continuation(self): + expect = "unexpected EOF while parsing (<string>, line 1)" + try: + compile('"\\xhh" \\', '<string>', 'exec', dont_inherit=True) + except SyntaxError as msg: + self.assertEqual(str(msg), expect) + else: + raise support.TestFailed + def test_line_continuation_EOF(self): """A continuation at the end of input must be an error; bpo2180.""" expect = 'unexpected EOF while parsing (<string>, line 1)' diff --git a/Parser/pegen/parse.c b/Parser/pegen/parse.c index 3a08abbca5..ae86841e86 100644 --- a/Parser/pegen/parse.c +++ b/Parser/pegen/parse.c @@ -11437,7 +11437,7 @@ _loop1_11_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -11876,7 +11876,7 @@ _loop1_22_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -12252,7 +12252,7 @@ _loop1_31_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -12911,7 +12911,7 @@ _loop1_47_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -13267,7 +13267,7 @@ _loop1_56_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -13369,7 +13369,7 @@ _loop1_58_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -13422,7 +13422,7 @@ _loop1_59_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -13475,7 +13475,7 @@ _loop1_60_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -13577,7 +13577,7 @@ _loop1_62_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -13679,7 +13679,7 @@ _loop1_64_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -13781,7 +13781,7 @@ _loop1_66_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -13834,7 +13834,7 @@ _loop1_67_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -14007,7 +14007,7 @@ _loop1_71_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -14145,7 +14145,7 @@ _loop1_74_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -14345,7 +14345,7 @@ _loop1_78_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -14447,7 +14447,7 @@ _loop1_80_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -14500,7 +14500,7 @@ _loop1_81_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -14553,7 +14553,7 @@ _loop1_82_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -14655,7 +14655,7 @@ _loop1_84_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -14757,7 +14757,7 @@ _loop1_86_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -14859,7 +14859,7 @@ _loop1_88_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -14912,7 +14912,7 @@ _loop1_89_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -14965,7 +14965,7 @@ _loop1_90_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -15018,7 +15018,7 @@ _loop1_91_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -15358,7 +15358,7 @@ _loop1_99_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -15567,7 +15567,7 @@ _loop1_104_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } @@ -17165,7 +17165,7 @@ _loop1_145_rule(Parser *p) } p->mark = mark; } - if (n == 0) { + if (n == 0 || p->error_indicator) { PyMem_Free(children); return NULL; } diff --git a/Tools/peg_generator/pegen/c_generator.py b/Tools/peg_generator/pegen/c_generator.py index 3bf6d9ed6a..b7a9942c2f 100644 --- a/Tools/peg_generator/pegen/c_generator.py +++ b/Tools/peg_generator/pegen/c_generator.py @@ -525,7 +525,7 @@ class CParserGenerator(ParserGenerator, GrammarVisitor): rulename=node.name if memoize else None, ) if is_repeat1: - self.print("if (n == 0) {") + self.print("if (n == 0 || p->error_indicator) {") with self.indent(): self.print("PyMem_Free(children);") self.print("return NULL;") |