forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Remove all unnecessary code from Tools/peg_generator; only keep the generator itself #23
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
374198f
Remove C code from Tools/peg_generator/peg_parser and rely on
lysnikolaou f61908f
Fix bugs in test_peg_parser.py
lysnikolaou d2cfb53
Move all tests to Lib/test/test_peg_generator
lysnikolaou f9da64f
Disable pegen tests on Github Actions
lysnikolaou 2cc2151
Fix bugs in some tests
lysnikolaou 7cfd0e0
Fix tests by copy-pasting ast.dump into test_peg_generator.py and rem…
lysnikolaou 2f1cc5d
Create test_peg_generator directory and move tests to different files
lysnikolaou 7c014b1
Add TODO
lysnikolaou cb3ff5a
Top-level comment
lysnikolaou 3305cf9
Rename peg_parser directory to peg_extension
lysnikolaou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import os | ||
|
|
||
| from test.support import load_package_tests | ||
|
|
||
| # Load all tests in package | ||
| def load_tests(*args): | ||
| return load_package_tests(os.path.dirname(__file__), *args) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import unittest | ||
| from . import load_tests | ||
|
|
||
| unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| """ | ||
| Copy-parse of ast.dump, removing the `isinstance` checks. This is needed, | ||
| because testing pegen requires generating a C extension module, which contains | ||
| a copy of the symbols defined in Python-ast.c. Thus, the isinstance check would | ||
| always fail. We rely on string comparison of the base classes instead. | ||
| TODO: Remove the above-described hack. | ||
| """ | ||
|
|
||
| def ast_dump(node, annotate_fields=True, include_attributes=False, *, indent=None): | ||
| def _format(node, level=0): | ||
| if indent is not None: | ||
| level += 1 | ||
| prefix = '\n' + indent * level | ||
| sep = ',\n' + indent * level | ||
| else: | ||
| prefix = '' | ||
| sep = ', ' | ||
| if any(cls.__name__ == 'AST' for cls in node.__class__.__mro__): | ||
| cls = type(node) | ||
| args = [] | ||
| allsimple = True | ||
| keywords = annotate_fields | ||
| for name in node._fields: | ||
| try: | ||
| value = getattr(node, name) | ||
| except AttributeError: | ||
| keywords = True | ||
| continue | ||
| if value is None and getattr(cls, name, ...) is None: | ||
| keywords = True | ||
| continue | ||
| value, simple = _format(value, level) | ||
| allsimple = allsimple and simple | ||
| if keywords: | ||
| args.append('%s=%s' % (name, value)) | ||
| else: | ||
| args.append(value) | ||
| if include_attributes and node._attributes: | ||
| for name in node._attributes: | ||
| try: | ||
| value = getattr(node, name) | ||
| except AttributeError: | ||
| continue | ||
| if value is None and getattr(cls, name, ...) is None: | ||
| continue | ||
| value, simple = _format(value, level) | ||
| allsimple = allsimple and simple | ||
| args.append('%s=%s' % (name, value)) | ||
| if allsimple and len(args) <= 3: | ||
| return '%s(%s)' % (node.__class__.__name__, ', '.join(args)), not args | ||
| return '%s(%s%s)' % (node.__class__.__name__, prefix, sep.join(args)), False | ||
| elif isinstance(node, list): | ||
| if not node: | ||
| return '[]', True | ||
| return '[%s%s]' % (prefix, sep.join(_format(x, level)[0] for x in node)), False | ||
| return repr(node), True | ||
|
|
||
| if all(cls.__name__ != 'AST' for cls in node.__class__.__mro__): | ||
| raise TypeError('expected AST, got %r' % node.__class__.__name__) | ||
| if indent is not None and not isinstance(indent, str): | ||
| indent = ' ' * indent | ||
| return _format(node)[0] | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, if it's just this file that's duplicated, I don't mind. Sorry for making a fuss!