On this page:
unquote_  bind
unquote_  bind.macro
unquote_  bind_  meta.unpack_  kind
unquote_  bind_  meta.pack_  invalid
unquote_  bind_  meta.Parsed
unquote_  bind_  meta.After  Prefix  Parsed
unquote_  bind_  meta.After  Infix  Parsed
9.0

4.7 Unquote Binding Macros🔗ℹ

Unquote binding forms are similar to normal binding forms, but they appear only under $ within a syntax binding pattern. Unquote binding forms are distinct from normal binding forms because they must match syntax objects; some operators work in both contexts but have different meanings, such as :: and _ for unquote bindings versus :: and _ for normal bindings.

The space for bindings of identifiers and operator that implement $ escape patterns.

definition

unquote_bind.macro macro_patterns

 

more_options

 = 

~kind id

 | 

~kind: id

Like expr.macro, but for binding an identifier or operator that works within a $ escape for a syntax pattern. The macro is bound in the unquote_bind space.

In addition to the option forms supported by expr.macro, unquote_bind.macro supports a ~kind option, which declares an identifier be bound to context-kind information:

  • #'term: A context that needs a matcher for terms or spliced sequences.

  • #'grouplet: A context where the Group syntax class could be used to match a nonempty term sequence.

  • #'group: A context to match a whole group, which is like #'grouplet, but where an identifier defaults to the Group syntax class instead of Term.

  • #'multi: A context to match a sequence of groups.

  • #'block: A context to match a sequence of groups within a block.

These context are tried last to first for possibilities that apply at the use site of an unquote binding form. If an unquote binding form is not compatible with the given context, it can return unquote_bind_meta.pack_invalid to have the next possibility tried.

> unquote_bind.macro 'dots':

    '«'$('...')'»'

> match Syntax.make_group(['...', '...', '...'])

  | '$dots ...': "all dots"

"all dots"

> syntax_class Wrapped

  | '($content)'

  | '[$content]'

  | '{$content}'

> unquote_bind.macro 'wrapped $(id :: Identifier)':

    '_ :: Wrapped: content as $id'

> match '{x} [y] (z)'

  | '$(wrapped a) ...': [a, ...]

['x', 'y', 'z']

function

fun unquote_bind_meta.unpack_kind(stx :: Term)

  :: One.of(#false, #'term, #'grouplet, #'group, #'multi, #'block, #'id)

 

function

fun unquote_bind_meta.pack_invalid() :: Term

Provided as meta.

The annot_meta.unpack_kind function takes a parsed unquote binding form and reports the kind of context that it was parsed for. A #false result indicates that parsing in a given context was unsuccessful. A #'id result indicates that stx can adapt to any context, like an identifier can.

The unquote_bind_meta.pack_invalid function returns a syntax object that represents a failure of an unquote binding form for a particular context. This kind of failure normally triggers a retry in a narrower kind of context.

syntax class

syntax_class unquote_bind_meta.Parsed(

  kind :: One.of(#'term, #'grouplet, #'group, #'multi, #'block)

):

  kind: ~group

  fields:

    group

 

syntax class

syntax_class unquote_bind_meta.AfterPrefixParsed(

  op_name :: Name,

  kind :: One.of(#'term, #'grouplet, #'group, #'multi, #'block)

):

  kind: ~group

  fields:

    group

    [tail, ...]

 

syntax class

syntax_class unquote_bind_meta.AfterInfixParsed(

  op_name :: Name,

  kind :: One.of(#'term, #'grouplet, #'group, #'multi, #'block)

):

  kind: ~group

  fields:

    group

    [tail, ...]

Provided as meta.

Analogous to expr_meta.Parsed, etc., but for unquote bindings.

Unlike expr_meta.Parsed, a kind argument specifies the kind of context for the escape as described in unquote_bind.macro.