()
| 37 | |
| 38 | |
| 39 | def main() -> None: |
| 40 | parser = argparse.ArgumentParser( |
| 41 | description="Generate the Lib/keywords.py file from the grammar." |
| 42 | ) |
| 43 | parser.add_argument( |
| 44 | "grammar", help="The file with the grammar definition in PEG format" |
| 45 | ) |
| 46 | parser.add_argument( |
| 47 | "tokens_file", help="The file with the token definitions" |
| 48 | ) |
| 49 | parser.add_argument( |
| 50 | "keyword_file", |
| 51 | help="The path to write the keyword definitions", |
| 52 | ) |
| 53 | args = parser.parse_args() |
| 54 | |
| 55 | grammar, _, _ = build_parser(args.grammar) |
| 56 | with open(args.tokens_file) as tok_file: |
| 57 | all_tokens, exact_tok, non_exact_tok = generate_token_definitions(tok_file) |
| 58 | gen = CParserGenerator(grammar, all_tokens, exact_tok, non_exact_tok, file=None) |
| 59 | gen.collect_rules() |
| 60 | |
| 61 | with open(args.keyword_file, 'w') as thefile: |
| 62 | all_keywords = sorted(list(gen.keywords.keys())) |
| 63 | all_soft_keywords = sorted(gen.soft_keywords) |
| 64 | |
| 65 | keywords = "" if not all_keywords else " " + ",\n ".join(map(repr, all_keywords)) |
| 66 | soft_keywords = ( |
| 67 | "" if not all_soft_keywords else " " + ",\n ".join(map(repr, all_soft_keywords)) |
| 68 | ) |
| 69 | thefile.write(TEMPLATE.format(keywords=keywords, soft_keywords=soft_keywords)) |
| 70 | |
| 71 | |
| 72 | if __name__ == "__main__": |
no test coverage detected
searching dependent graphs…