CodeSculptor.ASSIGNMENT_INNER_OP
— ConstantMaps a modifying assignment operator (like *=
) to its underlying operator (like *
)
CodeSculptor.ASSIGNMENT_WITH_OP
— ConstantConverts an operator (like *
) to its assignment operation (like *=
)
CodeSculptor.AbstractSplitExpr
— TypeSome data representation of a particular kind of expression.
- Turn it back into the original expression with
combine_expr(e)
. - Check if the entire split expression is escaped with
is_escaped(e)
(does not check for inner things being escaped). - Make a smart deep-copy (using
expr_deepcopy()
) by constructing another one and passing the original.
When applicable, constructors return nothing
if the expression cannot be split, but less strict interpretation can be requested by passing an extra parameter false
.
CodeSculptor.SplitArg
— TypeA data represenation of an argument declaration, comparable to the output of MacroTools.splitarg()
but handling extra stuff like being wrapped in an esc()
call.
CodeSculptor.SplitFunction
— TypeA data representation of a function definition, or lambda, comparable to MacroTools.splitdef()
but far more thorough.
You can also split/combine a function call, represented by a nothing
body, but must turn off strict mode (pass false
in the constructor) to successfully parse literal-valued parameters. In a generated function call, the only thing that matters in arguments is the name, for example named parameter a
turns into a=a
.
A lambda is represented by a nothing
name. Setting both the body and name to nothing
is not allowed.
CodeSculptor.SplitMacro
— TypeA data representation of a macro invocation, such as @assert x == 5
.
CodeSculptor.SplitMeta
— TypeInformation that sits outside of a definition (especially a function definition). For example @inline
, @generated
, and doc-strings.
CodeSculptor.SplitMeta
— MethodReturns nothing
if the metadata can't be extracted (i.e. it's wrapped by an unexpected macro)
CodeSculptor.SplitType
— TypeA data representation of a type declaration, such as C{R, T<:Integer} <: B
CodeSculptor.combine_expr
— FunctionWhen generating a function call, pass true
for each named arg a=5
to turn into a=a
. Pass false
for each named arg a=5
to turn into a=5
CodeSculptor.combine_expr
— MethodTurns the data representaton of a macro call into an AST
CodeSculptor.compute_op
— MethodComputes one of the modifying assignments (*=
, &=
, etc) given it and its inputs. Also implements =
for completeness.
CodeSculptor.expr_deepcopy
— MethodDeep-copies an expression AST, except for things that should not be copied like literal modules
CodeSculptor.function_wrapping_is_valid
— MethodChecks whether an expression contains valid function metadata (doc-string, @inline
, etc., or several at once, or none of them)
CodeSculptor.is_function_call
— MethodGets whether an expression looks like a function call
CodeSculptor.is_function_decl
— MethodChecks if an expression is a valid function declaration. Note that MacroTools' version of this function is overly permissive.
CodeSculptor.is_scopable_name
— FunctionChecks that an expression is a Symbol, possibly nested within .
operators. For example, Base.empty
.
Optionally allows type parameters at the end of the expression, like :( A.B{C} )
.
CodeSculptor.is_short_function_decl
— MethodChecks if an expression is a short-form function declaration (like f() = 5
). Preferred to MacroTools' version of this function, because that one accepts AST's that are not actually functions.
CodeSculptor.unescape
— MethodUnwraps esc()
from the outside of an expression, if it exists. Also see unescape_deep()
CodeSculptor.unescape_deep
— MethodRemoves esc()
from an entire AST, returning the sanitized copy. Also see unescape()
CodeSculptor.visit_exprs
— MethodWalks through an expression depth-first, invoking your lambda on every sub-expression with the following arguments:
1 .A list of integers representing the path to this sub-expression (for each Expr along the way, the index of its argument)
- A list of the parents to this sub-expression, from the root down to the current expr.
For example, you could pass a lambda of the form (path, exprs) -> let e = exprs[end] ... end
.
Like MacroTools.postwalk
, but without modifying the expression and with more context about where each expression sits in the AST.