mirror of
https://github.com/python/cpython.git
synced 2025-11-01 10:45:30 +00:00
bpo-42997: Improve error message for missing : before suites (GH-24292)
* Add to the peg generator a new directive ('&&') that allows to expect
a token and hard fail the parsing if the token is not found. This
allows to quickly emmit syntax errors for missing tokens.
* Use the new grammar element to hard-fail if the ':' is missing before
suites.
This commit is contained in:
parent
802b645e81
commit
58fb156edd
11 changed files with 1219 additions and 428 deletions
|
|
@ -27,6 +27,12 @@ class PEGLexer(RegexLexer):
|
|||
tokens = {
|
||||
"ws": [(r"\n", Text), (r"\s+", Text), (r"#.*$", Comment.Singleline),],
|
||||
"lookaheads": [
|
||||
# Forced tokens
|
||||
(r"(&&)(?=\w+\s?)", bygroups(None)),
|
||||
(r"(&&)(?='.+'\s?)", bygroups(None)),
|
||||
(r'(&&)(?=".+"\s?)', bygroups(None)),
|
||||
(r"(&&)(?=\(.+\)\s?)", bygroups(None)),
|
||||
|
||||
(r"(?<=\|\s)(&\w+\s?)", bygroups(None)),
|
||||
(r"(?<=\|\s)(&'.+'\s?)", bygroups(None)),
|
||||
(r'(?<=\|\s)(&".+"\s?)', bygroups(None)),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue