Skip to content

Commit 3aa5133

Browse files
authored
Merge pull request #296 from julia-vscode/sp/iter-fixes
fix various iteration issues
2 parents d98b693 + 1cf2d98 commit 3aa5133

File tree

5 files changed

+30
-10
lines changed

5 files changed

+30
-10
lines changed

src/components/internals.jl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,7 @@ function parse_parameters(ps::ParseState, args::Vector{EXPR}, args1::Vector{EXPR
232232
isfirst = true
233233
end
234234
if !isempty(args1)
235-
# this happens when multiple semi-colons are used
236-
# Julia will error during lowering, so these shenanigans are just for matching
237-
# kwarg order with Base's parser
238-
if length(args) >= 1 && args[1] isa EXPR && args[1].head == :kw && usekw
239-
insert!(args, max(insert_params_at - 1, 1), EXPR(:parameters, args1, trivia))
240-
else
241-
insert!(args, insert_params_at, EXPR(:parameters, args1, trivia))
242-
end
235+
insert!(args, insert_params_at, EXPR(:parameters, args1, trivia))
243236
end
244237
return
245238
end

src/components/operators.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ function parse_unary_colon(ps::ParseState, op::EXPR)
254254
if isoperator(unwrapped) || isidentifier(unwrapped) || isliteral(unwrapped)
255255
ret = EXPR(:quotenode, EXPR[arg], EXPR[op])
256256
elseif arg.head == :tuple && length(arg.args) == 1 && arg.args[1].head == :parameters && length(something(arg.args[1].args, [])) == 0 && arg.span > 3
257-
ret = EXPR(:quote, EXPR[EXPR(:BLOCK, EXPR[], EXPR[])], EXPR[])
257+
ret = EXPR(:quote, EXPR[EXPR(:BLOCK, EXPR[], EXPR[])], EXPR[op])
258258
else
259259
ret = EXPR(:quote, EXPR[arg], EXPR[op])
260260
end

src/conversion.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,20 @@ function Expr(x::EXPR)
195195
Expr(:string, Expr.(x.args[2:end])...)
196196
elseif x.args === nothing
197197
Expr(Symbol(lowercase(String(x.head))))
198+
elseif x.head === :parameters
199+
if length(x.args) > 1 && any(a -> a.head === :parameters, x.args)
200+
ordered_args = EXPR[]
201+
for arg in x.args
202+
if arg.head === :parameters
203+
pushfirst!(ordered_args, arg)
204+
else
205+
push!(ordered_args, arg)
206+
end
207+
end
208+
Expr(:parameters, Expr.(ordered_args)...)
209+
else
210+
Expr(:parameters, Expr.(x.args)...)
211+
end
198212
elseif x.head === :errortoken
199213
Expr(:error)
200214
else

src/iterate.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function Base.getindex(x::EXPR, i)
88
error("indexing error for $(x.head) expression at $i")
99
end
1010
return a
11-
catch
11+
catch
1212
error("indexing error for $(x.head) expression at $i. args: $(x.args !== nothing ? headof.(x.args) : []) trivia: $(x.trivia !== nothing ? headof.(x.trivia) : [])")
1313
end
1414
end

test/parser.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ randop() = rand(["-->", "→",
1616

1717
test_expr_broken(str) = test_expr(str, false)
1818

19+
function traverse(x)
20+
try
21+
for a in x
22+
@test traverse(a)
23+
end
24+
return true
25+
catch err
26+
@error "EXPR traversal failed." expr = x exception = err
27+
return false
28+
end
29+
end
30+
1931
function test_expr(str, show_data=true)
2032
x, ps = CSTParser.parse(ParseState(str))
2133

@@ -26,6 +38,7 @@ function test_expr(str, show_data=true)
2638
@test x.trivia === nothing || all(x === parentof(a) for a in x.trivia)
2739
@test isempty(check_span(x))
2840
check_parents(x)
41+
@test traverse(x)
2942

3043
if CSTParser.has_error(ps) || x0 != x1
3144
if show_data

0 commit comments

Comments
 (0)