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:
Pablo Galindo 2021-02-02 19:54:22 +00:00 committed by GitHub
parent 802b645e81
commit 58fb156edd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 1219 additions and 428 deletions

View file

@ -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)),