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

Operator precedence is not taken into account when parsing expressions #41

Closed
jhrcek opened this issue Apr 24, 2020 · 3 comments
Closed

Comments

@jhrcek
Copy link

jhrcek commented Apr 24, 2020

It seems to me, that operator precedence is not take into account when parsing expressions.

For example the following two expressions

1 ^ 2 * 3 + 4
1 + 2 * 3 ^ 4

both produce the same shape of the expression tree, the first one being obviously incorrect

^
│
├─ 1
│
└─ *
   │
   ├─ 2
   │
   └─ +
      │
      ├─ 3
      │
      └─ 4

+
│
├─ 1
│
└─ *
   │
   ├─ 2
   │
   └─ ^
      │
      ├─ 3
      │
      └─ 4

I created SSCCE which demonstrated this issue: https://github.com/jhrcek/elm-syntax-sscce

Wider context: this library is used by elm-review, which -among other things - allows writing custom linting rules for elm source code. Unfortunately since the expressions are not parsed correctly by this library, this leads to all sorts of false positives as in the following example

Screenshot from 2020-04-24 09-34-06

Because elm-syntax parses this as (f <| x) || y it gives this false positive warning, which shouldn't be there, because || has higher precedence than <|, so the correct parsing should look like f <| (x || y).

@MartinSStewart
Copy link
Collaborator

@stil4m I think this issue can be closed now.

@stil4m
Copy link
Owner

stil4m commented Jun 17, 2020

@jhrcek Thank you for your report. That was clearly a bug.
The fix @MartinSStewart made a functional fix for this which is already released in 7.1.2.

I've just prepared a pull request (#66) that will ship with 8.0.0, which will ensure that most programs have proper parsing of operators (and will nog require parsing of dependencies).

@stil4m stil4m closed this as completed Jun 17, 2020
@jhrcek
Copy link
Author

jhrcek commented Jun 18, 2020

Thank you both @MartinSStewart and @stil4m , I appreciate your work ❤️

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 a pull request may close this issue.

3 participants