Skip to content

Commit

Permalink
simplify bracket lowering macros
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyhffong committed Nov 16, 2014
1 parent 6478f30 commit 8328b55
Showing 1 changed file with 6 additions and 30 deletions.
36 changes: 6 additions & 30 deletions base/brackets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,17 @@

@doc "`⟪ args... ⟫` becomes `enclose_Angle( args... )`" ->
macro enclose_Angle(args...)
ex = Expr( :call, :enclose_Angle )
for c in args
push!( ex.args, c )
end
esc(ex)
esc( Expr( :call, :enclose_Angle, args... ) )
end

@doc "`{| args... |}` becomes `enclose_Brace( args... )`" ->
macro enclose_Brace(args...)
ex = Expr( :call, :enclose_Brace )
for c in args
push!( ex.args, c )
end
esc(ex)
esc( Expr( :call, :enclose_Brace, args... ) )
end

@doc "`[| args... |]` becomes `enclose_Brack( args... )`" ->
macro enclose_Brack(args...)
ex = Expr( :call, :enclose_Brack )
for c in args
push!( ex.args, c )
end
esc(ex)
esc( Expr( :call, :enclose_Brack, args... ) )
end

@doc """
Expand All @@ -35,11 +23,7 @@ end
In practice, the type of foobar usually drives the dispatch.
"""->
macro call_Angle(sym, args...)
ex = Expr( :call, :call_Angle, sym )
for c in args
push!( ex.args, c )
end
esc(ex)
esc( Expr( :call, :call_Angle, sym, args... ) )
end

@doc """
Expand All @@ -62,11 +46,7 @@ Also, we can pass an Expr as the 1st argument as well:
""" ->
macro call_Brace(sym, args...)
ex = Expr( :call, :call_Brace, QuoteNode( sym ) )
for c in args
push!( ex.args, c )
end
esc(ex)
esc( Expr( :call, :call_Brace, Expr( :quote, sym ), args... ) )
end

@doc """
Expand All @@ -77,11 +57,7 @@ end
In practice, the type of foobar usually drives the dispatch.
"""->
macro call_Brack(sym, args...)
ex = Expr( :call, :call_Brack, sym )
for c in args
push!( ex.args, c )
end
esc(ex)
esc( Expr( :call, :call_Brack, sym, args... ) )
end

enclose_Angle( args... ) = throw(ArgumentError( "Undefined enclose_Angle for " * string(args) ) )
Expand Down

0 comments on commit 8328b55

Please sign in to comment.