On this page:
meta
meta.bridge
8.12

7.1 Meta Definitions and Expressions🔗ℹ

declaration

meta:

  nestable_body

  ...

 

declaration

meta nestable_body

The same as the nestable_body sequence, but shifted to one phase greater. Defintions inside a meta block can be referenced in macro implementations, for example.

Alternatively, meta can have a single nestable_body in a group, in which case it is equivalent to a block with the single nestable_body.

See also the meta import modifier.

> meta:

    syntax_class Arithmetic

    | '$x + $y'

    | '$x - $y'

> expr.macro 'right_operand $(exp :: Arithmetic)':

    exp.y

> right_operand 1 + 2

2

> meta fun add1(x):

    x+1

> expr.macro 'add1_statically $(n :: Int)':

    '#%literal $(add1(Syntax.unwrap(n)))'

> add1_statically 13

14

definition

meta.bridge op_or_id_name:

  body

  ...

Binds op_or_id_name at the enclosing phase, but like a macro, where the body side is a compile-time block at one phase greater than the enclosing phase.

The result of the body block might be a macro transformer that is triggered by a use of op_or_id_name, or it might be some other kind of value that is accessed with syntax_meta.value.

For example, forms like expr.macro, bind.macro, and annot.macro expand to meta.bridge. In those cases, the generated body block produces an expression transformer, binding transformer, or annotation transformer. Some forms that expand to meta.bridge enrich the op_or_id_name with a scope for a space of bindings, which enables overloading a op_or_id_name for different contexts like expressions versus bindings. For example, annot.macro enriches its op_or_id_name with a scope for annotation operators.