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

Parse bracketed plain vars in a function call specially e.g. call((a), a) #204

Merged
merged 4 commits into from
Feb 1, 2022

Conversation

raehik
Copy link
Collaborator

@raehik raehik commented Jan 11, 2022

Targets #203 .

Based on the following tweet and referenced material

call double((i), i)

has potentially different meaning to, and should be parsed differently
from

call double(i, i)

As I understand, variables may be used as expressions in two ways:
either directly, as a value access, or indirectly, as an expression to
be evaluated. I add a new Expression constructor for the latter, throw
some hopefully-overriding parser rules in and hope for the best.

https://twitter.com/fortrantip/status/1479071485859962880

Based on the following tweet and referenced material

    call double((i), i)

has potentially different meaning to, and should be parsed differently
from

    call double(i, i)

As I understand, variables may be used as expressions in two ways:
either directly, as a value access, or indirectly, as an expression to
be evaluated. I add a new Expression constructor for the latter, throw
some hopefully-overriding parser rules in and hope for the best.

https://twitter.com/fortrantip/status/1479071485859962880
@raehik
Copy link
Collaborator Author

raehik commented Jan 11, 2022

@dorchard Seems I get away with S/R conflicts by simply adding an "override" case to EXPRESSION parser rules, without refactoring. This change would mean adding another case for all Expression pattern matches, which should almost always be treated the same way as an ExpValue (ValVariable name).

I wonder if I should instead move this to Argument. Make an Either ExpValSpecial Expression type and use it in Argument. Then the changes are limited to the call context only, and don't muddy the AST. Thinking about it I've now become fairly certain that's better, I didn't catch that Argument existed. Will try.

Still messy, but it clarifies that we only expect this to matter inside
function calls, and Argument shows up less than Expression.
@raehik
Copy link
Collaborator Author

raehik commented Jan 13, 2022

It looks like we get away with it in all parsers. I need to add some explicit tests, and think about how we handle the new case of "variable as expression" in analyses. Should be in the dataflow analysis.

@raehik
Copy link
Collaborator Author

raehik commented Jan 20, 2022

Note: This introduces 2 shift/reduce conflicts in each parser (expected).

@raehik raehik changed the title Attempt to parse bracketed plain vars specially Parse bracketed plain vars in a function call specially Feb 1, 2022
@raehik raehik changed the title Parse bracketed plain vars in a function call specially Parse bracketed plain vars in a function call specially e.g. call((a), a) Feb 1, 2022
@raehik
Copy link
Collaborator Author

raehik commented Feb 1, 2022

Merging the parser change & addressing behaviour (special behaviour with aliasing in certain functions) in another PR.

@raehik raehik merged commit a240060 into master Feb 1, 2022
@raehik raehik deleted the bracketed-var-as-expr branch February 1, 2022 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant