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

Do you have plans to support python 3.10 (for example, assignment expressions)? #2462

Open
dours opened this issue Dec 30, 2021 · 7 comments
Labels

Comments

@dours
Copy link

dours commented Dec 30, 2021

assignment_expression ::=  [identifier ":="] expression

An assignment expression (sometimes also called a “named expression” or “walrus”) assigns an expression to an identifier, while also returning the value of the expression.

One common use case is when handling matched regular expressions:

if matching := pattern.search(data):
    do_something(matching)

Or, when processing a file stream in chunks:

while chunk := file.read(9000):
    process(chunk)

From https://docs.python.org/3/reference/expressions.html#assignment-expressions

@RobEin
Copy link
Contributor

RobEin commented Dec 30, 2021

Yes, I have an implementation for Python 3.10 in ANTLR4.
I'll share in a few days.

@RobEin
Copy link
Contributor

RobEin commented Jan 10, 2022

uploaded:
https://github.com/RobEin/ANTLR4-Python-grammar-by-PEG

I'm not uploading it to the ANTLR4 repository yet because it has yet to be tested.
I have passed all the old tests, but I don't have many files about the latest features yet.

@dours
Copy link
Author

dours commented Jan 17, 2022

@RobEin Thank you very much! I'll try to use it soon.

@RobEin
Copy link
Contributor

RobEin commented Jan 19, 2022

I still have to work on it.
The parser is extremely slow but looks like it works.
The grammar was tested with the latest Python standard library.
I found a mistake.

@RobEin
Copy link
Contributor

RobEin commented Jan 27, 2022

I have also uploaded another version (3.8.12) which can also handle the named expressions.
It's fast enough, but it's still being tested.
I hope it helps.

@hasii2011
Copy link

hasii2011 commented Oct 21, 2022

The above grammars generate Java code is that true? Do you know of what that generates Python code? Actually, I tried to generate python code with these. I got a serialization error

@RobEin
Copy link
Contributor

RobEin commented Jul 31, 2023

A Python 3.11.4 parser for ANTLR4 is ready.
It looks like it's working fine, although it's still very slow.
If you are interested, please test it.
https://github.com/RobEin/ANTLR4-Python-grammar-by-PEG

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants