-
Notifications
You must be signed in to change notification settings - Fork 187
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
Implement a Python PEG parser in Rust #566
Merged
Merged
Changes from all commits
Commits
Show all changes
208 commits
Select commit
Hold shift + click to select a range
7d61ed2
[native] Add a rust implementation of whitespace_parser
bgw d24e6dd
[native] Add a native implementation of the tokenizer
bgw f0d3004
Basic FunctionDefinition parsing and codegen
zsol 44e785a
add license headers
zsol f471daf
Convert WhitespaceState to not own absolute indent and move it to parser
zsol e26a9c3
remove python wrappers for now
zsol 68516a6
expressions
zsol 728d856
tracing
zsol 275774d
nicer error messages
zsol 1b2b8ea
bump peg version
zsol b32f953
prettier error messages
zsol 3ed1b40
newline handling
zsol e198d01
blocks
zsol d195023
nicer error messages
zsol f83cf4f
remove unused dep
zsol f5fff7c
only show part of input in error msg
zsol 222e89e
keep newlines when splitting by line
zsol f02c2bf
if statements
zsol 4414c5f
parameters
zsol 0c040dc
add func def fixture
zsol a568392
more whitespace to function def
zsol 07812f1
tweak benchmarks
zsol dff70a6
improve codegen perf
zsol f83355b
use cpu cycles for benchmarks
zsol f1a363e
imports
zsol 0180d33
add test fixture
zsol d4de127
add parentheses to imports
zsol 7ecd5ae
eliminate warnings
zsol 9c06f52
comparisons (note tests are failing because operator parsing is not i…
zsol 016809d
operators
zsol 017b3d5
module footer
zsol 13884fa
sprinkle #[cached]
zsol de0c861
make sure keywords dont match names
zsol e293b3c
prettier roundtrip failures
zsol 0c28628
fix attr_or_name order
zsol c22c825
add comments fixture
zsol e7855ff
add assign target grammar
zsol f02bdee
name rule returns Name
zsol 7d032f9
assignment
zsol cf45134
tuples
zsol cf7c69b
add assignment fixtures
zsol 020eaab
parentheses
zsol eef5556
clippy
zsol 5d8cc59
fix module footer parsing
zsol a873e30
call expressions
zsol 459669e
left-recursive call expressions
zsol 67154ee
attributes!
zsol b71b511
split up into multiple crates
zsol e3de8d3
more comp ops
zsol 5318e19
add comprehension nodes
zsol 9da7587
generator expressions
zsol 9a45768
fix warnings
zsol db94cdc
allow call expressions in target positions
zsol bc148f5
list comprehensions
zsol d76e8d1
set comprehensions
zsol 6360bea
dict comprehensions
zsol a4a66ce
nodes for set/dict/list
zsol 13881a4
list and set literals
zsol bb7a5dd
dict literals - this completes the atom subgrammar
zsol ac98c27
subscript
zsol 1f895f8
add missing workspace config for cargo
zsol 2bc2023
new clippy fixes
zsol e6b612c
tuple shenanigans
zsol 680700b
add evil
zsol f74a4ba
fix left-recursive rules
zsol 78597e1
starred elements on RHS of assign
zsol 1051636
fix utf8 handling during whitespace parsing
zsol ecad6b7
lists in star_atom
zsol e8a0675
more caching
zsol f6336a4
ifexp
zsol f0b0d0f
fix arguments with no trailing comma
zsol c95eecc
lambdas
zsol 44f0f4f
ann assign
zsol 3d26a40
yield
zsol 3decc7d
return statement
zsol 6075910
assert statement
zsol cf8855b
raise statement
zsol 5ed3034
global and nonlocal statements
zsol d5c19c5
for loops
zsol 44a8084
while statement
zsol 72a3e7e
async/await
zsol 2febb8d
handle whitespace after last param
zsol cb4b49c
handle trailing whitespace in lambda params
zsol afe78a7
classes
zsol a04a607
concatenated strings
zsol 0d23fa7
add string fixtures
zsol c47501c
fstrings
zsol ffc69bc
fix duplicate whitespace between trailing comma and rpar in ImportFrom
zsol b6ec2af
fix lookahead in target rules
zsol 8c8c80a
try
zsol f6bf52a
aug assign
zsol 1293ea7
add fixtures for try
zsol e3daedc
add with_parens for all expressions
zsol 36a2b88
more yield weirdness
zsol 61220ab
fixup leading whitespace parsing
zsol 98df73e
fix decorators
zsol 6d2de41
with statements
zsol 0293158
fix indent parsing
zsol 67b470f
dotted annotated assignments
zsol 116cf50
allow files without statements
zsol 3b41fbc
del statements
zsol 0b6a819
allow no params for lambda
zsol ab444e3
add missing fixtures
zsol 735d9c0
exit with 1 for parse errors
zsol 3928e01
fix parsing with missing NL at EOF
zsol 2967095
module header
zsol ae9b436
fix fstring spec parsing
zsol 332cca5
fix ci
zsol 3839b90
add rust CI
zsol adfef46
fix python CI
zsol 2dcbfc2
add rustfmt and run cargo test
zsol ee78151
suppress f401
zsol 25a81ee
tweak pyre exclude
zsol 344fa7d
fix build.yml syntax
zsol 01f11c8
i know how to use #noqa :P
zsol 9fe9225
tweak pyre exclude regex
zsol a9cf52c
fix isort
zsol 0e3ba0c
fix black & isort
zsol 1126908
fix argument parsing for `foo(a=a, *b)`
zsol 52f8d58
display details of tokenizer error
zsol a59fc2c
swallow UTF-8 BOM from input
zsol f1b5121
Track ownership of newlines
zsol 896b74a
fix double whitespace for empty dict/set/list literals
zsol e240f6d
fix extra whitespace for no-arg return
zsol 8175451
semicolons
zsol 6f9aafd
Introduce inflate as a separate step post-parse
zsol 139bf88
merge all crates back into one
zsol 58c6772
remove duplicate structs
zsol 2be0522
add derive macro for Inflate
zsol 2225631
add roundtrip script
zsol 62fff69
move inflate implementations next to nodes
zsol 399af5a
inflate for functiondef and decorator
zsol 14cc28b
Inflate for If and Else
zsol d1a502b
Inflate for CompoundStatements
zsol 7aa7ad1
remove debug statement
zsol 00feef0
remove struct enum variants from SmallStatement
zsol 075d1c6
remove struct enum variants from Expression
zsol 5c7d6c0
use automatic deriving for Codegen and ParenthesizedNode
zsol 41085bd
Inflate for Expressions
zsol cf78ce8
construct lpar outside of class def
zsol 011828f
run rust CI tests in release mode temporarily
zsol db48ff3
fix whitespace around slice parenthesis
zsol 29ddba9
add fixture
zsol 51f190a
share token and whitespace between CST nodes
zsol aecf429
cargo fix
zsol 29b1042
elide redundant lifetimes
zsol b58ce62
remove TODOs related to whitespace adjustments
zsol def50fc
remove janky parse_empty_lines_from_end function
zsol 49249a2
no need to run cargo test with --release anymore
zsol 34f9b5d
clean up unnecessary line ownership tracker code
zsol 78794d4
Token does not need a RefCell wrapper
zsol cec6afe
add tricky comments cases
zsol b303ce1
concatenate all fixtures in benchmark to extend coverage
zsol 894554b
remove grammar dependency on whitespace config
zsol c1d73da
add separate benchmarks for tokenize/parse/inflate/codegen
zsol 0d8062f
expose native API via Python
zsol 350449a
fix invalid test case
zsol bc9c2fd
revert accidental debugging
zsol cd75963
handle optional values with defaults during IntoPy
zsol 5ae79cd
special case IntoPy for DictElement
zsol 7d55318
expose native libs at libcst.native and add env var to turn it on
zsol 06cca35
IndentedBlock.indent should be None when it matches default indent
zsol 09d9543
set extra attributes on Module
zsol 57b3ccf
parse floats and imaginaries
zsol 2e46eab
Add proper expression and statement input rules
zsol 7abcad6
add IntoPy implementation for enums with named fields
zsol 2e27f45
allow missing f-string spec
zsol cc753df
support raw f-strings
zsol c13f318
support more expressions in f-strings
zsol bb65955
allow yield expression in f-strings (?!?!?!)
zsol 3607030
disable tests asserting parse error for certain python versions when …
zsol 97db278
fix IntoPy impl for DictElement
zsol 1bf4536
rename DoubleStarredElement -> StarredDictElement to match pure py im…
zsol 9885372
skip version-specific parse error test
zsol 680ef58
fix FunctionDef tests
zsol 9dd903a
fix list and set tests
zsol 7e96f87
convert UnaryOp variants into named fields
zsol 9690cee
fix parsing of single simplestatements with trailing semicolon
zsol 8cdd027
parse files with trailing comment without newline
zsol ae8cef4
fix IntoPy for ImportFrom without a module attribute
zsol 5f59733
factor out separated meta-rule
zsol 10091a0
fix invalid testcases
zsol b68215a
only set whitespace_after_raise if theres an exception
zsol 7a5da79
whitespace_after_return is never None
zsol 69cf4f7
preserve left paren order in expressions
zsol 465b1c0
trailing comma doesnt own whitespace_after for tuple/list/dict/set
zsol 0ed4685
implement walrus
zsol 2c6b7dc
fix parsing of triple dots in import_from
zsol ed1c373
fix module header processing
zsol 88b7b27
disable singleton newline test in native mode
zsol b93b572
detect default_newline
zsol 9270360
fix simple test case
zsol 9d1a90b
parse_expression should accept tuples
zsol ba5d376
raise ParserSyntaxError in python land
zsol 177b8dd
populate syntax error details where available
zsol 418ff39
add check for pos arg after kw arg in class def
zsol 63c4f71
skip version tests in native mode
zsol a3dfea6
add support for parsing from bytes
zsol 785af81
thread through encoding field to Module
zsol 6557c2c
fix test to coerce call args to tuple
zsol 6925202
update codegen and formatting
zsol 27cd771
run unittests with rust too
zsol e430bbd
use cibw to build wheels
zsol e363058
fix codemod cli test in native/3.6 mode
zsol 30efa4e
fix rust unittests on macos
zsol bfa285f
revert accidental test change
zsol b188f42
address review comments & reorder grammar rules to match CPython
zsol 11cd13b
silence lints
zsol 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 contains 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,11 @@ | ||
[target.x86_64-apple-darwin] | ||
rustflags = [ | ||
"-C", "link-arg=-undefined", | ||
"-C", "link-arg=dynamic_lookup", | ||
] | ||
|
||
[target.aarch64-apple-darwin] | ||
rustflags = [ | ||
"-C", "link-arg=-undefined", | ||
"-C", "link-arg=dynamic_lookup", | ||
] |
This file contains 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 |
---|---|---|
@@ -1,10 +1,14 @@ | ||
root = true | ||
|
||
[*.{py,pyi,toml,md}] | ||
[*.{py,pyi,rs,toml,md}] | ||
charset = "utf-8" | ||
end_of_line = lf | ||
indent_size = 4 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
max_line_length = 88 | ||
|
||
[*.rs] | ||
# https://github.com/rust-dev-tools/fmt-rfcs/blob/master/guide/guide.md | ||
max_line_length = 100 |
This file contains 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 |
---|---|---|
|
@@ -106,6 +106,7 @@ exclude = | |
.pyre, | ||
__pycache__, | ||
.tox, | ||
native, | ||
|
||
max-complexity = 12 | ||
|
This file contains 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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
{ | ||
"exclude": [ | ||
".*\/native\/.*" | ||
], | ||
"source_directories": [ | ||
"." | ||
], | ||
|
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -16,3 +16,4 @@ libcst/_version.py | |
.hypothesis/ | ||
.pyre_configuration | ||
.python-version | ||
target/ |
This file contains 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
This file contains 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 |
---|---|---|
@@ -1 +1,4 @@ | ||
include README.rst LICENSE CODE_OF_CONDUCT.md CONTRIBUTING.md requirements.txt requirements-dev.txt docs/source/*.rst libcst/py.typed | ||
|
||
include native/Cargo.toml | ||
recursive-include native * |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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.
Do you have a plan for making them work? This is an important part of the API.
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.
Yeah it's possible to make it work, but my priority is to get 3.10 working first. The old parser won't be removed until this feature is supported by the new one.