Fixing ambiguities between template methods and comparisons #267
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR aims at fixing parsing of ambiguous expressions as mentioned in issue #231.
Consider for example the following code:
This is currently recognized as an assignment ( of template method x.foo<...> to value 1) instead of the logical disjunction of two comparisons.
My understanding is that, for some reason, the prec.right in front of the field_expression's rule in the grammar prevents the parser from forking when "x.foo" is on the stack and forces the parsing of a template method instead.
I thus removed the prec.right annotation and added a conflict between field_expression, template_method and template_type.
In addition, I added a prec.dynamic annotation in front of field_identifier to avoid the reduction to a template method when reducing to a field_identifier is possible.
Note that there exists situation in which both interpretations could be valid, and there is no way to decide which one is correct from the information available to the parser.
An example of this situation is the following:
In this specific case, I think having a binary expression as a template parameter is very unusual and so the dynamic precedence is fine. However, I might have overlook other situations where the template_method interpretation is the correct one.
The same ambiguity appears when the field_identifier is qualified, I thus apply the same modifications to the qualified_field_identifier rule, i.e. removing the prec.right, adding a conflict and forcing the interpretation to a field_identifier using dynamic precedence in case of ambiguity).
Some things to consider before accepting this PR: