Sitelet https://web.archive.org/web/20220508062759/https://github.com/python/cpython/pull/12456
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-36143: Regenerate Lib/keyword.py from the Grammar and Tokens file using pgen #12456

Merged
merged 5 commits into from Mar 25, 2019

Conversation

Copy link
Member

@pablogsal pablogsal commented Mar 20, 2019 •

Copy link
Member

@vstinner vstinner left a comment

LGTM.

Travis CI tests passed on this PR: it runs "make regean-all" and make sure that generated files are unchanged. So it means that your generator works ;-)

I proposed minor coding style changes, it's up to you to ignore them or not :-)

Parser/pgen/keywordgen.py Outdated Show resolved Hide resolved
Parser/pgen/keywordgen.py Outdated Show resolved Hide resolved
Parser/pgen/keywordgen.py Outdated Show resolved Hide resolved
Parser/pgen/keywordgen.py Outdated Show resolved Hide resolved
Parser/pgen/keywordgen.py Outdated Show resolved Hide resolved
Parser/pgen/keywordgen.py Outdated Show resolved Hide resolved
Copy link
Member

@vstinner vstinner left a comment

LGTM. It's now perfect, thanks :-)

Lib/keyword.py Outdated Show resolved Hide resolved
Parser/pgen/keywordgen.py Outdated Show resolved Hide resolved
)
parser.add_argument(
"keyword_file",
type=argparse.FileType('w'),
Copy link
Member

@serhiy-storchaka serhiy-storchaka Mar 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to make the script working on read-only sources (doing nothing if the file is not changed). See for example Tools/scripts/generate_token.py.

Copy link
Member Author

@pablogsal pablogsal Mar 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I am not sure I understand exactly what do you mean :(

Can you elaborate a bit more? Or if you want to do it directly, please, push directly to my branch to update the PR :)

Copy link
Member

@vstinner vstinner Mar 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See "make regen-opcode": Antoine Pitrou wrote $(UPDATE_FILE) which leaves the file unchanged if the content didn't change. One advantage is to not touch the modification time of the file at all. It matters for Makefile to avoid useless recompilation.

Copy link
Member

@serhiy-storchaka serhiy-storchaka Mar 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to use function update_file() from Tools/scripts/generate_token.py.

Copy link
Member Author

@pablogsal pablogsal Mar 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I like update_file() approach, I also like the fact that $(UPDATE_FILE) will check that the files are updated in every PR if someone changes the generator as this has been very valuable for gramminit.c and friends.

Lib/keyword.py Outdated Show resolved Hide resolved
Parser/pgen/keywordgen.py Show resolved Hide resolved
Parser/pgen/keywordgen.py Outdated Show resolved Hide resolved
'while',
'with',
'yield'
]
Copy link
Member

@vstinner vstinner Mar 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@serhiy-storchaka: Sorry, I'm the one who asked @pablogsal to write 'yield']. It doesn't matter, I'm fine with "]" on a separated line as well.

)
parser.add_argument(
"keyword_file",
type=argparse.FileType('w'),
Copy link
Member

@vstinner vstinner Mar 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See "make regen-opcode": Antoine Pitrou wrote $(UPDATE_FILE) which leaves the file unchanged if the content didn't change. One advantage is to not touch the modification time of the file at all. It matters for Makefile to avoid useless recompilation.

@pablogsal pablogsal merged commit 91759d9 into python:master Mar 25, 2019
5 checks passed
@pablogsal pablogsal deleted the bpo36143 branch Mar 25, 2019
ma8ma pushed a commit to ma8ma/cpython that referenced this issue Apr 7, 2019
… using pgen (pythonGH-12456)

Now that the parser generator is written in Python (Parser/pgen) we can make use of it to regenerate the Lib/keyword file that contains the language keywords instead of parsing the autogenerated grammar files. This also allows checking in the CI that the autogenerated files are up to date.
arnolddumas pushed a commit to arnolddumas/cpython that referenced this issue May 3, 2019
… using pgen (pythonGH-12456)

Now that the parser generator is written in Python (Parser/pgen) we can make use of it to regenerate the Lib/keyword file that contains the language keywords instead of parsing the autogenerated grammar files. This also allows checking in the CI that the autogenerated files are up to date.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants