JuliaLang / JuliaLang/JuliaSyntax.jl
Weird precedence of unary operators, `where` and syntactic unaries
- Dominant language
- Julia
- Stars
- 293
- Forks
- 50
- PR merge metrics
- No merged PRs in 30d
Description
The precedence of type operators `<:` is meant to be lower than `where` as handled with a special rule `parse_unary_subtype` (see https://github.com/JuliaLang/julia/pull/21567).
But the way this is implemented in the reference parser (and copied here) the precedence doesn't work when chained with normal unary ops. This happens because `parse_unary` is still involved in parsing chained unary type operators.
```
julia> parsestmt(SyntaxNode, "<: A where B")
line:col│ tree │ file_name
1:1 │[<:-pre]
1:3 │ [where]
1:4 │ A
1:12 │ B
```
```
julia> parsestmt(SyntaxNode, "+ <: A where B")
line:col│ tree │ file_name
1:1 │[where]
1:1 │ [call-pre]
1:1 │ +
1:2 │ [<:-pre]
1:6 │ A
1:14 │ B
```
Fixing this isn't super simple - if we call `parse_unary_subtype` from within `parse_unary`, we'll break the precedence of juxtaposition which is interposed between these two. For example, we must have `"√2i"` parse as `(juxtapose (call-pre √ 2) i)`.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.