diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2021-04-15 20:38:45 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-15 20:38:45 (GMT) |
commit | b280248be8e648feb82f3f3ed0050e50b238df7b (patch) | |
tree | fee5117cd4e2111d701422c52e30f3b85349b1a9 /Tools/peg_generator | |
parent | e692f55979980826a5281560c534ef399a8f9848 (diff) | |
download | cpython-b280248be8e648feb82f3f3ed0050e50b238df7b.zip cpython-b280248be8e648feb82f3f3ed0050e50b238df7b.tar.gz cpython-b280248be8e648feb82f3f3ed0050e50b238df7b.tar.bz2 |
bpo-43822: Improve syntax errors for missing commas (GH-25377)
Diffstat (limited to 'Tools/peg_generator')
-rw-r--r-- | Tools/peg_generator/pegen/c_generator.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Tools/peg_generator/pegen/c_generator.py b/Tools/peg_generator/pegen/c_generator.py index 24418ea..d762240 100644 --- a/Tools/peg_generator/pegen/c_generator.py +++ b/Tools/peg_generator/pegen/c_generator.py @@ -46,6 +46,7 @@ _PyPegen_parse(Parser *p) // Initialize keywords p->keywords = reserved_keywords; p->n_keyword_lists = n_keyword_lists; + p->soft_keywords = soft_keywords; return start_rule(p); } @@ -66,6 +67,7 @@ BASE_NODETYPES = { "NAME": NodeTypes.NAME_TOKEN, "NUMBER": NodeTypes.NUMBER_TOKEN, "STRING": NodeTypes.STRING_TOKEN, + "SOFT_KEYWORD": NodeTypes.SOFT_KEYWORD, } @@ -411,6 +413,7 @@ class CParserGenerator(ParserGenerator, GrammarVisitor): if subheader: self.print(subheader) self._setup_keywords() + self._setup_soft_keywords() for i, (rulename, rule) in enumerate(self.todo.items(), 1000): comment = " // Left-recursive" if rule.left_recursive else "" self.print(f"#define {rulename}_type {i}{comment}") @@ -474,6 +477,15 @@ class CParserGenerator(ParserGenerator, GrammarVisitor): self.print("},") self.print("};") + def _setup_soft_keywords(self) -> None: + soft_keywords = sorted(self.callmakervisitor.soft_keywords) + self.print("static char *soft_keywords[] = {") + with self.indent(): + for keyword in soft_keywords: + self.print(f'"{keyword}",') + self.print("NULL,") + self.print("};") + def _set_up_token_start_metadata_extraction(self) -> None: self.print("if (p->mark == p->fill && _PyPegen_fill_token(p) < 0) {") with self.indent(): |