-
Notifications
You must be signed in to change notification settings - Fork 55
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
Shift right mistakenly parsed as type argument list #176
Comments
I have tried to replace An example of code that parses now, but that I could not get to parse with my changes were:
Here it tries to parse |
I'm struggling to understand what exactly is happening here. I understand that with the current grammar, expression Doing a Both versions have
As far as I see the two stack versions are equally good. (I tried parsing the same input with a locally built tree-sitter, where the Putting aside the above that I don't understand why certain things are happening in tree-sitter. How would one solve this conflicting parsing issue? I see the following options:
What are other options? None of the above seem viable/straightforward. |
I wish I had more information or an answer for you but my experience in dealing with these awkward conflicts are also limited and there doesn't seem to be much else in the way of documentation or support available (Max has been quiet for quite some time). I'd be okay going with either solution for a while to see how it pans out. We could always switch later if we needed to - maybe leave some comments as to why things are the way they are in the meantime. |
I believe right now, there are two valid parses, and they both have the same dynamic precedence (zero, the default), so Tree-sitter is having to just choose one semi-arbitrarily. I agree with @initram - it seems like the grammar should be restructured so that |
Looking at this again, it is not so straight forward. It seems that in some rare cases
That is parsed as an invocation expression with a generic name as the argument expression by Roslyn. It is really hard to find a good rule or precedence that solves all these issues with when it should be parsed as a generic name or not. One idea that I have is that generic names maybe should only be allowed as the top level expression, and not as part of a composite expression, but that may easier said than done. We should add a bunch more test cases to cover some of all these use-cases of generic name and less-than and greather-than symbols. That way it is easier to experiment with new approaches and not have to rely on whether the "example repos" parse as well. |
I see. One way to get this more correct might be to put a negative dynamic precedence on
|
@initram I experimented with your approach a bit further. So changed
This got me quite far. (There are 177 failing files in Roslyn, which is in line with my earlier checks, so there might not be any new failures.) The above list is somewhat arbitrary, I think all expression types that are in the Primary row of the precedence table would be needed. Let me know if you think this is a wrong assumption. At the same time
Regarding
Do you know if this is specific to See the draft PR #285. |
@tamasvajk It seems promising. But why did you need to limit the expressions available for _invocation_function, why could it not just be (generic_name or _expression)? If it is needed to limit the expressions that are available to use as _invocation_function, then we need to make sure that there is no legal expression from _expression that is missing in _invocation_function. At least you are missing default expression, as this is valid C#: The only place that I can think of where generic_name is a legal expression is in nameof(). I could be wrong, and there are other cases where Roslyn accepts generic name as expressions for parsing purposes, but the code cannot compile for semantic reasons. If you could add a few more tests to cover some of the invocation expressions that are not covered currently, and at the very least the shift right expression from this issue. That would help making sure that we do not regress in parsing in the future. |
My initial goal was to limit it as much as possible in the hope that this way there wouldn't be too many new conflicts. The list grew a bit from what I initially added. So for grammar maintainability, your suggestion might be a lot better. I gave it a quick try
which resulted in a couple more conflicts:
and even the tests don't pass this way. For example
which I find rather odd. I don't understand why precedences are not working as I would expect. But this also suggests me that At the same time, |
I realized that this is not specific to
I'm closing the draft PR #285. |
Actual:
Interpreted as
A<X> > B
Expected:
Interpreted as
A < (X >> B)
The text was updated successfully, but these errors were encountered: