From 58fb156edda1a0e924a38bfed494bd06cb09c9a3 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Tue, 2 Feb 2021 19:54:22 +0000 Subject: 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. --- Doc/tools/extensions/peg_highlight.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Doc') diff --git a/Doc/tools/extensions/peg_highlight.py b/Doc/tools/extensions/peg_highlight.py index 9a2acb7f320..4ade1bfeaa0 100644 --- a/Doc/tools/extensions/peg_highlight.py +++ b/Doc/tools/extensions/peg_highlight.py @@ -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)), -- cgit v1.2.3-65-gdbad