120 |
118 |
|
|
121 |
119 |
|
# Expressions |
122 |
120 |
|
|
123 |
|
- |
# Fallback |
124 |
121 |
|
function Expr(x::EXPR) |
125 |
122 |
|
if isidentifier(x) |
126 |
|
- |
if typof(x) === NONSTDIDENTIFIER |
|
123 |
+ |
if headof(x) === :NONSTDIDENTIFIER |
127 |
124 |
|
Symbol(normalize_julia_identifier(valof(x.args[2]))) |
128 |
125 |
|
else |
129 |
126 |
|
return Symbol(normalize_julia_identifier(valof(x))) |
130 |
127 |
|
end |
131 |
|
- |
elseif iskw(x) |
132 |
|
- |
if kindof(x) === Tokens.BREAK |
|
128 |
+ |
elseif iskeyword(x) |
|
129 |
+ |
if headof(x) === :BREAK |
133 |
130 |
|
return Expr(:break) |
134 |
|
- |
elseif kindof(x) === Tokens.CONTINUE |
|
131 |
+ |
elseif headof(x) === :CONTINUE |
135 |
132 |
|
return Expr(:continue) |
136 |
133 |
|
else |
137 |
|
- |
return Symbol(lowercase(string(kindof(x)))) |
|
134 |
+ |
return Symbol(lowercase(string(headof(x)))) |
138 |
135 |
|
end |
139 |
136 |
|
elseif isoperator(x) |
140 |
|
- |
ret = x.val isa String ? Symbol(valof(x)) : UNICODE_OPS_REVERSE[kindof(x)] |
141 |
|
- |
return x.dot ? Symbol(:., ret) : ret |
|
137 |
+ |
return Symbol(valof(x)) |
142 |
138 |
|
elseif ispunctuation(x) |
143 |
|
- |
return string(kindof(x)) |
|
139 |
+ |
if headof(x) === :DOT |
|
140 |
+ |
return :(.) |
|
141 |
+ |
else |
|
142 |
+ |
error() |
|
143 |
+ |
end |
144 |
144 |
|
elseif isliteral(x) |
145 |
145 |
|
return _literal_expr(x) |
146 |
|
- |
elseif isunarycall(x) |
147 |
|
- |
return _unary_expr(x) |
148 |
|
- |
elseif isbinarycall(x) |
149 |
|
- |
return _binary_expr(x) |
150 |
|
- |
elseif iswherecall(x) |
151 |
|
- |
return _where_expr(x) |
152 |
|
- |
elseif typof(x) === ConditionalOpCall |
153 |
|
- |
return Expr(:if, Expr(x.args[1]), Expr(x.args[3]), Expr(x.args[5])) |
154 |
|
- |
elseif typof(x) === ErrorToken |
155 |
|
- |
ret = Expr(:error) |
156 |
|
- |
if x.args !== nothing |
157 |
|
- |
for a in x.args |
158 |
|
- |
if !(ispunctuation(a)) |
159 |
|
- |
push!(ret.args, Expr(a)) |
160 |
|
- |
end |
161 |
|
- |
end |
162 |
|
- |
end |
163 |
|
- |
return ret |
164 |
|
- |
elseif typof(x) === ChainOpCall |
165 |
|
- |
ret = Expr(:call, Expr(x.args[2])) |
166 |
|
- |
for i = 1:length(x.args) |
167 |
|
- |
if isodd(i) |
168 |
|
- |
push!(ret.args, Expr(x.args[i])) |
169 |
|
- |
end |
170 |
|
- |
end |
171 |
|
- |
return ret |
172 |
|
- |
elseif typof(x) === Comparison |
173 |
|
- |
ret = Expr(:comparison) |
174 |
|
- |
for a in x.args |
175 |
|
- |
if !(ispunctuation(a)) |
176 |
|
- |
push!(ret.args, Expr(a)) |
177 |
|
- |
end |
178 |
|
- |
end |
179 |
|
- |
return ret |
180 |
|
- |
elseif typof(x) === ColonOpCall |
181 |
|
- |
return Expr(:call, :(:), Expr(x.args[1]), Expr(x.args[3]), Expr(x.args[5])) |
182 |
|
- |
elseif typof(x) === TopLevel |
183 |
|
- |
ret = Expr(:toplevel) |
184 |
|
- |
for a in x.args |
185 |
|
- |
if !(ispunctuation(a)) |
186 |
|
- |
push!(ret.args, Expr(a)) |
187 |
|
- |
end |
188 |
|
- |
end |
189 |
|
- |
return ret |
190 |
|
- |
elseif typof(x) === MacroName |
191 |
|
- |
if isidentifier(x.args[2]) |
192 |
|
- |
if valof(x.args[2]) == "." |
193 |
|
- |
return Symbol("@", "__dot__") |
194 |
|
- |
else |
195 |
|
- |
return Symbol("@", valof(x.args[2])) |
196 |
|
- |
end |
197 |
|
- |
elseif isoperator(x.args[2]) |
198 |
|
- |
return Symbol("@", Expr(x.args[2])) |
199 |
|
- |
|
200 |
|
- |
else |
201 |
|
- |
return Symbol("@") |
202 |
|
- |
end |
203 |
|
- |
elseif typof(x) === MacroCall |
204 |
|
- |
ret = Expr(:macrocall) |
205 |
|
- |
for a in x.args |
206 |
|
- |
if !(ispunctuation(a)) |
207 |
|
- |
push!(ret.args, Expr(a)) |
208 |
|
- |
end |
209 |
|
- |
end |
210 |
|
- |
insert!(ret.args, 2, nothing) |
211 |
|
- |
if ret.args[1] isa Expr && ret.args[1].head == :. && string(ret.args[1].args[2].value)[1] != '@' |
212 |
|
- |
clear_at!(ret.args[1]) |
213 |
|
- |
ret.args[1].args[2] = QuoteNode(Symbol(string('@', ret.args[1].args[2].value))) |
214 |
|
- |
end |
215 |
|
- |
ret |
216 |
|
- |
elseif typof(x) === x_Str |
217 |
|
- |
if isbinarycall(x.args[1]) && issyntaxcall(x.args[1].args[2]) |
218 |
|
- |
mname = Expr(x.args[1]) |
219 |
|
- |
mname.args[2] = QuoteNode(Symbol("@", mname.args[2].value, "_str")) |
220 |
|
- |
ret = Expr(:macrocall, mname, nothing) |
221 |
|
- |
else |
222 |
|
- |
ret = Expr(:macrocall, Symbol("@", valof(x.args[1]), "_str"), nothing) |
223 |
|
- |
end |
224 |
|
- |
for i = 2:length(x.args) |
225 |
|
- |
push!(ret.args, valof(x.args[i])) |
226 |
|
- |
end |
227 |
|
- |
return ret |
228 |
|
- |
elseif typof(x) === x_Cmd |
229 |
|
- |
ret = Expr(:macrocall, Symbol("@", valof(x.args[1]), "_cmd"), nothing) |
230 |
|
- |
for i = 2:length(x.args) |
231 |
|
- |
push!(ret.args, valof(x.args[i])) |
232 |
|
- |
end |
233 |
|
- |
return ret |
234 |
|
- |
elseif typof(x) === Quotenode |
235 |
|
- |
return QuoteNode(Expr(x.args[end])) |
236 |
|
- |
elseif typof(x) === Call |
237 |
|
- |
if kindof(x.args[1]) === Tokens.ISSUBTYPE || kindof(x.args[1]) === Tokens.ISSUPERTYPE |
238 |
|
- |
ret = Expr(Expr(x.args[1])) |
239 |
|
- |
for i in 2:length(x.args) |
240 |
|
- |
a = x.args[i] |
241 |
|
- |
if typof(a) === Parameters |
242 |
|
- |
insert!(ret.args, 2, Expr(a)) |
243 |
|
- |
elseif !(ispunctuation(a)) |
244 |
|
- |
push!(ret.args, Expr(a)) |
245 |
|
- |
end |
246 |
|
- |
end |
247 |
|
- |
return ret |
248 |
|
- |
end |
249 |
|
- |
ret = Expr(:call) |
250 |
|
- |
for a in x.args |
251 |
|
- |
if typof(a) === Parameters |
252 |
|
- |
insert!(ret.args, 2, Expr(a)) |
253 |
|
- |
elseif !(ispunctuation(a)) |
254 |
|
- |
push!(ret.args, Expr(a)) |
255 |
|
- |
end |
256 |
|
- |
end |
257 |
|
- |
return ret |
258 |
|
- |
elseif typof(x) === Braces |
259 |
|
- |
ret = Expr(:braces) |
260 |
|
- |
for a in x.args |
261 |
|
- |
if typof(a) === Parameters |
262 |
|
- |
insert!(ret.args, 1, Expr(a)) |
263 |
|
- |
elseif !(ispunctuation(a)) |
264 |
|
- |
push!(ret.args, Expr(a)) |
265 |
|
- |
end |
266 |
|
- |
end |
267 |
|
- |
return ret |
268 |
|
- |
elseif typof(x) === BracesCat |
269 |
|
- |
ret = Expr(:bracescat) |
270 |
|
- |
for a in x.args |
271 |
|
- |
if typof(a) === Parameters |
272 |
|
- |
insert!(ret.args, 1, Expr(a)) |
273 |
|
- |
elseif !(ispunctuation(a)) |
274 |
|
- |
push!(ret.args, Expr(a)) |
275 |
|
- |
end |
276 |
|
- |
end |
277 |
|
- |
return ret |
278 |
|
- |
elseif typof(x) === Struct |
279 |
|
- |
return Expr(:struct, false, Expr(x.args[2]), Expr(x.args[3])) |
280 |
|
- |
elseif typof(x) === Mutable |
281 |
|
- |
return length(x.args) == 4 ? Expr(:struct, true, Expr(x.args[2]), Expr(x.args[3])) : Expr(:struct, true, Expr(x.args[3]), Expr(x.args[4])) |
282 |
|
- |
elseif typof(x) === Abstract |
283 |
|
- |
return length(x.args) == 2 ? Expr(:abstract, Expr(x.args[2])) : Expr(:abstract, Expr(x.args[3])) |
284 |
|
- |
elseif typof(x) === Primitive |
285 |
|
- |
return Expr(:primitive, Expr(x.args[3]), Expr(x.args[4])) |
286 |
|
- |
elseif typof(x) === FunctionDef |
287 |
|
- |
ret = Expr(:function) |
288 |
|
- |
for a in x.args |
289 |
|
- |
if !(ispunctuation(a) || iskw(a)) |
290 |
|
- |
push!(ret.args, Expr(a)) |
291 |
|
- |
end |
292 |
|
- |
end |
293 |
|
- |
return ret |
294 |
|
- |
elseif typof(x) === Macro |
295 |
|
- |
if length(x.args) == 3 |
296 |
|
- |
Expr(:macro, Expr(x.args[2])) |
297 |
|
- |
else |
298 |
|
- |
Expr(:macro, Expr(x.args[2]), Expr(x.args[3])) |
299 |
|
- |
end |
300 |
|
- |
elseif typof(x) === ModuleH |
301 |
|
- |
return Expr(:module, true, Expr(x.args[2]), Expr(x.args[3])) |
302 |
|
- |
elseif typof(x) === BareModule |
303 |
|
- |
return Expr(:module, false, Expr(x.args[2]), Expr(x.args[3])) |
304 |
|
- |
elseif typof(x) === If |
305 |
|
- |
return _if_expr(x) |
306 |
|
- |
elseif typof(x) === Try |
307 |
|
- |
ret = Expr(:try) |
308 |
|
- |
for a in x.args |
309 |
|
- |
if !(ispunctuation(a) || iskw(a)) |
310 |
|
- |
push!(ret.args, Expr(a)) |
311 |
|
- |
end |
312 |
|
- |
end |
313 |
|
- |
return ret |
314 |
|
- |
elseif typof(x) === Let |
315 |
|
- |
return _let_expr(x) |
316 |
|
- |
elseif typof(x) === Do |
317 |
|
- |
return Expr(:do, Expr(x.args[1]), Expr(:->, Expr(x.args[3]), Expr(x.args[4]))) |
318 |
|
- |
elseif typof(x) === Outer |
319 |
|
- |
return Expr(:outer, Expr(x.args[2])) |
320 |
|
- |
elseif typof(x) === For |
321 |
|
- |
ret = Expr(:for) |
322 |
|
- |
if typof(x.args[2]) === Block |
323 |
|
- |
arg = Expr(:block) |
324 |
|
- |
for a in x.args[2].args |
325 |
|
- |
if !(ispunctuation(a)) |
326 |
|
- |
push!(arg.args, fix_range(a)) |
327 |
|
- |
end |
328 |
|
- |
end |
329 |
|
- |
push!(ret.args, arg) |
330 |
|
- |
else |
331 |
|
- |
push!(ret.args, fix_range(x.args[2])) |
332 |
|
- |
end |
333 |
|
- |
push!(ret.args, Expr(x.args[3])) |
334 |
|
- |
return ret |
335 |
|
- |
elseif typof(x) === While |
336 |
|
- |
ret = Expr(:while) |
337 |
|
- |
for a in x.args |
338 |
|
- |
if !(ispunctuation(a) || iskw(a)) |
339 |
|
- |
push!(ret.args, Expr(a)) |
340 |
|
- |
end |
341 |
|
- |
end |
342 |
|
- |
return ret |
343 |
|
- |
elseif istuple(x) |
344 |
|
- |
ret = Expr(:tuple) |
345 |
|
- |
for a in x.args |
346 |
|
- |
if typof(a) == Parameters |
347 |
|
- |
insert!(ret.args, 1, Expr(a)) |
348 |
|
- |
elseif !(ispunctuation(a)) |
349 |
|
- |
push!(ret.args, Expr(a)) |
350 |
|
- |
end |
351 |
|
- |
end |
352 |
|
- |
return ret |
353 |
|
- |
elseif typof(x) === Curly |
354 |
|
- |
ret = Expr(:curly) |
355 |
|
- |
for a in x.args |
356 |
|
- |
if typof(a) === Parameters |
357 |
|
- |
insert!(ret.args, 2, Expr(a)) |
358 |
|
- |
elseif !(ispunctuation(a)) |
359 |
|
- |
push!(ret.args, Expr(a)) |
360 |
|
- |
end |
361 |
|
- |
end |
362 |
|
- |
return ret |
363 |
|
- |
elseif typof(x) === Vect |
364 |
|
- |
ret = Expr(:vect) |
365 |
|
- |
for a in x.args |
366 |
|
- |
if typof(a) === Parameters |
367 |
|
- |
pushfirst!(ret.args, Expr(a)) |
368 |
|
- |
elseif !(ispunctuation(a)) |
369 |
|
- |
push!(ret.args, Expr(a)) |
370 |
|
- |
end |
371 |
|
- |
end |
372 |
|
- |
return ret |
373 |
|
- |
elseif typof(x) === Row |
374 |
|
- |
ret = Expr(:row) |
375 |
|
- |
for a in x.args |
376 |
|
- |
if !(ispunctuation(a)) |
377 |
|
- |
push!(ret.args, Expr(a)) |
378 |
|
- |
end |
379 |
|
- |
end |
380 |
|
- |
return ret |
381 |
|
- |
elseif typof(x) === Hcat |
382 |
|
- |
ret = Expr(:hcat) |
383 |
|
- |
for a in x.args |
384 |
|
- |
if !(ispunctuation(a)) |
385 |
|
- |
push!(ret.args, Expr(a)) |
386 |
|
- |
end |
387 |
|
- |
end |
388 |
|
- |
return ret |
389 |
|
- |
elseif typof(x) === Vcat |
390 |
|
- |
ret = Expr(:vcat) |
391 |
|
- |
for a in x.args |
392 |
|
- |
if !(ispunctuation(a)) |
393 |
|
- |
push!(ret.args, Expr(a)) |
394 |
|
- |
end |
395 |
|
- |
end |
396 |
|
- |
return ret |
397 |
|
- |
elseif typof(x) === Block |
398 |
|
- |
ret = Expr(:block) |
399 |
|
- |
for a in x.args |
400 |
|
- |
if !(ispunctuation(a)) |
401 |
|
- |
push!(ret.args, Expr(a)) |
402 |
|
- |
end |
403 |
|
- |
end |
404 |
|
- |
return ret |
405 |
|
- |
elseif typof(x) === Kw |
406 |
|
- |
return Expr(:kw, Expr(x.args[1]), Expr(x.args[3])) |
407 |
|
- |
elseif typof(x) === Parameters |
408 |
|
- |
ret = Expr(:parameters) |
409 |
|
- |
for a in x.args |
410 |
|
- |
if typof(a) === Parameters |
411 |
|
- |
insert!(ret.args, 2, Expr(a)) |
412 |
|
- |
elseif !(ispunctuation(a)) |
413 |
|
- |
push!(ret.args, Expr(a)) |
414 |
|
- |
end |
415 |
|
- |
end |
416 |
|
- |
return ret |
417 |
|
- |
elseif typof(x) === Return |
418 |
|
- |
ret = Expr(:return) |
419 |
|
- |
for i = 2:length(x.args) |
420 |
|
- |
a = x.args[i] |
421 |
|
- |
push!(ret.args, Expr(a)) |
422 |
|
- |
end |
423 |
|
- |
return ret |
424 |
146 |
|
elseif isbracketed(x) |
425 |
|
- |
return Expr(x.args[2]) |
426 |
|
- |
elseif typof(x) === Begin |
427 |
|
- |
return Expr(x.args[2]) |
428 |
|
- |
elseif typof(x) === Quote |
429 |
|
- |
if length(x.args) == 1 |
430 |
|
- |
return Expr(:quote, Expr(x.args[1])) |
431 |
|
- |
elseif isbracketed(x.args[2]) && (isoperator(x.args[2].args[2]) || isliteral(x.args[2].args[2]) || isidentifier(x.args[2].args[2])) |
432 |
|
- |
return QuoteNode(Expr(x.args[2])) |
|
147 |
+ |
return Expr(x.args[1]) |
|
148 |
+ |
elseif x.head isa EXPR |
|
149 |
+ |
Expr(Expr(x.head), Expr.(x.args)...) |
|
150 |
+ |
elseif x.head === :quotenode |
|
151 |
+ |
QuoteNode(Expr(x.args[1])) |
|
152 |
+ |
elseif x.head === :globalrefdoc |
|
153 |
+ |
GlobalRef(Core, Symbol("@doc")) |
|
154 |
+ |
elseif x.head === :globalrefcmd |
|
155 |
+ |
if VERSION > v"1.1" |
|
156 |
+ |
GlobalRef(Core, Symbol("@cmd")) |
433 |
157 |
|
else |
434 |
|
- |
return Expr(:quote, Expr(x.args[2])) |
435 |
|
- |
end |
436 |
|
- |
elseif typof(x) === Global |
437 |
|
- |
ret = Expr(:global) |
438 |
|
- |
if typof(x.args[2]) === Const |
439 |
|
- |
ret = Expr(:const, Expr(:global, Expr(x.args[2].args[2]))) |
440 |
|
- |
elseif length(x.args) == 2 && istuple(x.args[2]) |
441 |
|
- |
for a in x.args[2].args |
442 |
|
- |
if !(ispunctuation(a)) |
443 |
|
- |
push!(ret.args, Expr(a)) |
444 |
|
- |
end |
445 |
|
- |
end |
446 |
|
- |
else |
447 |
|
- |
for i = 2:length(x.args) |
448 |
|
- |
a = x.args[i] |
449 |
|
- |
push!(ret.args, Expr(a)) |
450 |
|
- |
end |
451 |
|
- |
end |
452 |
|
- |
return ret |
453 |
|
- |
elseif typof(x) === Local |
454 |
|
- |
ret = Expr(:local) |
455 |
|
- |
if typof(x.args[2]) === Const |
456 |
|
- |
ret = Expr(:const, Expr(:global, Expr(x.args[2].args[2]))) |
457 |
|
- |
elseif length(x.args) == 2 && istuple(x.args[2]) |
458 |
|
- |
for a in x.args[2].args |
459 |
|
- |
if !(ispunctuation(a)) |
460 |
|
- |
push!(ret.args, Expr(a)) |
461 |
|
- |
end |
462 |
|
- |
end |
463 |
|
- |
else |
464 |
|
- |
for i = 2:length(x.args) |
465 |
|
- |
a = x.args[i] |
466 |
|
- |
push!(ret.args, Expr(a)) |
467 |
|
- |
end |
468 |
|
- |
end |
469 |
|
- |
return ret |
470 |
|
- |
elseif typof(x) === Const |
471 |
|
- |
ret = Expr(:const) |
472 |
|
- |
for i = 2:length(x.args) |
473 |
|
- |
a = x.args[i] |
474 |
|
- |
push!(ret.args, Expr(a)) |
475 |
|
- |
end |
476 |
|
- |
return ret |
477 |
|
- |
elseif typof(x) === GlobalRefDoc |
478 |
|
- |
return GlobalRef(Core, Symbol("@doc")) |
479 |
|
- |
elseif typof(x) === Ref |
480 |
|
- |
ret = Expr(:ref) |
481 |
|
- |
for a in x.args |
482 |
|
- |
if typof(a) === Parameters |
483 |
|
- |
insert!(ret.args, 2, Expr(a)) |
484 |
|
- |
elseif !(ispunctuation(a)) |
485 |
|
- |
push!(ret.args, Expr(a)) |
486 |
|
- |
end |
487 |
|
- |
end |
488 |
|
- |
return ret |
489 |
|
- |
elseif typof(x) === TypedHcat |
490 |
|
- |
ret = Expr(:typed_hcat) |
491 |
|
- |
for a in x.args |
492 |
|
- |
if !(ispunctuation(a)) |
493 |
|
- |
push!(ret.args, Expr(a)) |
494 |
|
- |
end |
495 |
|
- |
end |
496 |
|
- |
return ret |
497 |
|
- |
elseif typof(x) === TypedVcat |
498 |
|
- |
ret = Expr(:typed_vcat) |
499 |
|
- |
for a in x.args |
500 |
|
- |
if typof(a) === Parameters |
501 |
|
- |
insert!(ret.args, 2, Expr(a)) |
502 |
|
- |
elseif !(ispunctuation(a)) |
503 |
|
- |
push!(ret.args, Expr(a)) |
504 |
|
- |
end |
505 |
|
- |
end |
506 |
|
- |
return ret |
507 |
|
- |
elseif typof(x) === Comprehension || typof(x) === DictComprehension |
508 |
|
- |
ret = Expr(:comprehension) |
509 |
|
- |
for a in x.args |
510 |
|
- |
if !(ispunctuation(a)) |
511 |
|
- |
push!(ret.args, Expr(a)) |
512 |
|
- |
end |
513 |
|
- |
end |
514 |
|
- |
return ret |
515 |
|
- |
elseif typof(x) === Flatten |
516 |
|
- |
iters, args = get_inner_gen(x) |
517 |
|
- |
i = popfirst!(iters) |
518 |
|
- |
ex = Expr(:generator, Expr(args[1]), convert_iter_assign(i[1])) |
519 |
|
- |
for i in iters |
520 |
|
- |
if length(i) == 1 |
521 |
|
- |
ex = Expr(:generator, ex, convert_iter_assign(i[1])) |
522 |
|
- |
ex = Expr(:flatten, ex) |
523 |
|
- |
else |
524 |
|
- |
ex = Expr(:generator, ex) |
525 |
|
- |
for j in i |
526 |
|
- |
push!(ex.args, convert_iter_assign(j)) |
527 |
|
- |
end |
528 |
|
- |
ex = Expr(:flatten, ex) |
529 |
|
- |
end |
530 |
|
- |
end |
531 |
|
- |
return ex |
532 |
|
- |
elseif typof(x) === Generator |
533 |
|
- |
ret = Expr(:generator, Expr(x.args[1])) |
534 |
|
- |
for i = 3:length(x.args) |
535 |
|
- |
a = x.args[i] |
536 |
|
- |
if !(ispunctuation(a)) |
537 |
|
- |
push!(ret.args, convert_iter_assign(a)) |
538 |
|
- |
end |
539 |
|
- |
end |
540 |
|
- |
return ret |
541 |
|
- |
elseif typof(x) === Filter |
542 |
|
- |
ret = Expr(:filter) |
543 |
|
- |
push!(ret.args, Expr(last(x.args))) |
544 |
|
- |
for i in 1:length(x.args) - 1 |
545 |
|
- |
a = x.args[i] |
546 |
|
- |
if !(is_if(a) || ispunctuation(a)) |
547 |
|
- |
push!(ret.args, convert_iter_assign(a)) |
548 |
|
- |
end |
549 |
|
- |
end |
550 |
|
- |
return ret |
551 |
|
- |
elseif typof(x) === TypedComprehension |
552 |
|
- |
ret = Expr(:typed_comprehension) |
553 |
|
- |
for a in x.args |
554 |
|
- |
if !(ispunctuation(a)) |
555 |
|
- |
push!(ret.args, Expr(a)) |
556 |
|
- |
end |
557 |
|
- |
end |
558 |
|
- |
return ret |
559 |
|
- |
elseif typof(x) === Import |
560 |
|
- |
return expr_import(x, :import) |
561 |
|
- |
elseif typof(x) === Using |
562 |
|
- |
return expr_import(x, :using) |
563 |
|
- |
elseif typof(x) === Export |
564 |
|
- |
ret = Expr(:export) |
565 |
|
- |
for i = 2:length(x.args) |
566 |
|
- |
a = x.args[i] |
567 |
|
- |
if !(ispunctuation(a)) |
568 |
|
- |
push!(ret.args, Expr(a)) |
569 |
|
- |
end |
570 |
|
- |
end |
571 |
|
- |
return ret |
572 |
|
- |
elseif typof(x) === FileH |
573 |
|
- |
ret = Expr(:file) |
574 |
|
- |
for a in x.args |
575 |
|
- |
push!(ret.args, Expr(a)) |
576 |
|
- |
end |
577 |
|
- |
return ret |
578 |
|
- |
elseif typof(x) === StringH |
579 |
|
- |
ret = Expr(:string) |
580 |
|
- |
for (i, a) in enumerate(x.args) |
581 |
|
- |
if isunarycall(a) |
582 |
|
- |
a = a.args[2] |
583 |
|
- |
elseif isliteral(a) && kindof(a) === Tokens.STRING && span(a) == 0 || ((i == 1 || i == length(x.args)) && span(a) == 1) || (valof(a) === nothing || isempty(valof(a))) |
584 |
|
- |
continue |
585 |
|
- |
else isliteral(a) && kindof(a) === Tokens.TRIPLE_STRING && span(a) == 0 || ((i == 1 || i == length(x.args)) && span(a) == 3) || (valof(a) === nothing || isempty(valof(a))) |
586 |
|
- |
end |
587 |
|
- |
push!(ret.args, Expr(a)) |
588 |
|
- |
end |
589 |
|
- |
return ret |
|
158 |
+ |
Symbol("@cmd") |
|
159 |
+ |
end |
|
160 |
+ |
elseif x.head === :macrocall && is_getfield_w_quotenode(x.args[1]) && !ismacroname(x.args[1].args[2].args[1]) |
|
161 |
+ |
# Shift '@' to the right |
|
162 |
+ |
new_name = Expr(:., remove_at(x.args[1].args[1]), QuoteNode(Symbol("@", valof(x.args[1].args[2].args[1])))) |
|
163 |
+ |
Expr(:macrocall, new_name, Expr.(x.args[2:end])...) |
|
164 |
+ |
elseif x.head === :macrocall && isidentifier(x.args[1]) && valof(x.args[1]) == "@." |
|
165 |
+ |
Expr(:macrocall, Symbol("@__dot__"), Expr.(x.args[2:end])...) |
|
166 |
+ |
elseif x.head === :string && length(x.args) > 0 && (x.args[1].head === :STRING || x.args[1].head === :TRIPLESTRING) && isempty(valof(x.args[1])) |
|
167 |
+ |
# 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. |
|
168 |
+ |
Expr(:string, Expr.(x.args[2:end])...) |
|
169 |
+ |
elseif x.args === nothing |
|
170 |
+ |
Expr(Symbol(lowercase(String(x.head)))) |
590 |
171 |
|
else |
591 |
|
- |
ret = Expr(:call) |
592 |
|
- |
for a in x.args |
593 |
|
- |
if !(ispunctuation(a)) |
594 |
|
- |
push!(ret.args, Expr(a)) |
595 |
|
- |
end |
596 |
|
- |
end |
597 |
|
- |
return ret |
|
172 |
+ |
Expr(Symbol(lowercase(String(x.head))), Expr.(x.args)...) |
598 |
173 |
|
end |
599 |
174 |
|
end |
600 |
175 |
|
|
601 |
|
- |
# Op. expressions |
602 |
|
- |
|
603 |
|
- |
function _unary_expr(x) |
604 |
|
- |
if isoperator(x.args[1]) && issyntaxunarycall(x.args[1]) |
605 |
|
- |
Expr(Expr(x.args[1]), Expr(x.args[2])) |
606 |
|
- |
elseif isoperator(x.args[2]) && issyntaxunarycall(x.args[2]) |
607 |
|
- |
Expr(Expr(x.args[2]), Expr(x.args[1])) |
|
176 |
+ |
function remove_at(x) |
|
177 |
+ |
if isidentifier(x) && valof(x) !== nothing && first(valof(x)) == '@' |
|
178 |
+ |
return Symbol(valof(x)[2:end]) |
|
179 |
+ |
elseif is_getfield_w_quotenode(x) |
|
180 |
+ |
Expr(:., remove_at(x.args[1]), QuoteNode(remove_at(x.args[2].args[1]))) |
608 |
181 |
|
else |
609 |
|
- |
Expr(:call, Expr(x.args[1]), Expr(x.args[2])) |
610 |
|
- |
end |
611 |
|
- |
end |
612 |
|
- |
function _binary_expr(x) |
613 |
|
- |
if issyntaxcall(x.args[2]) && !(kindof(x.args[2]) in (Tokens.COLON,)) |
614 |
|
- |
if kindof(x.args[2]) === Tokens.DOT |
615 |
|
- |
arg1, arg2 = Expr(x.args[1]), Expr(x.args[3]) |
616 |
|
- |
if arg2 isa Expr && arg2.head === :macrocall && endswith(string(arg2.args[1]), "_cmd") |
617 |
|
- |
return Expr(:macrocall, Expr(:., arg1, QuoteNode(arg2.args[1])), nothing, arg2.args[3]) |
618 |
|
- |
elseif arg2 isa Expr && arg2.head === :braces |
619 |
|
- |
return Expr(:., arg1, Expr(:quote, arg2)) |
620 |
|
- |
end |
621 |
|
- |
end |
622 |
|
- |
Expr(Expr(x.args[2]), Expr(x.args[1]), Expr(x.args[3])) |
623 |
|
- |
else |
624 |
|
- |
Expr(:call, Expr(x.args[2]), Expr(x.args[1]), Expr(x.args[3])) |
|
182 |
+ |
Expr(x) |
625 |
183 |
|
end |
626 |
184 |
|
end |
627 |
185 |
|
|
628 |
|
- |
function _where_expr(x) |
629 |
|
- |
ret = Expr(:where, Expr(x.args[1])) |
630 |
|
- |
for i = 3:length(x.args) |
631 |
|
- |
a = x.args[i] |
632 |
|
- |
if typof(a) === Parameters |
633 |
|
- |
insert!(ret.args, 2, Expr(a)) |
634 |
|
- |
elseif !(ispunctuation(a) || iskw(a)) |
635 |
|
- |
push!(ret.args, Expr(a)) |
636 |
|
- |
end |
637 |
|
- |
end |
638 |
|
- |
return ret |
639 |
|
- |
end |
640 |
|
- |
|
641 |
|
- |
|
642 |
186 |
|
# cross compatability for line number insertion in macrocalls |
643 |
187 |
|
if VERSION > v"1.1-" |
644 |
188 |
|
Expr_cmd(x) = Expr(:macrocall, GlobalRef(Core, Symbol("@cmd")), nothing, valof(x)) |