@@ -495,10 +495,6 @@ const prec_decl = operator_precedence(:(::))
495
495
is_expr (ex, head:: Symbol ) = (isa (ex, Expr) && (ex. head == head))
496
496
is_expr (ex, head:: Symbol , n:: Int ) = is_expr (ex, head) && length (ex. args) == n
497
497
498
- is_linenumber (ex:: LineNumberNode ) = true
499
- is_linenumber (ex:: Expr ) = (ex. head == :line )
500
- is_linenumber (ex) = false
501
-
502
498
is_quoted (ex) = false
503
499
is_quoted (ex:: QuoteNode ) = true
504
500
is_quoted (ex:: Expr ) = is_expr (ex, :quote , 1 ) || is_expr (ex, :inert , 1 )
@@ -528,18 +524,22 @@ end
528
524
529
525
emphasize (io, str:: AbstractString ) = have_color ? print_with_color (Base. error_color (), io, str; bold = true ) : print (io, uppercase (str))
530
526
531
- show_linenumber (io:: IO , line) = print (io," # line " ,line,' :' )
532
- show_linenumber (io:: IO , line, file) = print (io," # " , file," , line " ,line,' :' )
527
+ show_linenumber (io:: IO , line) = print (io, " #= line " , line, " =#" )
528
+ show_linenumber (io:: IO , line, file) = print (io, " #= " , file, " :" , line, " =#" )
529
+ show_linenumber (io:: IO , line, file:: Void ) = show_linenumber (io, line)
533
530
534
531
# show a block, e g if/for/etc
535
532
function show_block (io:: IO , head, args:: Vector , body, indent:: Int )
536
- print (io, head, ' ' )
537
- show_list (io, args, " , " , indent)
533
+ print (io, head)
534
+ if ! isempty (args)
535
+ print (io, ' ' )
536
+ show_list (io, args, " , " , indent)
537
+ end
538
538
539
539
ind = head === :module || head === :baremodule ? indent : indent + indent_width
540
540
exs = (is_expr (body, :block ) || is_expr (body, :body )) ? body. args : Any[body]
541
541
for ex in exs
542
- if ! is_linenumber (ex); print (io, ' \n ' , " " ^ ind); end
542
+ print (io, ' \n ' , " " ^ ind)
543
543
show_unquoted (io, ex, ind, - 1 )
544
544
end
545
545
print (io, ' \n ' , " " ^ indent)
556
556
# show an indented list
557
557
function show_list (io:: IO , items, sep, indent:: Int , prec:: Int = 0 , enclose_operators:: Bool = false )
558
558
n = length (items)
559
- if n == 0 ; return end
559
+ n == 0 && return
560
560
indent += indent_width
561
561
first = true
562
562
for item in items
603
603
# # AST printing ##
604
604
605
605
show_unquoted (io:: IO , sym:: Symbol , :: Int , :: Int ) = print (io, sym)
606
- show_unquoted (io:: IO , ex:: LineNumberNode , :: Int , :: Int ) = show_linenumber (io, ex. line)
606
+ show_unquoted (io:: IO , ex:: LineNumberNode , :: Int , :: Int ) = show_linenumber (io, ex. line, ex . file )
607
607
show_unquoted (io:: IO , ex:: LabelNode , :: Int , :: Int ) = print (io, ex. label, " : " )
608
608
show_unquoted (io:: IO , ex:: GotoNode , :: Int , :: Int ) = print (io, " goto " , ex. label)
609
609
show_unquoted (io:: IO , ex:: GlobalRef , :: Int , :: Int ) = print (io, ex. mod, ' .' , ex. name)
@@ -903,12 +903,20 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int)
903
903
print (io, head, ' ' )
904
904
show_list (io, args, " , " , indent)
905
905
906
- elseif head === :macrocall && nargs >= 1
906
+ elseif head === :macrocall && nargs >= 2
907
+ # first show the line number argument as a comment
908
+ if isa (args[2 ], LineNumberNode) || is_expr (args[2 ], :line )
909
+ print (io, args[2 ], ' ' )
910
+ end
907
911
# Use the functional syntax unless specifically designated with prec=-1
912
+ # and hide the line number argument from the argument list
908
913
if prec >= 0
909
- show_call (io, :call , ex . args[1 ], ex . args[2 : end ], indent)
914
+ show_call (io, :call , args[1 ], args[3 : end ], indent)
910
915
else
911
- show_list (io, args, ' ' , indent)
916
+ show_args = Vector {Any} (length (args) - 1 )
917
+ show_args[1 ] = args[1 ]
918
+ show_args[2 : end ] = args[3 : end ]
919
+ show_list (io, show_args, ' ' , indent)
912
920
end
913
921
914
922
elseif head === :line && 1 <= nargs <= 2
0 commit comments