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
Group line and column metadata needs special handling #107
Comments
Hm, so I guess this is another reason why I think we may have to come up with a way to gather line/column information out of band, rather than passing it to the node constructors using (PS. I reformatted your code so I could read it. The easiest way to do it that I've found is to write it to a file and run black over it... I'm weaponizing this as we speak. :-) |
Having refactored all of the PS Very good idea! I was trying to do it using |
Ah, so it's because the group disappears. Can we introduce a helper object? Or does it have to be an existing I propose not to worry about this -- I'm not sure it's worth reproducing this particular behavior. OTOH maybe the solution really is to take the line/col info out of band. PS. #108 |
What exactly do you mean with out of band? |
We could add some code to the generated code that extracts the start line/col from the upcoming token at the top of a rule implementation function, and extracts the end line/col from the last token just before calling the action. Something like this:
before diving into the first alternative (but after checking the memo), and then in each rule, just before the action is executed:
insert this:
And then, finally, change the
We can then drop a whole bunch of infrastructure around |
That seems like a nice solution. It also resembles what In #109, I'm just ignoring this problem, until we have a final decision on how to proceed with this one. |
I recommend spending a few days trying to implement this idea and seeing if
there's anything I've missed.
|
OK! I'll start with it tonight. |
After spending some time on this, the only problem I'm having now has to do with the |
That indeed works and the whole test suite now passes. The problem is as we refactor more of |
Hm, this seems due to some idiosyncrasy in ast.c (ast_for_if_stmt()). I wonder if we could submit a PR to ast.c that fixes the column offset there? It could just use CHILD(n, off - 1) in the asdl_seq_SET() call. |
I can do that, should I open an issue on bpo? |
Sure. Link it here. |
Opened an issue at https://bugs.python.org/issue39031. |
Also opened a PR on python/cpython#17582. |
Two new observations: First of all, after the newest refactorings we've got two new problems.
Second of all, there is a REALLY SIGNIFICANT runtime increase. Running |
So to be clear, the runtime increase is due to #121?
|
I'm not 100% sure on that. The runtime increase is only reproducible on that branch on my local environment, but Travis thinks otherwise, as it completed in a little more that 6 seconds in #121. I need to investigate further. |
Closing due to #121. |
When writing the action for the
group
rule, I found out that parsing something like(yield a)
returns the following AST object:That means that the
Expr
node's start column offset is 0, although theyield
node's is 1. The correct action forgroup
is thus:but the surrounding
Expr
node needs to have a different column offset and I can't seem to come up with a way of handling this, so any ideas are welcome!The text was updated successfully, but these errors were encountered: