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

Grammar parses != in right-associative way #373

Closed
f-f opened this issue Feb 16, 2019 · 4 comments · Fixed by dhall-lang/dhall-haskell#825
Closed

Grammar parses != in right-associative way #373

f-f opened this issue Feb 16, 2019 · 4 comments · Fixed by dhall-lang/dhall-haskell#825

Comments

@f-f
Copy link
Member

f-f commented Feb 16, 2019

According to the standard all operators are left-associative

For example, the following expression:

True == False != False

should parse in this way:

(True == False) != False

-- Or in CBOR encoding:
-- [3 3 [3 2 true false] false]

However, the only parse the grammar allows in this case is the following:

True == (False != False)

-- Or in CBOR encoding:
-- [3 2 true [3 3 false false]]

The issue should be here, as an "equal expression" can contain "not-equal-expression"s, but not viceversa 🤔

@f-f f-f changed the title Grammar parses bool operators in right-associative way Grammar parses != in right-associative way Feb 16, 2019
@Gabriella439
Copy link
Contributor

My understanding is that associativity only specifies how multiple occurrences of the same operator are parenthesized. If you combine different operators then operator precedence governs how they are parenthesized and that takes precedence (pun intended) over associativity.

@f-f
Copy link
Member Author

f-f commented Feb 22, 2019

Oh right, makes sense. Then I guess the grammar is also the proper reference for operator precedence (as it limits the possible parses one can get, as in this case)

But then it looks like the parsing by the Haskell implementation not using the right operator precedence: in the parser/success/operators test the True == False != False is parsed as (True == False) != False, which is not allowed by the grammar

@Gabriella439
Copy link
Contributor

Oh, that's a bug in the Haskell implementation. It has the precedence of the != and == operators backwards:

https://github.com/dhall-lang/dhall-haskell/blob/8663bfe2967fbad07590a17e90abe60c4ab0c170/dhall/src/Dhall/Parser/Expression.hs#L175-L181

I can fix that

Gabriella439 added a commit to dhall-lang/dhall-haskell that referenced this issue Feb 22, 2019
Fixes dhall-lang/dhall-lang#373

The standard specifies that `!=` should have higher precedence than `==`,
which this change fixes.
@Gabriella439
Copy link
Contributor

Fix is up here: dhall-lang/dhall-haskell#825

Gabriella439 added a commit to dhall-lang/dhall-haskell that referenced this issue Feb 23, 2019
Fixes dhall-lang/dhall-lang#373

The standard specifies that `!=` should have higher precedence than `==`,
which this change fixes.
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.

2 participants