diff options
author | Lysandros Nikolaou <lisandrosnik@gmail.com> | 2020-10-27 00:42:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-27 00:42:04 +0200 |
commit | bca701403253379409dece03053dbd739c0bd059 (patch) | |
tree | 9222677d56d4669ac00f734ffeb7d72797bb6a89 /Tools/peg_generator | |
parent | bpo-42157: Convert unicodedata.UCD to heap type (GH-22991) (diff) | |
download | cpython-bca701403253379409dece03053dbd739c0bd059.tar.gz cpython-bca701403253379409dece03053dbd739c0bd059.tar.bz2 cpython-bca701403253379409dece03053dbd739c0bd059.zip |
bpo-42123: Run the parser two times and only enable invalid rules on the second run (GH-22111)
* Implement running the parser a second time for the errors messages
The first parser run is only responsible for detecting whether
there is a `SyntaxError` or not. If there isn't the AST gets returned.
Otherwise, the parser is run a second time with all the `invalid_*`
rules enabled so that all the customized error messages get produced.
Diffstat (limited to 'Tools/peg_generator')
-rw-r--r-- | Tools/peg_generator/pegen/c_generator.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Tools/peg_generator/pegen/c_generator.py b/Tools/peg_generator/pegen/c_generator.py index 1a814aad11c..52bdb844e6b 100644 --- a/Tools/peg_generator/pegen/c_generator.py +++ b/Tools/peg_generator/pegen/c_generator.py @@ -736,7 +736,10 @@ class CParserGenerator(ParserGenerator, GrammarVisitor): def visit_Alt( self, node: Alt, is_loop: bool, is_gather: bool, rulename: Optional[str] ) -> None: - self.print(f"{{ // {node}") + if len(node.items) == 1 and str(node.items[0]).startswith('invalid_'): + self.print(f"if (p->call_invalid_rules) {{ // {node}") + else: + self.print(f"{{ // {node}") with self.indent(): self._check_for_errors() node_str = str(node).replace('"', '\\"') |