Staging
v0.5.1
v0.5.1
https://github.com/python/cpython
Revision 94bb4b7db2a4eadd299acede204b087aca30c9a2 authored by Miss Islington (bot) on 13 June 2020, 12:44:38 UTC, committed by GitHub on 13 June 2020, 12:44:38 UTC
(cherry picked from commit 29c117202e386bad1d66ae336e2fefa1a1809ee0) Co-authored-by: An Long <aisk@users.noreply.github.com>
1 parent 166d723
Tip revision: 94bb4b7db2a4eadd299acede204b087aca30c9a2 authored by Miss Islington (bot) on 13 June 2020, 12:44:38 UTC
bpo-40834: Fix truncate when sending str object with channel (GH-20555)
bpo-40834: Fix truncate when sending str object with channel (GH-20555)
Tip revision: 94bb4b7
keywordgen.py
"""Generate Lib/keyword.py from the Grammar and Tokens files using pgen"""
import argparse
from .pgen import ParserGenerator
TEMPLATE = r'''
"""Keywords (from "Grammar/Grammar")
This file is automatically generated; please don't muck it up!
To update the symbols in this file, 'cd' to the top directory of
the python source tree and run:
python3 -m Parser.pgen.keywordgen Grammar/Grammar \
Grammar/Tokens \
Lib/keyword.py
Alternatively, you can run 'make regen-keyword'.
"""
__all__ = ["iskeyword", "kwlist"]
kwlist = [
{keywords}
]
iskeyword = frozenset(kwlist).__contains__
'''.lstrip()
EXTRA_KEYWORDS = ["async", "await"]
def main():
parser = argparse.ArgumentParser(
description="Generate the Lib/keywords.py " "file from the grammar."
)
parser.add_argument(
"grammar", type=str, help="The file with the grammar definition in EBNF format"
)
parser.add_argument("tokens", type=str, help="The file with the token definitions")
parser.add_argument(
"keyword_file",
type=argparse.FileType("w"),
help="The path to write the keyword definitions",
)
args = parser.parse_args()
p = ParserGenerator(args.grammar, args.tokens)
grammar = p.make_grammar()
with args.keyword_file as thefile:
all_keywords = sorted(list(grammar.keywords) + EXTRA_KEYWORDS)
keywords = ",\n ".join(map(repr, all_keywords))
thefile.write(TEMPLATE.format(keywords=keywords))
if __name__ == "__main__":
main()
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...