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

infixr and infixl not respected #77

Closed
Munksgaard opened this issue Apr 13, 2022 · 4 comments
Closed

infixr and infixl not respected #77

Munksgaard opened this issue Apr 13, 2022 · 4 comments

Comments

@Munksgaard
Copy link

Munksgaard commented Apr 13, 2022

Using infixr and infixl for a given operator should result in different parse-trees.

For example, parsing infixl 7 +>; a +> c +> d and infixr 7 +>; a +> c +> d results in the same parse tree, but really we would expect the +> operator to be right-associative in the second example.

For completeness, I've included the output of tree-sitter parse with those inputs below.

Now, I don't even know if it is possible to amend this issue while using tree-sitter, or if you want to, so feel free to close this issue at your convenience.

$ tree-sitter parse <(echo 'infixl 7 +>; a +> c +> d')
(haskell [0, 0] - [1, 0]
  (fixity [0, 0] - [0, 11]
    (integer [0, 7] - [0, 8])
    (varop [0, 9] - [0, 11]
      (operator [0, 9] - [0, 11])))
  (top_splice [0, 13] - [0, 24]
    (exp_infix [0, 13] - [0, 24]
      (exp_infix [0, 13] - [0, 19]
        (exp_name [0, 13] - [0, 14]
          (variable [0, 13] - [0, 14]))
        (operator [0, 15] - [0, 17])
        (exp_name [0, 18] - [0, 19]
          (variable [0, 18] - [0, 19])))
      (operator [0, 20] - [0, 22])
      (exp_name [0, 23] - [0, 24]
        (variable [0, 23] - [0, 24])))))

$ tree-sitter parse <(echo 'infixr 7 +>; a +> c +> d')
(haskell [0, 0] - [1, 0]
  (fixity [0, 0] - [0, 11]
    (integer [0, 7] - [0, 8])
    (varop [0, 9] - [0, 11]
      (operator [0, 9] - [0, 11])))
  (top_splice [0, 13] - [0, 24]
    (exp_infix [0, 13] - [0, 24]
      (exp_infix [0, 13] - [0, 19]
        (exp_name [0, 13] - [0, 14]
          (variable [0, 13] - [0, 14]))
        (operator [0, 15] - [0, 17])
        (exp_name [0, 18] - [0, 19]
          (variable [0, 18] - [0, 19])))
      (operator [0, 20] - [0, 22])
      (exp_name [0, 23] - [0, 24]
        (variable [0, 23] - [0, 24])))))
@tek
Copy link
Contributor

tek commented Apr 13, 2022

I think it isn't possible at all, but even if it were, it would require substantial changes and work only for the edge case of the fixity being defined in the same module as its usage, if that usage is after the definition. so quite unlikely to be feasible 🙂

@Munksgaard
Copy link
Author

Munksgaard commented Apr 13, 2022 via email

@tek
Copy link
Contributor

tek commented Apr 13, 2022

heh. a similar problem occurs with #if/#else cpp macros – we can't easily pass around state except to descendants. fixity would be a little simpler, but still very limited.

@Munksgaard
Copy link
Author

All good. I'll close this issue as "wontfix".

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