JuliaLang / JuliaLang/JuliaSyntax.jl

`begin .. end` blocks in `ref` expression is unsupported

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

Description

Defining arrays with a `begin end` block is valid:
```julia
julia> parsestmt(SyntaxNode, "[begin 1 end]")
SyntaxNode:
[vect]
[block]
1 :: Integer
```

Defining arrays with a type in front is valid:
```julia
julia> parsestmt(SyntaxNode, "Int[1]")
SyntaxNode:
[ref]
Int :: Identifier
1 :: Integer
```

Yet we can't use both:
```
julia> parsestmt(SyntaxNode, "Int[begin 1 end]")
ERROR: ParseError:
# Error @ line 1:12
Int[begin 1 end]
# └ ── Expected `]`
Stacktrace:
[1] _parse(rule::Symbol, need_eof::Bool, ::Type{…}, text::String, index::Int64; version::VersionNumber, ignore_trivia::Bool, filename::Nothing, first_line::Int64, ignore_errors::Bool, ignore_warnings::Bool, kws::@Kwargs{})
@ JuliaSyntax ~/.julia/dev/JuliaSyntax/src/parser_api.jl:98
[2] _parse (repeats 2 times)
@ ~/.julia/dev/JuliaSyntax/src/parser_api.jl:82 [inlined]
[3] parsestmt(::Type{SyntaxNode}, text::String)
@ JuliaSyntax ~/.julia/dev/JuliaSyntax/src/parser_api.jl:145
[4] top-level scope
@ REPL[5]:1
```

I expected something like this:
```julia
julia> parsestmt(SyntaxNode, "Int[begin 1 end]")
SyntaxNode:
[ref]
Int :: Identifier
[block]
1 :: Integer
```

Note that this AST is valid:
```julia
julia> eval(Expr(:ref, :Int, Expr(:block, LineNumberNode(1, :a), 1)))
1-element Vector{Int64}:
1
```

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.