MLStyle.Modules.AST

MLStyle.Modules.AST

@matchast

@matchast :(1 + 1) quote
    $a + 1 => a + 2
end

is equivalent to

@match :(1 + 1) begin
    :($a + 1) => a + 2
end

@capture

func_node = :(f(a, b, c))
let_node = :(let a = b; a + b end)
@info :function @capture $fn($(args...)) func_node
@info :let @capture let $a = $b; $(stmts...) end let_node

outputs

┌ Info: function
│   #= REPL[9]:1 =# @capture ($(Expr(:$, :fn)))($(Expr(:$, :(args...)))) func_node =
│    Dict{Symbol,Any} with 2 entries:
│      :args => Any[:a, :b, :c]
└      :fn   => :f

┌ Info: let
│   #= REPL[10]:1 =# @capture let $(Expr(:$, :a)) = $(Expr(:$, :b))
        #= REPL[10]:1 =#
        $(Expr(:$, :(stmts...)))
    end let_node =
│    Dict{Symbol,Any} with 3 entries:
│      :a     => :a
│      :b     => :b
└      :stmts => Any[:(#= REPL[8]:1 =#), :(a + b)]