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

Extraneous brackets cause parsing for arithmetic operator error #246

Open
RaoulHC opened this issue Oct 17, 2022 · 5 comments
Open

Extraneous brackets cause parsing for arithmetic operator error #246

RaoulHC opened this issue Oct 17, 2022 · 5 comments

Comments

@RaoulHC
Copy link
Collaborator

RaoulHC commented Oct 17, 2022

The following valid fortran fails to be parsed

      program main
      integer*4 bar
      call foo((bar)*2)
      end program main

Giving:

ProgramFilefortran-src: test.f, 3:22: test.f: parsing failed. 
Last parsed token: TStar (3:21)-(3:21).
CallStack (from HasCallStack):
  error, called at app/Main.hs:108:36 in main:Main

This seems to apply to all arithmetic operators (haven't tried other operators) and only if the brackets are on the left side.

@raehik
Copy link
Collaborator

raehik commented Oct 18, 2022

Argh. This is surely caused by b335ac5 . I imagine it gets to the '(' VARIABLE ')' line in the CALLABLE_EXPRESSION rule:

| '(' VARIABLE ')'
{ let ExpValue _ _ (ValVariable v) = $2
in Argument () (getTransSpan $1 $3) Nothing (ArgExprVar () (getSpan $2) v) }
| EXPRESSION { Argument () (getSpan $1) Nothing (ArgExpr $1) }

But (bar)*2 is an expression, not a variable. So it erroneously parses (bar), then has nowhere to go for the rest of the expression.

@raehik
Copy link
Collaborator

raehik commented Oct 18, 2022

Works fine on commit 58b0de3 (immediately before the arg expr change)

@RaoulHC
Copy link
Collaborator Author

RaoulHC commented Oct 18, 2022

Why exactly is that parsed differently? Is there anything significant about bracketed arguments?

@raehik
Copy link
Collaborator

raehik commented Oct 18, 2022

In #203 we found some surprising cases where bracketing variables in call() argument lists produced different behaviour. We inserted an intermediate data type to enable disambiguating whether an arg was bracketed or not and adding parsing for it, above.

Not too sure how to approach this immediately. Do we have to refactor to handle bracketed expressions in a more complex way? may I ask @dorchard if he has any insights...?

@RaoulHC
Copy link
Collaborator Author

RaoulHC commented Oct 18, 2022

Oh I was unaware of that too, that's a feature that introduces some unfortunate syntactical ambiguity.

Not sure what the best way to handle that is. Obviously foo((var)*2) should still be valid so the parser might have some nastiness to deal with both these cases.

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

No branches or pull requests

2 participants