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

Support simple flag in annotate assignment #127

Open
Glyphack opened this issue Apr 29, 2023 · 2 comments
Open

Support simple flag in annotate assignment #127

Glyphack opened this issue Apr 29, 2023 · 2 comments
Labels
good first issue Good for newcomers parser

Comments

@Glyphack
Copy link
Owner

Annotated assignment statements have a flag called simple. This is hardcoded but should be assigned based on the following spec:
https://docs.python.org/3/library/ast.html#ast.AnnAssign

@Glyphack Glyphack added parser good first issue Good for newcomers labels Apr 29, 2023
@Glyphack
Copy link
Owner Author

Flag is set on this field:

pub simple: bool,

Here we need to match lhs agains Name nodes and check if it is inside "()" or not:

target: lhs,

@dwoznicki
Copy link
Collaborator

dwoznicki commented Jun 25, 2024

Thanks. I went down a rabbit hole yesterday trying to figure out where lhs gets initialized as an Expression::Name. I figure that's probably not that important, but now I'm curious as I can't seem to follow the stack trace. It must go something like:

parse_assignment_or_expression_statement -> parse_expressions -> parse_expression -> parse_conditional_expression -> ?

EDIT: Nevermind. I printed a backtrace so now I see how this works. The parser "cascades" down through various checks, eventually landing on parse_identifier.

I suppose it might actually be important if we don't track tokens by offset, or some other way to look up a token at a particular index. I'm assuming we don't want to add a surrounded_by_parens or similar field to the Name struct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers parser
Projects
None yet
Development

No branches or pull requests

2 participants