add comment support to rustpython parser #20
Labels
No Milestone
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: M-Labs/nac3#20
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The new branch with_nac3comment contains modifications to use the moded python parser to support nac3comment in ast.
The current approach is to add two more string fields to the
ast::StmtKind::AnnAssign
andast::StmtKind::For
which contains the nac3 comment. Not much is needed to modify the current nac3 code.I do not seem to have the permission to push to the RustPython repository in m-labs, so currently I just temporarily forked a copy of rustpython and use it in the branch with_nac3comment, will modify later.
Just ask - fixed.
Can we avoid NAC3 references in the parser? Hopefully this comment support would be generic enough and perhaps even merged upstream.
The updated with_nac3comment branch contains updates related to previous discussion, including:
ast::StmtKind
can have pseudo-comment, on top of them(correctly indented) or on the right hand side of the first line of them. And multiple pseduo-comments are supported:will give this ast:
if 1: a = a + 1
) and semicolons (a + 1; print(a)
) supported with pseudocomment;
is fixednow the first one is not allowed
what do you mean by
?
sorry, please just ignore the content of the previous comment. Let me explain again:
I mean for this piece of code:
it should not parse, but the previous version will accept this and regard the first comment as written for the
a + 1
, and the second comment as written forc = b
which is equivalent to:And in the latest version, this is fixed:
this code will not parse
I don't think it should parse due to indentation error? You mean
should not parse right? But why can't we associate the first comment to the if statement and the second comment to the
b = 1
statement?Thanks for the suggestion, I have added this support in the latest version
now
would parse to: