Skip to content

Commit 39ffec8

Browse files
committed
rename Expr constructor to to_expr
1 parent 778212a commit 39ffec8

File tree

7 files changed

+29
-31
lines changed

7 files changed

+29
-31
lines changed

src/conversion.jl

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import Core: Expr
2-
31
# Terminals
42
function julia_normalization_map(c::Int32, x::Ptr{Nothing})::Int32
53
return c == 0x00B5 ? 0x03BC : # micro sign -> greek small letter mu
@@ -129,8 +127,8 @@ end
129127

130128

131129
# Expressions
132-
133-
function Expr(x::EXPR)
130+
to_expr(args...) = Expr(args...)
131+
function to_expr(x::EXPR)
134132
if isidentifier(x)
135133
if headof(x) === :NONSTDIDENTIFIER
136134
if startswith(valof(x.args[1]), "@")
@@ -143,9 +141,9 @@ function Expr(x::EXPR)
143141
end
144142
elseif iskeyword(x)
145143
if headof(x) === :BREAK
146-
return Expr(:break)
144+
return to_expr(:break)
147145
elseif headof(x) === :CONTINUE
148-
return Expr(:continue)
146+
return to_expr(:continue)
149147
else
150148
return Symbol(lowercase(string(headof(x))))
151149
end
@@ -156,7 +154,7 @@ function Expr(x::EXPR)
156154
if x.args === nothing
157155
return :(.)
158156
elseif length(x.args) == 1 && isoperator(x.args[1])
159-
return Expr(:(.), Expr(x.args[1]))
157+
return Expr(:(.), to_expr(x.args[1]))
160158
else
161159
Expr(:error)
162160
end
@@ -167,11 +165,11 @@ function Expr(x::EXPR)
167165
elseif isliteral(x)
168166
return _literal_expr(x)
169167
elseif isbracketed(x)
170-
return Expr(x.args[1])
168+
return to_expr(x.args[1])
171169
elseif x.head isa EXPR
172-
Expr(Expr(x.head), Expr.(x.args)...)
170+
Expr(to_expr(x.head), to_expr.(x.args)...)
173171
elseif x.head === :quotenode
174-
QuoteNode(Expr(x.args[1]))
172+
QuoteNode(to_expr(x.args[1]))
175173
elseif x.head === :globalrefdoc
176174
GlobalRef(Core, Symbol("@doc"))
177175
elseif x.head === :globalrefcmd
@@ -185,20 +183,20 @@ function Expr(x::EXPR)
185183
valofrhs = valof(x.args[1].args[2].args[1])
186184
valofrhs = valofrhs === nothing ? "" : valofrhs
187185
new_name = Expr(:., remove_at(x.args[1].args[1]), QuoteNode(Symbol("@", valofrhs)))
188-
Expr(:macrocall, new_name, Expr.(x.args[2:end])...)
186+
Expr(:macrocall, new_name, to_expr.(x.args[2:end])...)
189187
elseif x.head === :macrocall && isidentifier(x.args[1]) && valof(x.args[1]) == "@."
190-
Expr(:macrocall, Symbol("@__dot__"), Expr.(x.args[2:end])...)
188+
Expr(:macrocall, Symbol("@__dot__"), to_expr.(x.args[2:end])...)
191189
elseif x.head === :macrocall && length(x.args) == 3 && x.args[1].head === :globalrefcmd && x.args[3].head == :string
192-
Expr(:macrocall, Expr(x.args[1]), Expr(x.args[2]), x.args[3].meta)
190+
Expr(:macrocall, to_expr(x.args[1]), to_expr(x.args[2]), x.args[3].meta)
193191
elseif x.head === :string && length(x.args) > 0 && (x.args[1].head === :STRING || x.args[1].head === :TRIPLESTRING) && isempty(valof(x.args[1]))
194192
# Special conversion needed - the initial text section is treated as empty for the represented string following lowest-common-prefix adjustments, but exists in the source.
195-
Expr(:string, Expr.(x.args[2:end])...)
193+
Expr(:string, to_expr.(x.args[2:end])...)
196194
elseif x.args === nothing
197195
Expr(Symbol(lowercase(String(x.head))))
198196
elseif x.head === :errortoken
199197
Expr(:error)
200198
else
201-
Expr(Symbol(lowercase(String(x.head))), Expr.(x.args)...)
199+
Expr(Symbol(lowercase(String(x.head))), to_expr.(x.args)...)
202200
end
203201
end
204202

@@ -208,7 +206,7 @@ function remove_at(x)
208206
elseif is_getfield_w_quotenode(x)
209207
Expr(:., remove_at(x.args[1]), QuoteNode(remove_at(x.args[2].args[1])))
210208
else
211-
Expr(x)
209+
to_expr(x)
212210
end
213211
end
214212

src/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ function str_value(x)
441441
elseif isidentifier(x)
442442
valof(x.args[2])
443443
elseif isoperator(x)
444-
return string(Expr(x))
444+
return string(to_expr(x))
445445
else
446446
return ""
447447
end

test/check_base.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function cst_parse_file(str)
7272
@error "CST spans inconsistent!"
7373
end
7474

75-
x0 = norm_ast(Expr(x))
75+
x0 = norm_ast(to_expr(x))
7676
x0, CSTParser.has_error(ps) || !isempty(sp)
7777
end
7878

test/errparse.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
rethrow(e)
4747
end
4848
try
49-
Expr(x)
49+
to_expr(x)
5050
catch e
5151
@info "Couldn't convert:"
5252
@info s

test/iterate.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function test_iter_spans(x)
55
for i = 1:length(x)
66
a = x[i]
77
if !(a isa EXPR)
8-
@info i, headof(x), Expr(x)
8+
@info i, headof(x), to_expr(x)
99
end
1010
@test a isa EXPR
1111
test_iter_spans(a)

test/parser.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ end
3131
function test_expr(str, show_data=true)
3232
x, ps = CSTParser.parse(ParseState(str))
3333

34-
x0 = Expr(x)
34+
x0 = to_expr(x)
3535
x1 = remlineinfo!(Meta.parse(str))
3636

3737
@test x.args === nothing || all(x === parentof(a) for a in x.args)
@@ -624,10 +624,10 @@ end
624624
@test valof(CSTParser.parse("\"\"\"a\"\"\"")) == "a"
625625
@test valof(CSTParser.parse("\"\"\"\"\"\"")) == ""
626626
@test valof(CSTParser.parse("\"\"\"\n\t \ta\n\n\t \tb\"\"\"")) == "a\n\nb"
627-
@test Expr(CSTParser.parse("\"\"\"\ta\n\tb \$c\n\td\n\"\"\"")) == Expr(:string, "\ta\n\tb ", :c, "\n\td\n")
628-
@test Expr(CSTParser.parse("\"\"\"\n\ta\n\tb \$c\n\td\n\"\"\"")) == Expr(:string, "\ta\n\tb ", :c, "\n\td\n")
629-
@test Expr(CSTParser.parse("\"\"\"\n\ta\n\tb \$c\n\td\n\t\"\"\"")) == Expr(:string, "a\nb ", :c, "\nd\n")
630-
@test Expr(CSTParser.parse("\"\"\"\n\t \ta\$(1+\n1)\n\t \tb\"\"\"")) == Expr(:string, "a", :(1 + 1), "\nb")
627+
@test to_expr(CSTParser.parse("\"\"\"\ta\n\tb \$c\n\td\n\"\"\"")) == Expr(:string, "\ta\n\tb ", :c, "\n\td\n")
628+
@test to_expr(CSTParser.parse("\"\"\"\n\ta\n\tb \$c\n\td\n\"\"\"")) == Expr(:string, "\ta\n\tb ", :c, "\n\td\n")
629+
@test to_expr(CSTParser.parse("\"\"\"\n\ta\n\tb \$c\n\td\n\t\"\"\"")) == Expr(:string, "a\nb ", :c, "\nd\n")
630+
@test to_expr(CSTParser.parse("\"\"\"\n\t \ta\$(1+\n1)\n\t \tb\"\"\"")) == Expr(:string, "a", :(1 + 1), "\nb")
631631
ws = " "
632632
"\"\"\"\n$ws%rv = atomicrmw \$rmw \$lt* %0, \$lt %1 acq_rel\n$(ws)ret \$lt %rv\n$ws\"\"\"" |> test_expr
633633
ws1 = " "
@@ -1061,7 +1061,7 @@ end
10611061
end
10621062
end
10631063
@testset "bad uint" begin
1064-
@test Expr(CSTParser.parse("0x.")) == Expr(:error)
1064+
@test to_expr(CSTParser.parse("0x.")) == Expr(:error)
10651065
end
10661066

10671067
@testset "endswithtrivia" begin

test/spec.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using CSTParser: @cst_str, headof, parentof, check_span, EXPR
1+
using CSTParser: @cst_str, headof, parentof, check_span, EXPR, to_expr
22
jl_parse(s) = CSTParser.remlineinfo!(Meta.parse(s))
33

44
function check_parents(x::EXPR)
@@ -33,7 +33,7 @@ function test_expr(s, head, n, endswithtrivia = false)
3333
@test length(x) === n
3434
@test x.args === nothing || all(x === parentof(a) for a in x.args)
3535
@test x.trivia === nothing || all(x === parentof(a) for a in x.trivia)
36-
@test Expr(x) == jl_parse(s)
36+
@test to_expr(x) == jl_parse(s)
3737
@test isempty(check_span(x))
3838
check_parents(x)
3939
test_iter(x)
@@ -266,17 +266,17 @@ end
266266
let s = "``"
267267
x = CSTParser.parse(s)
268268
x1 = jl_parse(s)
269-
@test x1 == Expr(x)
269+
@test x1 == to_expr(x)
270270
end
271271
let s = "`a`"
272272
x = CSTParser.parse(s)
273273
x1 = jl_parse(s)
274-
@test x1 == Expr(x)
274+
@test x1 == to_expr(x)
275275
end
276276
let s = "`a \$a`"
277277
x = CSTParser.parse(s)
278278
x1 = jl_parse(s)
279-
@test x1 == Expr(x)
279+
@test x1 == to_expr(x)
280280
end
281281
test_expr("a``", nothing, 3, false)
282282
test_expr("a`a`", nothing, 3, false)

0 commit comments

Comments
 (0)