Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function reorder_parameters!(args, params_pos)
end

function _to_expr(node::SyntaxNode; iteration_spec=false, need_linenodes=true,
eq_to_kw=false, inside_dot_expr=false, inside_vect_or_braces=false)
eq_to_kw=false, inside_vect_or_braces=false)
if !haschildren(node)
val = node.val
if val isa Union{Int128,UInt128,BigInt}
Expand Down Expand Up @@ -125,11 +125,9 @@ function _to_expr(node::SyntaxNode; iteration_spec=false, need_linenodes=true,
args[2] = _to_expr(node_args[2])
else
eq_to_kw_in_call =
headsym == :call && is_prefix_call(node) ||
((headsym == :call || headsym == :dotcall) && is_prefix_call(node)) ||
headsym == :ref
eq_to_kw_all = headsym == :parameters && !inside_vect_or_braces ||
(headsym == :tuple && inside_dot_expr)
in_dot = headsym == :.
eq_to_kw_all = headsym == :parameters && !inside_vect_or_braces
in_vb = headsym == :vect || headsym == :braces
if insert_linenums && isempty(node_args)
push!(args, source_location(LineNumberNode, node.source, node.position))
Expand All @@ -142,7 +140,6 @@ 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,
inside_dot_expr=in_dot,
inside_vect_or_braces=in_vb)
end
end
Expand All @@ -155,7 +152,7 @@ function _to_expr(node::SyntaxNode; iteration_spec=false, need_linenodes=true,
if args[1] == Symbol("@.")
args[1] = Symbol("@__dot__")
end
elseif headsym in (:call, :ref)
elseif headsym in (:dotcall, :call, :ref)
# 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.
Expand All @@ -169,6 +166,21 @@ function _to_expr(node::SyntaxNode; iteration_spec=false, need_linenodes=true,
end
# Move parameters blocks to args[2]
reorder_parameters!(args, 2)
if headsym === :dotcall
if is_prefix_call(node)
return Expr(:., args[1], Expr(:tuple, args[2:end]...))
else
# operator calls
headsym = :call
args[1] = Symbol(".", args[1])
end
end
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)
Expand Down
1 change: 1 addition & 0 deletions src/kinds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,7 @@ const _kind_names =
"BEGIN_SYNTAX_KINDS"
"block"
"call"
"dotcall"
"comparison"
"curly"
"inert" # QuoteNode; not quasiquote
Expand Down
6 changes: 2 additions & 4 deletions src/parse_stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function untokenize(head::SyntaxHead; unique=true, include_flag_suff=true)
if include_flag_suff && suffix_flags != EMPTY_FLAGS
str = str*"-"
is_trivia(head) && (str = str*"t")
is_infix_op_call(head) && (str = str*"i")
is_infix_op_call(head) && (str = str*"i")
is_prefix_op_call(head) && (str = str*"pre")
is_postfix_op_call(head) && (str = str*"post")
has_flags(head, TRIPLE_STRING_FLAG) && (str = str*"s")
Expand Down Expand Up @@ -725,9 +725,7 @@ function bump_split(stream::ParseStream, split_spec...)
push!(stream.tokens, SyntaxToken(h, kind(tok), b))
end
stream.peek_count = 0
# Returning position(stream) like the other bump* methods would be
# ambiguous here; return nothing instead.
nothing
return position(stream)
end

function _reset_node_head(x, k, f)
Expand Down
Loading