ExproniconLite.no_default
— Constantconst no_default = NoDefault()
Constant instance for NoDefault
that describes a field should have no default value.
ExproniconLite.JLExpr
— Typeabstract type JLExpr end
Abstract type for Julia syntax type.
ExproniconLite.JLField
— Typemutable struct JLField <: JLExpr
JLField(;kw...)
Type describes a Julia field in a Julia struct.
Fields and Keyword Arguments
All the following fields are valid as keyword arguments kw
in the constructor, and can be access via <object>.<field>
.
The only required keyword argument for the constructor is name
, the rest are all optional.
name::Symbol
: the name of the field.type
: the type of the field.isconst
: if the field is annotated withconst
.line::LineNumberNode
: aLineNumberNode
to indicate the line information.doc::String
: the docstring of this definition.
ExproniconLite.JLFor
— TypeJLFor <: JLExpr
Syntax type for Julia for loop.
ExproniconLite.JLFor
— MethodJLFor(kernel, iterators::Vector)
Convenient constructor for creating multiple loop expression from a list of iterators.
Example
julia> JLFor([:it1, :it2, :it3]) do i, j, k
:(kernel_function_call($i, $j, $k))
end
for ##i#291 = it1, ##i#292 = it2, ##i#293 = it3
kernel_function_call(##i#291, ##i#292, ##i#293)
end
ExproniconLite.JLFor
— MethodJLFor(ex::Expr)
Create a JLFor
from given Julia for loop expression.
Example
julia> ex = @expr for i in 1:10, j in 1:j
M[i, j] += 1
end
:(for i = 1:10, j = 1:j
#= REPL[3]:2 =#
M[i, j] += 1
end)
julia> jl = JLFor(ex)
for i in 1 : 10,
j in 1 : j
#= loop body =#
begin
#= REPL[3]:2 =#
M[i, j] += 1
end
end
julia> jl.vars
2-element Vector{Any}:
:i
:j
julia> jl.iterators
2-element Vector{Any}:
:(1:10)
:(1:j)
ExproniconLite.JLFor
— MethodJLFor(;vars=[], iterators=[], kernel=nothing)
Generate a JLFor
object.
Kwargs
vars
: loop variables.iterators
: loop iterators.kernel
: loop kernel.
ExproniconLite.JLFunction
— Typemutable struct JLFunction <: JLExpr
JLFunction(;kw...)
Type describes a Julia function declaration expression.
Fields and Keyword Arguments
All the following fields are valid as keyword arguments kw
in the constructor, and can be access via <object>.<field>
.
The only required keyword argument for the constructor is name
, the rest are all optional.
head
: optional, function head, can be:function
,:(=)
or:(->)
.name
: optional, function name, can has typeNothing
,Symbol
orExpr
, default isnothing
.args
: optional, function arguments, a list ofExpr
orSymbol
.kwargs
: optional, function keyword arguments, a list ofExpr(:kw, name, default)
.rettype
: optional, the explicit return type of a function, can be aType
,Symbol
,Expr
or justnothing
, default isnothing
.generated
: optional, if this is a generated function.whereparams
: optional, type variables, can be a list ofType
,Expr
ornothing
, default isnothing
.body
: optional, function body, anExpr
, default isExpr(:block)
.line::LineNumberNode
: aLineNumberNode
to indicate the line information.doc::String
: the docstring of this definition.
Example
Construct a function expression
julia> JLFunction(;name=:foo, args=[:(x::T)], body= quote 1+1 end, head=:function, whereparams=[:T])
function foo(x::T) where {T}
#= REPL[25]:1 =#
1 + 1
end
Decompose a function expression
julia> ex = :(function foo(x::T) where {T}
#= REPL[25]:1 =#
1 + 1
end)
:(function foo(x::T) where T
#= REPL[26]:1 =#
#= REPL[26]:3 =#
1 + 1
end)
julia> jl = JLFunction(ex)
function foo(x::T) where {T}
#= REPL[26]:1 =#
#= REPL[26]:3 =#
1 + 1
end
Generate Expr
from JLFunction
julia> codegen_ast(jl)
:(function foo(x::T) where T
#= REPL[26]:1 =#
#= REPL[26]:3 =#
1 + 1
end)
ExproniconLite.JLFunction
— MethodJLFunction(ex::Expr)
Create a JLFunction
object from a Julia function Expr
.
Example
julia> JLFunction(:(f(x) = 2))
f(x) = begin
#= REPL[37]:1 =#
2
end
ExproniconLite.JLIfElse
— TypeJLIfElse <: JLExpr
JLIfElse(;kw...)
JLIfElse
describes a Julia if ... elseif ... else ... end
expression. It allows one to easily construct such expression by inserting condition and code block via a map.
Fields and Keyword Arguments
All the following fields are valid as keyword arguments kw
in the constructor, and can be access via <object>.<field>
.
conds::Vector{Any}
: expression for the conditions.stmts::Vector{Any}
: expression for the statements for corresponding condition.otherwise
: theelse
body.
Example
Construct JLIfElse object
One can construct an ifelse
as following
julia> jl = JLIfElse()
nothing
julia> jl[:(foo(x))] = :(x = 1 + 1)
:(x = 1 + 1)
julia> jl[:(goo(x))] = :(y = 1 + 2)
:(y = 1 + 2)
julia> jl.otherwise = :(error("abc"))
:(error("abc"))
julia> jl
if foo(x)
x = 1 + 1
elseif goo(x)
y = 1 + 2
else
error("abc")
end
Generate the Julia Expr
object
to generate the corresponding Expr
object, one can call codegen_ast
.
julia> codegen_ast(jl)
:(if foo(x)
x = 1 + 1
elseif goo(x)
y = 1 + 2
else
error("abc")
end)
ExproniconLite.JLIfElse
— MethodJLIfElse(ex::Expr)
Create a JLIfElse
from given Julia ifelse Expr
.
Example
julia> ex = :(if foo(x)
x = 1 + 1
elseif goo(x)
y = 1 + 2
else
error("abc")
end)
:(if foo(x)
#= REPL[41]:2 =#
x = 1 + 1
elseif #= REPL[41]:3 =# goo(x)
#= REPL[41]:4 =#
y = 1 + 2
else
#= REPL[41]:6 =#
error("abc")
end)
julia> JLIfElse(ex)
if foo(x)
begin
#= REPL[41]:2 =#
x = 1 + 1
end
elseif begin
#= REPL[41]:3 =#
goo(x)
end
begin
#= REPL[41]:4 =#
y = 1 + 2
end
else
begin
#= REPL[41]:6 =#
error("abc")
end
end
ExproniconLite.JLKwField
— Typemutable struct JLKwField <: JLExpr
Type describes a Julia field that can have a default value in a Julia struct.
JLKwField(;kw...)
Create a JLKwField
instance.
Fields and Keyword Arguments
All the following fields are valid as keyword arguments kw
in the constructor, and can be access via <object>.<field>
.
The only required keyword argument for the constructor is name
, the rest are all optional.
name::Symbol
: the name of the field.type
: the type of the field.isconst
: if the field is annotated withconst
.default
: default value of the field, default isno_default
.line::LineNumberNode
: aLineNumberNode
to indicate the line information.doc::String
: the docstring of this definition.
ExproniconLite.JLKwStruct
— TypeJLKwStruct(ex::Expr, typealias=nothing)
Create a JLKwStruct
from given Julia struct Expr
, with an option to attach an alias to this type name.
Example
julia> JLKwStruct(:(struct Foo
x::Int = 1
end))
#= kw =# struct Foo
#= REPL[39]:2 =#
x::Int = 1
end
ExproniconLite.JLKwStruct
— Typemutable struct JLKwStruct <: JLExpr
JLKwStruct(;kw...)
Type describes a Julia struct that allows keyword definition of defaults. This syntax is similar to JLStruct
except the the fields are of type JLKwField
.
Fields and Keyword Arguments
All the following fields are valid as keyword arguments kw
in the constructor, and can be access via <object>.<field>
.
The only required keyword argument for the constructor is name
, the rest are all optional.
name::Symbol
: name of the struct, this is the only required keyword argument.typealias::String
: an alias of theJLKwStruct
, see also the@option
macro in Configurations.jl.ismutable::Bool
: if the struct definition is mutable.typevars::Vector{Any}
: type variables of the struct, should beSymbol
orExpr
.supertype
: supertype of the struct definition.fields::Vector{JLField}
: field definitions of the struct, should be aJLField
.constructors::Vector{JLFunction}
: constructors definitions of the struct, should beJLFunction
.line::LineNumberNode
: aLineNumberNode
to indicate the definition position for error report etc.doc::String
: documentation string of the struct.misc
: other things that happens inside the struct body, by definition this will just fall through and is equivalent to eval them outside the struct body.
ExproniconLite.JLStruct
— Typemutable struct JLStruct <: JLExpr
Type describes a Julia struct.
JLStruct(;kw...)
Create a JLStruct
instance.
Available Fields and Keyword Arguments
All the following fields are valid as keyword arguments kw
in the constructor, and can be access via <object>.<field>
.
The only required keyword argument for the constructor is name
, the rest are all optional.
name::Symbol
: name of the struct, this is the only required keyword argument.ismutable::Bool
: if the struct definition is mutable.typevars::Vector{Any}
: type variables of the struct, should beSymbol
orExpr
.supertype
: supertype of the struct definition.fields::Vector{JLField}
: field definitions of the struct, should be aJLField
.constructors::Vector{JLFunction}
: constructors definitions of the struct, should beJLFunction
.line::LineNumberNode
: aLineNumberNode
to indicate the definition position for error report etc.doc::String
: documentation string of the struct.misc
: other things that happens inside the struct body, by definition this will just fall through and is equivalent to eval them outside the struct body.
Example
Construct a Julia struct.
julia> JLStruct(;name=:Foo, typevars=[:T], fields=[JLField(;name=:x, type=Int)])
struct Foo{T}
x::Int64
end
Decompose a Julia struct expression
julia> ex = :(struct Foo{T}
x::Int64
end)
:(struct Foo{T}
#= REPL[31]:2 =#
x::Int64
end)
julia> jl = JLStruct(ex)
struct Foo{T}
#= REPL[31]:2 =#
x::Int64
end
Generate a Julia struct expression
julia> codegen_ast(jl)
:(struct Foo{T}
#= REPL[31]:2 =#
x::Int64
end)
ExproniconLite.JLStruct
— MethodJLStruct(ex::Expr)
Create a JLStruct
object from a Julia struct Expr
.
Example
julia> JLStruct(:(struct Foo
x::Int
end))
struct Foo
#= REPL[38]:2 =#
x::Int
end
ExproniconLite.NoDefault
— TypeNoDefault
Type describes a field should have no default value.
ExproniconLite.Substitute
— TypeSubstitute(condition) -> substitute(f(expr), expr)
Returns a function that substitutes expr
with f(expr)
if condition(expr)
is true. Applied recursively to all sub-expressions.
Example
julia> sub = Substitute() do expr
expr isa Symbol && expr in [:x] && return true
return false
end;
julia> sub(_->1, :(x + y))
:(1 + y)
ExproniconLite.Variable
— Typestruct Variable
Marks a Symbol
as a variable. So that compare_expr
will always return true
.
ExproniconLite.alias_gensym
— MethodExproniconLite.annotations_only
— Methodannotations_only(ex)
Return type annotations only. See also name_only
.
ExproniconLite.assert_equal_expr
— Methodassert_equal_expr(m::Module, lhs, rhs)
Assert that lhs
and rhs
are equal in m
. Throw an ExprNotEqual
if they are not equal.
ExproniconLite.canonicalize_lambda_head
— Methodcanonicalize_lambda_head(ex)
Canonicalize the Expr(:function, Expr(:block, x, Expr(:(=), key, default)), body)
to
Expr(:function, Expr(:tuple, Expr(:parameters, Expr(:kw, key, default)), x), body)
ExproniconLite.codegen_ast
— Methodcodegen_ast(def)
Generate Julia AST object Expr
from a given syntax type.
Example
One can generate the Julia AST object from a JLKwStruct
syntax type.
julia> def = @expr JLKwStruct struct Foo{N, T}
x::T = 1
end
#= kw =# struct Foo{N, T}
#= REPL[19]:2 =#
x::T = 1
end
julia> codegen_ast(def)|>rm_lineinfo
quote
struct Foo{N, T}
x::T
end
begin
function Foo{N, T}(; x = 1) where {N, T}
Foo{N, T}(x)
end
function Foo{N}(; x::T = 1) where {N, T}
Foo{N, T}(x)
end
end
end
ExproniconLite.codegen_ast_fields
— Methodcodegen_ast_fields(fields; just_name::Bool=true)
Generate a list of Julia AST object for each field, only generate a list of field names by default, option just_name
can be turned off to call codegen_ast
on each field object.
ExproniconLite.codegen_ast_kwfn
— Functioncodegen_ast_kwfn(def[, name = nothing])
Generate the keyword function from a Julia struct definition.
Example
julia> def = @expr JLKwStruct struct Foo{N, T}
x::T = 1
end
#= kw =# struct Foo{N, T}
#= REPL[19]:2 =#
x::T = 1
end
julia> codegen_ast_kwfn(def)|>prettify
quote
function Foo{N, T}(; x = 1) where {N, T}
Foo{N, T}(x)
end
function Foo{N}(; x::T = 1) where {N, T}
Foo{N, T}(x)
end
end
julia> def = @expr JLKwStruct struct Foo
x::Int = 1
end
#= kw =# struct Foo
#= REPL[23]:2 =#
x::Int = 1
end
julia> codegen_ast_kwfn(def)|>prettify
quote
function Foo(; x = 1)
Foo(x)
end
nothing
end
ExproniconLite.codegen_ast_kwfn_infer
— Functioncodegen_ast_kwfn_infer(def, name = nothing)
Generate the keyword function that infers the type.
ExproniconLite.codegen_ast_kwfn_plain
— Functioncodegen_ast_kwfn_plain(def[, name = nothing])
Generate the plain keyword function that does not infer type variables. So that one can use the type conversions defined by constructors.
ExproniconLite.codegen_ast_struct
— Methodcodegen_ast_struct(def)
Generate pure Julia struct Expr
from struct definition. This is equivalent to codegen_ast
for JLStruct
. See also codegen_ast
.
Example
julia> def = JLKwStruct(:(struct Foo
x::Int=1
Foo(x::Int) = new(x)
end))
struct Foo
x::Int = 1
end
julia> codegen_ast_struct(def)
:(struct Foo
#= REPL[21]:2 =#
x::Int
Foo(x::Int) = begin
#= REPL[21]:4 =#
new(x)
end
end)
ExproniconLite.codegen_ast_struct_body
— Methodcodegen_ast_struct_body(def)
Generate the struct body.
Example
julia> def = JLStruct(:(struct Foo
x::Int
Foo(x::Int) = new(x)
end))
struct Foo
x::Int
end
julia> codegen_ast_struct_body(def)
quote
#= REPL[15]:2 =#
x::Int
Foo(x::Int) = begin
#= REPL[15]:4 =#
new(x)
end
end
ExproniconLite.codegen_ast_struct_head
— Methodcodegen_ast_struct_head(def)
Generate the struct head.
Example
julia> using Expronicon
julia> def = JLStruct(:(struct Foo{T} end))
struct Foo{T}
end
julia> codegen_ast_struct_head(def)
:(Foo{T})
julia> def = JLStruct(:(struct Foo{T} <: AbstractArray end))
struct Foo{T} <: AbstractArray
end
julia> codegen_ast_struct_head(def)
:(Foo{T} <: AbstractArray)
ExproniconLite.compare_expr
— Methodcompare_expr([m=Main], lhs, rhs)
Compare two expression of type Expr
or Symbol
semantically, which:
- ignore the detail value
LineNumberNode
in comparision; - ignore the detailed name of typevars declared by
where
; - recognize inserted objects and
Symbol
, e.g:($Int)
is equal to:(Int)
; - recognize
QuoteNode(:x)
andSymbol("x")
as equal; - will guess module and type objects and compare their value directly instead of their expression;
This function is usually combined with prettify
with preserve_last_nothing=true
and alias_gensym=false
.
This gives a way to compare two Julia expression semantically which means although some details of the expression is different but they should produce the same lowered code.
ExproniconLite.eval_interp
— Methodeval_interp(m::Module, ex)
evaluate the interpolation operator in ex
inside given module m
.
ExproniconLite.eval_literal
— Methodeval_literal(m::Module, ex)
Evaluate the literal values and insert them back to the expression. The literal value can be checked via is_literal
.
ExproniconLite.expr_map
— Methodexpr_map(f, c...; skip_nothing::Bool=false)
Similar to Base.map
, but expects f
to return an expression, and will concanate these expression as a Expr(:block, ...)
expression.
Skip nothing
if skip_nothing
is true
.
Example
julia> expr_map(1:10, 2:11) do i,j
:(1 + $i + $j)
end
quote
1 + 1 + 2
1 + 2 + 3
1 + 3 + 4
1 + 4 + 5
1 + 5 + 6
1 + 6 + 7
1 + 7 + 8
1 + 8 + 9
1 + 9 + 10
1 + 10 + 11
end
ExproniconLite.flatten_blocks
— Methodflatten_blocks(ex)
Remove hierachical expression blocks.
ExproniconLite.gensym_name
— MethodExproniconLite.guess_module
— Methodguess_module(m, ex)
Guess the module of given expression ex
(of a module) in module m
. If ex
is not a module, or cannot be determined return nothing
.
ExproniconLite.guess_type
— Methodguess_type(m::Module, ex)
Guess the actual type of expression ex
(of a type) in module m
. Returns the type if it can be determined, otherwise returns the expression. This function is used in compare_expr
.
ExproniconLite.has_kwfn_constructor
— Functionhas_kwfn_constructor(def[, name = struct_name_plain(def)])
Check if the struct definition contains keyword function constructor of name
. The constructor name to check by default is the plain constructor which does not infer any type variables and requires user to input all type variables. See also struct_name_plain
.
ExproniconLite.has_plain_constructor
— Functionhas_plain_constructor(def, name = struct_name_plain(def))
Check if the struct definition contains the plain constructor of name
. By default the name is the inferable name struct_name_plain
.
Example
def = @expr JLKwStruct struct Foo{T, N}
x::Int
y::N
Foo{T, N}(x, y) where {T, N} = new{T, N}(x, y)
end
has_plain_constructor(def) # true
def = @expr JLKwStruct struct Foo{T, N}
x::T
y::N
Foo(x, y) = new{typeof(x), typeof(y)}(x, y)
end
has_plain_constructor(def) # false
the arguments must have no type annotations.
def = @expr JLKwStruct struct Foo{T, N}
x::T
y::N
Foo{T, N}(x::T, y::N) where {T, N} = new{T, N}(x, y)
end
has_plain_constructor(def) # false
ExproniconLite.has_symbol
— Methodhas_symbol(ex, name::Symbol)
Check if ex
contains symbol name
.
ExproniconLite.is_datatype_expr
— Methodis_datatype_expr(ex)
Check if ex
is an expression for a concrete DataType
, e.g where
is not allowed in the expression.
ExproniconLite.is_field
— Methodis_field(ex)
Check if ex
is a valid field expression.
ExproniconLite.is_field_default
— Methodis_field_default(ex)
Check if ex
is a <field expr> = <default expr>
expression.
ExproniconLite.is_for
— Methodis_for(ex)
Check if ex
is a for
loop expression.
ExproniconLite.is_function
— Methodis_function(def)
Check if given object is a function expression.
ExproniconLite.is_gensym
— MethodExproniconLite.is_ifelse
— Methodis_ifelse(ex)
Check if ex
is an if ... elseif ... else ... end
expression.
ExproniconLite.is_kw_function
— Methodis_kw_function(def)
Check if a given function definition supports keyword arguments.
ExproniconLite.is_literal
— Methodis_literal(x)
Check if x
is a literal value.
ExproniconLite.is_matrix_expr
— Methodis_matrix_expr(ex)
Check if ex
is an expression for a Matrix
.
ExproniconLite.is_splat
— Methodis_splat(ex)
Check if ex
is a splat expression, i.e. :(f(x)...)
ExproniconLite.is_struct
— Methodis_struct(ex)
Check if ex
is a struct expression.
ExproniconLite.is_struct_not_kw_struct
— Methodis_struct_not_kw_struct(ex)
Check if ex
is a struct expression excluding keyword struct syntax.
ExproniconLite.is_tuple
— Methodis_tuple(ex)
Check if ex
is a tuple expression, i.e. :((a,b,c))
ExproniconLite.is_valid_typevar
— Methodis_valid_typevar(typevar)
Check if the given typevar is a valid typevar.
This function is based on this discourse post.
ExproniconLite.name_only
— Methodname_only(ex)
Remove everything else leaving just names, currently supports function calls, type with type variables, subtype operator <:
and type annotation ::
.
Example
julia> using Expronicon
julia> name_only(:(sin(2)))
:sin
julia> name_only(:(Foo{Int}))
:Foo
julia> name_only(:(Foo{Int} <: Real))
:Foo
julia> name_only(:(x::Int))
:x
ExproniconLite.nexprs
— Methodnexprs(f, n::Int)
Create n
similar expressions by evaluating f
.
Example
julia> nexprs(5) do k
:(1 + $k)
end
quote
1 + 1
1 + 2
1 + 3
1 + 4
1 + 5
end
ExproniconLite.prettify
— Methodprettify(ex; kw...)
Prettify given expression, remove all LineNumberNode
and extra code blocks.
Options (Kwargs)
All the options are true
by default.
rm_lineinfo
: removeLineNumberNode
.flatten_blocks
: flattenbegin ... end
code blocks.rm_nothing
: removenothing
in thebegin ... end
.preserve_last_nothing
: preserve the lastnothing
in thebegin ... end
.rm_single_block
: remove singlebegin ... end
.alias_gensym
: replace##<name>#<num>
with<name>_<id>
.renumber_gensym
: renumber the gensym id.
the LineNumberNode
inside macro calls won't be removed since the macrocall
expression requires a LineNumberNode
. See also issues/#9.
ExproniconLite.print_expr
— Methodprint_expr([io::IO], ex; kw...)
Print a given expression. ex
can be a Expr
or a syntax type JLExpr
.
ExproniconLite.print_inline
— Methodprint_expr([io::IO], ex; kw...)
Print a given expression within one line. ex
can be a Expr
or a syntax type JLExpr
.
ExproniconLite.renumber_gensym
— Methodrenumber_gensym(ex)
Re-number gensym with counter from this expression. Produce a deterministic gensym name for testing etc. See also: alias_gensym
ExproniconLite.rm_annotations
— Methodrm_annotations(x)
Remove type annotation of given expression.
ExproniconLite.rm_lineinfo
— Methodrm_lineinfo(ex)
Remove LineNumberNode
in a given expression.
the LineNumberNode
inside macro calls won't be removed since the macrocall
expression requires a LineNumberNode
. See also issues/#9.
ExproniconLite.rm_nothing
— Methodrm_nothing(ex)
Remove the constant value nothing
in given expression ex
.
Keyword Arguments
preserve_last_nothing
: iftrue
, the lastnothing
will be preserved.
ExproniconLite.split_anonymous_function_head
— Methodsplit_anonymous_function_head(ex::Expr) -> nothing, args, kw, whereparams, rettype
Split anonymous function head to arguments, keyword arguments and where parameters.
ExproniconLite.split_doc
— Methodsplit_doc(ex::Expr) -> line, doc, expr
Split doc string from given expression.
ExproniconLite.split_field_if_match
— Functionsplit_field_if_match(typename::Symbol, expr, default::Bool=false)
Split the field definition if it matches the given type name. Returns NamedTuple
with name
, type
, default
and isconst
fields if it matches, otherwise return nothing
.
ExproniconLite.split_function
— Methodsplit_function(ex::Expr) -> head, call, body
Split function head declaration with function body.
ExproniconLite.split_function_head
— Methodsplit_function_head(ex::Expr) -> name, args, kw, whereparams, rettype
Split function head to name, arguments, keyword arguments and where parameters.
ExproniconLite.split_struct
— Methodsplit_struct(ex::Expr) -> ismutable, name, typevars, supertype, body
Split struct definition head and body.
ExproniconLite.split_struct_name
— Methodsplit_struct_name(ex::Expr) -> name, typevars, supertype
Split the name, type parameters and supertype definition from struct
declaration head.
ExproniconLite.sprint_expr
— Methodsprint_expr(ex; context=nothing, kw...)
Print given expression to String
, see also print_expr
.
ExproniconLite.struct_name_plain
— Methodstruct_name_plain(def)
Plain constructor name. See also struct_name_without_inferable
.
Example
julia> def = @expr JLKwStruct struct Foo{N, Inferable}
x::Inferable = 1
end
julia> struct_name_plain(def)
:(Foo{N, Inferable})
ExproniconLite.struct_name_without_inferable
— Methodstruct_name_without_inferable(def; leading_inferable::Bool=true)
Constructor name that assume some of the type variables is inferred. See also struct_name_plain
. The kwarg leading_inferable
can be used to configure whether to preserve the leading inferable type variables, the default is true
to be consistent with the default julia constructors.
Example
julia> def = @expr JLKwStruct struct Foo{N, Inferable}
x::Inferable = 1
end
julia> struct_name_without_inferable(def)
:(Foo{N})
julia> def = @expr JLKwStruct struct Foo{Inferable, NotInferable}
x::Inferable
end
julia> struct_name_without_inferable(def; leading_inferable=true)
:(Foo{Inferable, NotInferable})
julia> struct_name_without_inferable(def; leading_inferable=false)
:(Foo{NotInferable})
ExproniconLite.substitute
— Methodsubstitute(ex::Expr, old=>new)
Substitute the old symbol old
with new
.
ExproniconLite.support_default
— Methodsupport_default(f)
Check if field type f
supports default value.
ExproniconLite.uninferrable_typevars
— Methoduninferrable_typevars(def::Union{JLStruct, JLKwStruct}; leading_inferable::Bool=true)
Return the type variables that are not inferrable in given struct definition.
ExproniconLite.xcall
— Methodxcall(name, args...; kw...)
Create a function call to name
.
ExproniconLite.xcall
— Methodxcall(m::Module, name::Symbol, args...; kw...)
Create a function call to GlobalRef(m, name)
.
due to Revise/#616, to make your macro work with Revise, we use the dot expression Expr(:., <module>, QuoteNode(<name>))
instead of GlobalRef
here.
ExproniconLite.xfirst
— Methodxfirst(collection)
Create a function call expression to Base.first
.
ExproniconLite.xgetindex
— Methodxgetindex(collection, key...)
Create a function call expression to Base.getindex
.
ExproniconLite.xiterate
— Methodxiterate(it, st)
Create a function call expression to Base.iterate
.
ExproniconLite.xiterate
— Methodxiterate(it)
Create a function call expression to Base.iterate
.
ExproniconLite.xlast
— Methodxlast(collection)
Create a function call expression to Base.last
.
ExproniconLite.xmap
— Methodxmap(f, xs...)
Create a function call expression to Base.map
.
ExproniconLite.xmapreduce
— Methodxmapreduce(f, op, xs...)
Create a function call expression to Base.mapreduce
.
ExproniconLite.xnamedtuple
— Methodxnamedtuple(;kw...)
Create a NamedTuple
expression.
ExproniconLite.xprint
— Methodxprint(xs...)
Create a function call expression to Base.print
.
ExproniconLite.xprintln
— Methodxprintln(xs...)
Create a function call expression to Base.println
.
ExproniconLite.xpush
— Methodxpush(collection, items...)
Create a function call expression to Base.push!
.
ExproniconLite.xtuple
— Methodxtuple(xs...)
Create a Tuple
expression.
ExproniconLite.@expr
— Macro@expr <type> <expression>
Return the expression in given type.
Example
julia> ex = @expr JLKwStruct struct Foo{N, T}
x::T = 1
end
#= kw =# struct Foo{N, T}
#= /home/roger/code/julia/Expronicon/test/analysis.jl:5 =#
x::T = 1
end
ExproniconLite.@expr
— Macro@expr <expression>
Return the original expression object.
Example
julia> ex = @expr x + 1
:(x + 1)
ExproniconLite.@test_expr
— Macro@test_expr <type> <ex>
Test if the syntax type generates the same expression ex
. Returns the corresponding syntax type instance. Requires using Test
before using this macro.
Example
def = @test_expr JLFunction function (x, y)
return 2
end
@test is_kw_fn(def) == false
ExproniconLite.@test_expr
— Macro@test_expr <expr> == <expr>
Test if two expression is equivalent semantically, this uses compare_expr
to decide if they are equivalent, ignores things such as LineNumberNode
generated Symbol
in Expr(:curly, ...)
or Expr(:where, ...)
.
This macro requires one using Test
to import the Test
module name.