Skip to content

Commit 027ee01

Browse files
authored
Merge pull request #378 from julia-vscode/sp/fix-1-10
fix: 1.10 compat
2 parents 02c54a6 + 464aa13 commit 027ee01

File tree

8 files changed

+111
-48
lines changed

8 files changed

+111
-48
lines changed

src/components/internals.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ end
4949
function adjust_iter(x::EXPR)
5050
# Assumes x is a valid iterator
5151
if x.head === :call # isoperator(x.args[1]) && x.args[1].val in ("in", "∈")
52-
EXPR(EXPR(:OPERATOR, 0, 0, "="), EXPR[x.args[2], x.args[3]], EXPR[x.args[1]])
53-
elseif isassignment(x) && length(x.args) == 2 && x.args[1].head == :call && x.args[2].head == :block && length(x.args[2].args) == 1
52+
if VERSION > v"1.10-" && x.args[2] isa EXPR && x.args[2].head === :call
53+
x.args[3] = EXPR(:block, EXPR[x.args[3]])
54+
end
55+
return EXPR(EXPR(:OPERATOR, 0, 0, "="), EXPR[x.args[2], x.args[3]], EXPR[x.args[1]])
56+
elseif VERSION < v"1.10-" && isassignment(x) && length(x.args) == 2 && x.args[1].head == :call && x.args[2].head == :block && length(x.args[2].args) == 1
5457
x.args[2] = setparent!(x.args[2].args[1], x)
55-
x
56-
else
57-
x
5858
end
59+
return x
5960
end
6061

6162
"""

src/conversion.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Terminals
22
function julia_normalization_map(c::Int32, x::Ptr{Nothing})::Int32
3-
return c == 0x00B5 ? 0x03BC : # micro sign -> greek small letter mu
4-
c == 0x025B ? 0x03B5 : # latin small letter open e -> greek small letter
5-
c == 0x00B7 ? 0x22C5 :
6-
c == 0x0387 ? 0x22C5 :
7-
c == 0x2212 ? 0x002D :
3+
return c == 0x025B ? 0x03B5 : # latin small letter open e -> greek small letter epsilon
4+
c == 0x00B5 ? 0x03BC : # micro sign -> greek small letter mu
5+
c == 0x00B7 ? 0x22C5 : # middot char -> dot operator (#25098)
6+
c == 0x0387 ? 0x22C5 : # Greek interpunct -> dot operator (#25098)
7+
c == 0x2212 ? 0x002D : # minus -> hyphen-minus (#26193)
8+
c == 0x210F ? 0x0127 : # hbar -> small letter h with stroke (#48870)
89
c
910
end
1011

@@ -219,7 +220,7 @@ function to_codeobject(x::EXPR)
219220
Expr(Symbol(lowercase(String(x.head))))
220221
elseif VERSION < v"1.7.0-DEV.1129" && x.head === :ncat
221222
dim = tryparse(Int, String(x.args[1].head))
222-
dim == nothing && return Expr(:error)
223+
dim === nothing && return Expr(:error)
223224
head = dim == 1 ? :hcat : :vcat
224225
Expr(head, to_codeobject.(x.args[2:end])...)
225226
elseif x.head === :errortoken

src/utils.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,12 @@ _kw_convert(x::EXPR) = EXPR(:kw, EXPR[x.args[1], x.args[2]], EXPR[x.head], x.ful
617617
618618
When parsing a function or macro signature, should it be converted to a tuple?
619619
"""
620-
convertsigtotuple(sig::EXPR) = isbracketed(sig) && !(istuple(sig.args[1]) || iscall(sig.args[1]) || (headof(sig.args[1]) === :block) || issplat(sig.args[1]))
620+
convertsigtotuple(sig::EXPR) = isbracketed(sig) && !(
621+
istuple(sig.args[1]) ||
622+
iscall(sig.args[1]) ||
623+
headof(sig.args[1]) === :block ||
624+
issplat(sig.args[1])
625+
)
621626

622627
"""
623628
docable(head)

test/parser/test_function_calls.jl

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,31 @@ end
5353
@test "x->y" |> test_expr
5454
@test "(x,y)->x*y" |> test_expr
5555
@test """function ()
56-
return
57-
end""" |> test_expr
58-
end
56+
return
57+
end""" |> test_expr
58+
@test """
59+
function (a,b)
60+
a+b
61+
end
62+
""" |> test_expr
63+
@test """
64+
function (a,b;c=2)
65+
a+b
66+
end
67+
""" |> test_expr
68+
@test """
69+
function (a,b;c)
70+
a+b
71+
end
72+
""" |> test_expr
73+
@test """
74+
function (;a,b=2)
75+
a+b
76+
end
77+
""" |> test_expr
78+
@test """
79+
function (b=2)
80+
a+b
81+
end
82+
""" |> test_expr
83+
end

test/parser/test_operators.jl

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# @testitem "Binary Operators" begin
22
# using CSTParser: remlineinfo!
33
# include("../shared.jl")
4-
4+
55
# for iter = 1:25
66
# println(iter)
77
# str = join([["x$(randop())" for i = 1:19];"x"])
@@ -13,7 +13,7 @@
1313
@testitem "Conditional Operator" begin
1414
using CSTParser: remlineinfo!
1515
include("../shared.jl")
16-
16+
1717
@test test_expr("a ? b : c")
1818
@test test_expr("a ? b : c : d")
1919
@test test_expr("a ? b : c : d : e")
@@ -24,7 +24,7 @@ end
2424
@testitem "Dot Operator" begin
2525
using CSTParser: remlineinfo!
2626
include("../shared.jl")
27-
27+
2828
@test "a.b" |> test_expr
2929
@test "a.b.c" |> test_expr
3030
@test "(a(b)).c" |> test_expr
@@ -36,7 +36,7 @@ end
3636
@testitem "Unary Operator" begin
3737
using CSTParser: remlineinfo!
3838
include("../shared.jl")
39-
39+
4040
@test "+" |> test_expr
4141
@test "-" |> test_expr
4242
@test "!" |> test_expr
@@ -49,7 +49,7 @@ end
4949
@test "" |> test_expr
5050
@test "" |> test_expr
5151
@test "" |> test_expr
52-
52+
5353
@test "a=b..." |> test_expr
5454
@test "a-->b..." |> test_expr
5555
if VERSION >= v"1.6"
@@ -77,7 +77,7 @@ end
7777
@testitem "unary op calls" begin
7878
using CSTParser: remlineinfo!
7979
include("../shared.jl")
80-
80+
8181
@test "+(a,b)" |> test_expr
8282
@test "-(a,b)" |> test_expr
8383
@test "!(a,b)" |> test_expr
@@ -100,7 +100,7 @@ end
100100
@testitem "dotted non-calls" begin
101101
using CSTParser: remlineinfo!
102102
include("../shared.jl")
103-
103+
104104
@test "f(.+)" |> test_expr
105105
@test "f(.-)" |> test_expr
106106
@test "f(.!)" |> test_expr
@@ -118,7 +118,7 @@ end
118118
@testitem "comment parsing" begin
119119
using CSTParser: remlineinfo!
120120
include("../shared.jl")
121-
121+
122122
if VERSION >= v"1.6"
123123
@test "[1#==#2#==#3]" |> test_expr
124124
@test """
@@ -138,27 +138,29 @@ end
138138
@testitem "weird quote parsing" begin
139139
using CSTParser: remlineinfo!
140140
include("../shared.jl")
141-
141+
142142
@test ":(;)" |> test_expr
143143
@test ":(;;)" |> test_expr
144144
@test ":(;;;)" |> test_expr
145145
end
146146

147-
# this errors during *lowering*, not parsing.
148-
@testitem "parse const without assignment in quote" begin
149-
using CSTParser: remlineinfo!
150-
include("../shared.jl")
151-
152-
@test ":(global const x)" |> test_expr
153-
@test ":(global const x::Int)" |> test_expr
154-
@test ":(const global x)" |> test_expr
155-
@test ":(const global x::Int)" |> test_expr
147+
# In previous Julia versions, this errored during lowering. With JuliaSyntax, this is a parser error
148+
if VERSION < v"1.10-"
149+
@testitem "parse const without assignment in quote" begin
150+
using CSTParser: remlineinfo!
151+
include("../shared.jl")
152+
153+
@test ":(global const x)" |> test_expr
154+
@test ":(global const x::Int)" |> test_expr
155+
@test ":(const global x)" |> test_expr
156+
@test ":(const global x::Int)" |> test_expr
157+
end
156158
end
157159

158160
@testitem "where precedence" begin
159161
using CSTParser: remlineinfo!
160162
include("../shared.jl")
161-
163+
162164
@test "a = b where c = d" |> test_expr
163165
@test "a = b where c" |> test_expr
164166
@test "b where c = d" |> test_expr

test/parser/test_parser.jl

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,12 @@ end
272272
end
273273
""" |> test_expr
274274
@test "function f() ::T end" |> test_expr # ws closer
275-
@test "import Base: +, -, .+, .-" |> test_expr
275+
if VERSION > v"1.10-"
276+
# import Base: .+ is no longer valid with Julia 1.10
277+
@test "import Base: +, -" |> test_expr
278+
else
279+
@test "import Base: +, -, .+, .-" |> test_expr
280+
end
276281
if VERSION > v"1.6-"
277282
@test "import Base.:+" |> test_expr
278283
@test "import Base.:⋅" |> test_expr
@@ -314,6 +319,9 @@ end
314319
"\\\\\$ch"
315320
""" |> test_expr
316321
@test "µs" |> test_expr # normalize unicode
322+
if VERSION >= v"1.10-"
323+
@test "ℏħ" |> test_expr # normalize unicode
324+
end
317325
@test """
318326
(x, o; p = 1) -> begin
319327
return o, p
@@ -865,8 +873,11 @@ end
865873
@test test_expr(raw"""test"asd"0x0""")
866874
@test test_expr(raw"""test"asd"0.0""")
867875
end
868-
@test test_expr(raw"""test"asd"true""")
869-
@test test_expr(raw"""test""true""")
876+
# this regressed in JuliaSyntax: https://github.com/JuliaLang/JuliaSyntax.jl/issues/401
877+
if VERSION <= v"1.10-"
878+
@test test_expr(raw"""test"asd"true""")
879+
@test test_expr(raw"""test""true""")
880+
end
870881
end
871882

872883
@testitem "number parsing" begin

test/parser/test_square.jl

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@testitem "vect" begin
22
using CSTParser: remlineinfo!
33
include("../shared.jl")
4-
4+
55
@test "[x]" |> test_expr
66
@test "[(1,2)]" |> test_expr
77
@test "[x...]" |> test_expr
@@ -20,15 +20,15 @@ end
2020
@testitem "ref" begin
2121
using CSTParser: remlineinfo!
2222
include("../shared.jl")
23-
23+
2424
@test "t[i]" |> test_expr
2525
@test "t[i, j]" |> test_expr
2626
end
2727

2828
@testitem "vcat" begin
2929
using CSTParser: remlineinfo!
3030
include("../shared.jl")
31-
31+
3232
@test "[x;]" |> test_expr
3333
@test "[x;y;z]" |> test_expr
3434
@test """[x
@@ -45,7 +45,7 @@ end
4545
@testitem "typed_vcat" begin
4646
using CSTParser: remlineinfo!
4747
include("../shared.jl")
48-
48+
4949
@test "t[x;]" |> test_expr
5050
@test "t[x;y]" |> test_expr
5151
@test """t[x
@@ -58,7 +58,7 @@ end
5858
@testitem "ncat" begin
5959
using CSTParser: remlineinfo!
6060
include("../shared.jl")
61-
61+
6262
if VERSION > v"1.8-"
6363
@test "[;]" |> test_expr
6464
@test "[;;]" |> test_expr
@@ -82,7 +82,7 @@ end
8282
@testitem "typed_ncat" begin
8383
using CSTParser: remlineinfo!
8484
include("../shared.jl")
85-
85+
8686
if VERSION > v"1.8-"
8787
@test "t[;;]" |> test_expr
8888
@test "t[;;;;;;;]" |> test_expr
@@ -101,7 +101,7 @@ end
101101
@testitem "hcat" begin
102102
using CSTParser: remlineinfo!
103103
include("../shared.jl")
104-
104+
105105
@test "[x y]" |> test_expr
106106
@test "[let; x; end y]" |> test_expr
107107
@test "[let; x; end; y]" |> test_expr
@@ -110,7 +110,7 @@ end
110110
@testitem "typed_hcat" begin
111111
using CSTParser: remlineinfo!
112112
include("../shared.jl")
113-
113+
114114
@test "t[x y]" |> test_expr
115115
@test "t[let; x; end y]" |> test_expr
116116
@test "t[let; x; end; y]" |> test_expr
@@ -119,13 +119,13 @@ end
119119
@testitem "Comprehension" begin
120120
using CSTParser: remlineinfo!
121121
include("../shared.jl")
122-
122+
123123
@test "[i for i = 1:10]" |> test_expr
124124
@test "Int[i for i = 1:10]" |> test_expr
125125
@test "[let;x;end for x in x]" |> test_expr
126126
@test "[let; x; end for x in x]" |> test_expr
127127
@test "[let x=x; x+x; end for x in x]" |> test_expr
128-
if VERSION > v"1.7-"
128+
if v"1.7-" < VERSION < v"1.10-"
129129
@test """[
130130
[
131131
let l = min((d-k),k);
@@ -135,4 +135,14 @@ end
135135
]
136136
""" |> test_expr
137137
end
138+
if VERSION > v"1.10-"
139+
@test """[
140+
[
141+
let l = min((d-k),k);
142+
binomial(d-l,l);
143+
end for k in 1:d-1
144+
] for d in 2:9
145+
]
146+
""" |> test_expr
147+
end
138148
end

test/test_check_base.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,15 @@
156156
else
157157
@error "parsing difference" file = file
158158
_compare(cst_expr, meta_expr)
159-
@test false
159+
# 1.10 introduced a bunch of changes to the canonical AST, which
160+
# CSTParser does not support right now. This does not mean that we
161+
# cannot parse that file though, just that Expr conversion doesn't
162+
# work well
163+
if v"1.10-" <= VERSION < v"1.11-" && basename(file) == "syntax.jl"
164+
@test_broken false
165+
else
166+
@test false
167+
end
160168
end
161169
end
162170
end

0 commit comments

Comments
 (0)