This module defines the set of predefined macros. It is &use
d by default.
This module contains some functions to help writing macros
Macro to mark an element as deprecated.
Can be used as a toplevel macro decorator. For instance, to mark a function as deprecated:
@deprecated
function foo = |a, b| -> a + b
Moreover, some additional informations can be provided. They are used to modify the element documentation.
@deprecated(since="3.4", comment="Use `gololang.Functions::add` instead")
function foo = |a, b| -> a + b
since
: the version since the element is deprecatedcomment
: a comment explaining the reasons of the deprecation or the element to use insteadDon't try to expand regular calls as macros.
This special macro configure the expansion process to not be tried on regular
function invocations. Only explicit macro calls (prefixed with &
) are
expanded.
Don't expand the result of a macro.
This special macro configure the expansion process to not expand the macros contained in the result of a macro expansion. This can be useful for debugging, to diagnose intermediary steps.
Adds metadata to an element.
The metadata can be used by another macro, for instance to conditionally deal with the marked element.
The metadata value must be a value convertible by
gololang.macros.Utils::getLiteralValue
This macro is called with named parameters for metadata followed with the element to annotate, as in:
@meta(foo="bar", answer=42)
function example = -> null
It is similar to withMetadata
, but with a more convenient syntax, and allows to add several
metadata at once.
key=value
sequenceelement
: the element to which add the metadataSee also withMetadata
Define the recursion limit for macro expansion in the current module.
This setting only takes effect for macros following it.
Adds a module in the macro resolution scope.
Modules added with this special macro are used for macro resolution, but are not imported. They does not appear in the compiled code, and are not used for regular function invocation resolutions.
Moreover, if the used module has a macro named init
, a call to this macro,
using the additional parameters of use
, is injected into the module.
For instance:
module Test
&use("my.macros", "answer", 42)
configures the visitor to lookup macros in the my.macros
module, and expands
to
module Test
&my.macros.init("answer", 42)
The init
macro may be contextual, to further modify the calling module.
visitor
: the MacroExpansionIrVisitor
used to expand this macro (injected)mod
: the name of the module to use as a string, or a class literal.args
: additional arguments that will be passed to init
init
if the macro exists, null
otherwise.Use old-style destructuring for the current module.
This macro customize the behavior of the destructuring feature by forcing the use of the destruct
method instead of
_$$_destruct
.
This is a toplevel macro.
Adds metadata to an element.
The metadata can be used by another macro, for instance to conditionally deal with the marked element.
The metadata value must be a value convertible by
gololang.macros.Utils::getLiteralValue
This macro is similar to meta
, but allows to use a key with a name not allowed by the named parameter
syntax (for instance "foo.bar Bz"
.
key
: the metadata key (as a String)value
: the metadata valueelement
: the element to which add the metadataSee also meta