JuliaLang / JuliaLang/JuliaSyntax.jl

Syntax error when chaining “colon-like” operators (except `:`)

Open
#578 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
293
Forks
50
PR merge metrics
No merged PRs in 30d

Description

```julia
julia> versioninfo()
Julia Version 1.8.5
Commit 17cfb8e65ea (2023-01-08 06:45 UTC)
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 16 × AMD Ryzen 7 4800H with Radeon Graphics
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-13.0.1 (ORCJIT, znver2)
Threads: 1 on 16 virtual cores
```
In `julia-parser.scm`, there is a precedence class for “colon-like” operators, containing `: .. … ⁝ ⋮ ⋱ ⋰ ⋯`:
https://github.com/JuliaLang/julia/blob/7618e64f9c0ac77ee6e5c6cf3e3251526ccf8ff6/src/julia-parser.scm#L21
However, of these, only `:` seems to allow chaining arbitrarily long infix expressions:
```julia
julia> :(1:2:3:4:5:6)
:(((1:2:3):4:5):6)

```
(Note of course the special behavior of `:` of taking three arguments before nested calls show up.)
For the other ones, only two arguments seem to be allowed:
```julia
julia> :(1..2..3)
ERROR: syntax: missing comma or ) in argument list
Stacktrace:
[1] top-level scope
@ none:1

julia> :(1…2…3)
ERROR: syntax: missing comma or ) in argument list
Stacktrace:
[1] top-level scope
@ none:1

julia> :(1⁝2⁝3)
ERROR: syntax: missing comma or ) in argument list
Stacktrace:
[1] top-level scope
@ none:1

julia> :(1⋮2⋮3)
ERROR: syntax: missing comma or ) in argument list
Stacktrace:
[1] top-level scope
@ none:1

julia> :(1⋱2⋱3)
ERROR: syntax: missing comma or ) in argument list
Stacktrace:
[1] top-level scope
@ none:1

julia> :(1⋰2⋰3)
ERROR: syntax: missing comma or ) in argument list
Stacktrace:
[1] top-level scope
@ none:1

julia> :(1⋯2⋯3)
ERROR: syntax: missing comma or ) in argument list
Stacktrace:
[1] top-level scope
@ none:1

```

[The manual describes these operators (explicitly including `..`) as left-associative](https://docs.julialang.org/en/v1/manual/mathematical-operations/#Operator-Precedence-and-Associativity), so I would expect that these should work. It also works for all the operators from the other classes:
```julia
julia> :(1→2→3)
:(1 → (2 → 3))

julia> :(1||2||3)
:(1 || (2 || 3))

julia> :(1&&2&&3)
:(1 && (2 && 3))

julia> :(1|>2|>3)
:((1 |> 2) |> 3)

julia> :(1+2+3)
:(1 + 2 + 3)

julia> :(1¦2¦3)
:((1 ¦ 2) ¦ 3)

julia> :(1*2*3)
:(1 * 2 * 3)

julia> :(1%2%3)
:((1 % 2) % 3)

julia> :(1//2//3)
:((1 // 2) // 3)

julia> :(1>>2>>3)
:((1 >> 2) >> 3)

julia> :(1^2^3)
:(1 ^ (2 ^ 3))

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.