Skip to content

Refactor scripts in Tools/peg_generator/scripts#20401

Merged
miss-islington merged 8 commits into
python:masterfrom
lysnikolaou:refactor-scripts
Jun 6, 2020
Merged

Refactor scripts in Tools/peg_generator/scripts#20401
miss-islington merged 8 commits into
python:masterfrom
lysnikolaou:refactor-scripts

Conversation

@lysnikolaou

@lysnikolaou lysnikolaou commented May 25, 2020

Copy link
Copy Markdown
Member

Automerge-Triggered-By: @gvanrossum

@lysnikolaou

Copy link
Copy Markdown
Member Author

Is it okay to not open an issue for this?

@gvanrossum

Copy link
Copy Markdown
Member

Is it okay to not open an issue for this?

Why not use the same bpo issue we've been using for almost everything? Then again, labeling as "skip issue" sounds fine too.

@lysnikolaou

lysnikolaou commented May 25, 2020

Copy link
Copy Markdown
Member Author

Why not use the same bpo issue we've been using for almost everything?

That's a valid question. I've been trying to refrain from doing so generally. I'm thinking about closing that issue as soon as #20106 is merged.

Then again, labeling as "skip issue" sounds fine too.

I'm going to do that then.

Comment thread Tools/peg_generator/scripts/test_pypi_packages.py
@pablogsal

Copy link
Copy Markdown
Member

Btw, I noticed that the scripts/grammar_grapher.py is not taking into account that the start node is not called start anymore.

@pablogsal

Copy link
Copy Markdown
Member

Also, we could remove the need to parse the grammar to scripts/show_parse.py as we are going to use it mainly to compare the two parsers, not to compare a specific new grammar file.

Comment thread Tools/peg_generator/scripts/benchmark.py
Comment thread Tools/peg_generator/scripts/test_parse_directory.py Outdated
Comment thread Tools/peg_generator/scripts/test_parse_directory.py Outdated
Comment thread Tools/peg_generator/scripts/benchmark.py Outdated
lysnikolaou and others added 2 commits May 26, 2020 23:01
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Comment thread Tools/peg_generator/scripts/grammar_grapher.py Outdated
@lysnikolaou lysnikolaou changed the title Refactor test_parse_directory in Tools/peg_generator/scripts Refactor scripts in Tools/peg_generator/scripts May 26, 2020
Comment thread Tools/peg_generator/scripts/test_parse_directory.py Outdated

@pablogsal pablogsal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
@lysnikolaou

Copy link
Copy Markdown
Member Author

Friendly ping.

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for taking so long! This is a great improvement to the readability of this code. I have a few comments.

if new_parser:
tree = _peg_parser.parse_string(program)

if args.diff:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm actually curious if we shouldn't swap a and b here. Wouldn't it make more sense if a was the old parser's tree and b was the new parser's tree? That's how we usually view diffs -- a (or "left") is the old code, b ("right") is the new code.

print("# Trees are the same")
else:
print(f"# Parsed using {args.grammar_file}")
print(f"# Parsed using the new parser")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Doesn't need to be an f-string any more.

return 1
def parse_file(source: str, file: str, mode: int, oldparser: bool) -> Tuple[Any, float]:
t0 = time.time()
if mode == 2:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if we shouldn't introduce an enum or at least named constants for the mode values. I am already forgetting what 2 means here.

else:
print(
"A grammar file or a tokens file was not provided - attempting to use existing parser from stdlib...\n"
result = _peg_parser.parse_string(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In the pegenvm branch I introduced a new flag to parse_string, ast, which if set to False doesn't produce a parse tree. This would be useful for mode=0. It also makes test parses of xxl.py much quicker (converting the tree to Python objects takes more time than the actual parsing).

@lysnikolaou

Copy link
Copy Markdown
Member Author

I added support for mode=0 in parse_directory back by implementing an ast keyword argument, as @gvanrossum suggested.

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! Go for it.

@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @lysnikolaou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒⛏🤖

@bedevere-bot

Copy link
Copy Markdown

GH-20671 is a backport of this pull request to the 3.9 branch.

miss-islington added a commit that referenced this pull request Jun 6, 2020
(cherry picked from commit ba6fd87)

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
@lysnikolaou lysnikolaou deleted the refactor-scripts branch June 6, 2020 07:53
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.

6 participants