Skip to content

begin .. end blocks in ref expression is unsupported #539

@Keluaa

Description

@Keluaa

Defining arrays with a begin end block is valid:

julia> parsestmt(SyntaxNode, "[begin 1 end]")
SyntaxNode:
[vect]
  [block]
    1                                    :: Integer

Defining arrays with a type in front is valid:

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> parsestmt(SyntaxNode, "Int[begin 1 end]")
SyntaxNode:
[ref]
  Int                                    :: Identifier
  [block]
    1                                    :: Integer

Note that this AST is valid:

julia> eval(Expr(:ref, :Int, Expr(:block, LineNumberNode(1, :a), 1)))
1-element Vector{Int64}:
 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions