diff --git a/src/expr.jl b/src/expr.jl index 5c3c9fe9..83b7fa36 100644 --- a/src/expr.jl +++ b/src/expr.jl @@ -132,7 +132,7 @@ function _to_expr(node::SyntaxNode; iteration_spec=false, need_linenodes=true, ((headsym == :call || headsym == :dotcall) && is_prefix_call(node)) || headsym == :ref eq_to_kw_all = headsym == :parameters && !map_kw_in_params - in_vbr = headsym == :vect || headsym == :braces || headsym == :ref + in_vcbr = headsym == :vect || headsym == :curly || headsym == :braces || headsym == :ref if insert_linenums && isempty(node_args) push!(args, source_location(LineNumberNode, node.source, node.position)) else @@ -144,7 +144,7 @@ function _to_expr(node::SyntaxNode; iteration_spec=false, need_linenodes=true, eq_to_kw = eq_to_kw_in_call && i > 1 || eq_to_kw_all args[insert_linenums ? 2*i : i] = _to_expr(n, eq_to_kw=eq_to_kw, - map_kw_in_params=in_vbr) + map_kw_in_params=in_vcbr) end end end @@ -157,7 +157,7 @@ function _to_expr(node::SyntaxNode; iteration_spec=false, need_linenodes=true, end reorder_parameters!(args, 2) insert!(args, 2, loc) - elseif headsym in (:dotcall, :call, :ref) + elseif headsym in (:dotcall, :call) # Julia's standard `Expr` ASTs have children stored in a canonical # order which is often not always source order. We permute the children # here as necessary to get the canonical order. @@ -180,15 +180,18 @@ function _to_expr(node::SyntaxNode; iteration_spec=false, need_linenodes=true, args[1] = Symbol(".", args[1]) end end + elseif headsym in (:ref, :curly) + # Move parameters blocks to args[2] + reorder_parameters!(args, 2) + elseif headsym in (:tuple, :vect, :braces) + # Move parameters blocks to args[1] + reorder_parameters!(args, 1) elseif headsym === :comparison for i in 1:length(args) if Meta.isexpr(args[i], :., 1) args[i] = Symbol(".",args[i].args[1]) end end - elseif headsym in (:tuple, :vect, :braces) - # Move parameters blocks to args[1] - reorder_parameters!(args, 1) elseif headsym === :where reorder_parameters!(args, 2) elseif headsym in (:try, :try_finally_catch) diff --git a/test/expr.jl b/test/expr.jl index 656f645a..3a2f46f1 100644 --- a/test/expr.jl +++ b/test/expr.jl @@ -208,14 +208,22 @@ # ref @test parse(Expr, "x[i=j]") == Expr(:ref, :x, Expr(:kw, :i, :j)) + @test parse(Expr, "(i=j)[x]") == + Expr(:ref, Expr(:(=), :i, :j), :x) @test parse(Expr, "x[a, b; i=j]") == Expr(:ref, :x, Expr(:parameters, Expr(:(=), :i, :j)), :a, :b) + # curly + @test parse(Expr, "(i=j){x}") == + Expr(:curly, Expr(:(=), :i, :j), :x) + @test parse(Expr, "x{a, b; i=j}") == + Expr(:curly, :x, Expr(:parameters, Expr(:(=), :i, :j)), :a, :b) - # vect/braces + # vect @test parse(Expr, "[a=1,; b=2]") == Expr(:vect, Expr(:parameters, Expr(:(=), :b, 2)), Expr(:(=), :a, 1)) + # braces @test parse(Expr, "{a=1,; b=2}") == Expr(:braces, Expr(:parameters, Expr(:(=), :b, 2)),