Std. Syntax
(Cure Standard Library v0.37.2)
View Source
The generic quoted-AST value a Tier-3 computed by elab receives and
returns (macro-facility design §3, generic layer). Reflects the parser's
{tag, meta, third} node: Node for a child list, Leaf for a scalar
third value, Raw for a node the parser produced that doesn't fit the
{tag, meta, third} shape at all (e.g. a bare impossible-body marker
or a non-conforming pattern tuple) -- reflected opaquely rather than
crashing. attrs carries the semantic meta (a function's name, an
operator, a literal's subtype) — dropping it would lose those. A meta
value need not be a plain scalar: SynLit also covers a list of values
(SList), a nested AST (SSyntax), and a lookup table (SMap), each
losslessly. Source positions are not represented (the expansion is
re-elaborated, K3 firewall).
Examples
use Std.Syntax
let expr = call("add", [int_literal(1), variable("x")])
tag(expr) # => :function_call
has_tag(expr, :function_call) # => true
Summary
Types
Shape-specific aliases keep generated family records readable without introducing separate runtime representations or weakening the generic reflection boundary.
Typed declaration specifications keep ordinary macro authors away from positional attribute lists. They are source-level records, so a builder call reads like the declaration it produces and remains reusable by any user-defined macro.
A constructor head extracted from a reflected match arm. The arity is retained in the generic constructor key so source-defined derivations can reject unsupported payload views without compiler-owned domain knowledge.
Functions
Lower an AliasSpec record into a typealias syntax node.
typealias is what the authored surface tags this node with, and the
elaborator's header pre-pass keys off it: only a flagged alias gets a
forward-referenceable header. Emitting the flag is therefore not cosmetic
-- without it a generated alias (Handle, Data in an fsm) is invisible
to any declaration lowered before it, including the enclosing unit's own
declarations, which module lifting inlines ahead of the generated ones.
Construct an AliasSpec record with name and right-hand side value.
Construct an atom (symbol) literal syntax leaf.
Look up attribute key in values, returning Found(value) or Missing.
Return true when attribute key in values is SAtom(expected).
Construct a key-value Attr entry.
Return the attribute list of syntax (unwrapping Quoted, or [] for Raw and Failure).
Construct a :block syntax node containing items.
Construct a boolean literal syntax leaf.
call is part of the compile-time reflection API. Core-evaluator macro
execution must unfold it across the Std.Syntax interface boundary, so its
body is semantic interface data rather than an opaque runtime detail.
Name-intent constructors make scope decisions explicit in macro source.
caller_identifier deliberately retains the call-site scope; the other
two are used for generated references and declaration names respectively.
Extract the parameter name from a reflected :param syntax node, if present.
Convert a reflected parameter node into a typed_pattern, when both name and type are available.
Extract the :type syntax attribute from a reflected parameter node, if present.
Construct a character literal syntax leaf.
Return the child syntax nodes of syntax (empty for Leaf and Raw, [inner] for Quoted).
Collect deduplicated constructor heads from arms, preserving order and failing on invalid arms.
Extract the :constructor_key atom from values, or :invalid_constructor if missing.
Return true when values carries :pascal_case set to true.
Look up one field in the generic staged expansion context.
Derive deduplicated constructor heads from the match arms of a reflected handler body.
Attach user-facing content to an authored diagnostic while keeping its
stable failure name in the outer Failure. Presentation adapters consume
this record uniformly for source-defined macros.
Select a Unicode-scalar-relative range inside syntax captured from the caller. The compiler validates the range against the captured source span; an invalid or generated target falls back to the macro invocation. Macro authors therefore cannot forge a path or escape the captured syntax.
Construct an enum container syntax node named name with variants.
Construct a nullary enum variant syntax leaf named name.
Build a constructor variant with explicitly typed payload fields. The
parser represents enum constructors as function definitions whose params
are type expressions, so this is the same surface form as a user-written
type Message = Ping(Int) declaration.
Wrap a syntax tree as a successful Expanded MacroResult.
Read the generic staged expansion context attached to reflected syntax. A context-free use site is represented by the same opaque value used for any unavailable syntax, so a source-defined macro can inspect it without relying on a compiler-owned callback record.
Construct an exported-scope identifier syntax leaf.
Construct a float literal syntax leaf.
Mark a generated binder or reference for the parser's existing hygienic freshening pass. Use the marker at each generated occurrence that should share a binding; syntax reflected from the caller remains untouched. The marker is compile-time syntax and disappears before ordinary elaboration; it is not a runtime name generator.
Construct a :function_def syntax node with name, params, return_type, and body.
Build a function whose name is derived from reflected identifier syntax. The generic syntax bridge performs the requested Unicode-safe transform while converting the compile-time Syntax value back to parser AST.
Lower a FunctionSpec record into a :function_def syntax node.
Construct a guarded :match_arm syntax node for pattern when guard -> body.
Return the child nodes of a reflected handler body.
Extract the constructor head from a single unguarded :match_arm syntax node.
Return true when key appears in keys.
Return true when syntax has the given tag expected.
Generic identifier transformations for declaration-producing macros. These inspect reflected identifier syntax only; domain macros decide what generated name means (for example, an actor query adapter).
Lift ordinary primitive values into literal syntax. These constructors are explicit so a string can never be mistaken for an identifier or raw syntax.
Construct an integer literal syntax leaf.
Return true when syntax is a :variable node whose :variable_name attribute equals expected.
Construct a Leaf with tag name, attributes values, and scalar value.
Return the scalar SynLit payload of a Leaf, or SOpaque for any other node kind.
Construct an untyped let assignment syntax node binding name to value.
Construct a :lift_module syntax node for module with behaviour and declarations.
Build a lifted unit that inherits enclosing declarations but not the imports used only to define the surrounding macro. Macro authors can use this when the generated unit declares its complete import surface.
Construct a linear ParameterSpec with name and type kind.
Construct a list literal syntax node from items.
Construct an unguarded :match_arm syntax node for pattern -> body.
Lower a ModuleSpec record into a :lift_module syntax node.
Construct a Node with tag name, attributes values, and children terms.
Construct a function parameter syntax node with name and type kind.
Lower a ParameterSpec record into a :param syntax node.
Construct a linearly graded function parameter syntax node with name and type kind.
Encode a list of parameter syntax nodes as an SList of SSyntax literals.
Build a SynLit list of wildcard ("_") binder names with the same length as items.
Construct a non-linear ParameterSpec with name and type kind.
Lower a list of ParameterSpec records into :param syntax nodes.
Extract a closed constructor head from a reflected match arm. A handler whose head cannot determine a nominal constructor is rejected by the caller rather than silently widening the generated message/event type.
Extract derivable payload type expressions from a constructor pattern's argument list.
Construct a hygienically freshened private identifier syntax leaf.
Reject macro expansion with a single Diagnostic.
Reject macro expansion with a list of Diagnostic values.
Reverse a list of collected pattern-head syntax nodes.
Tail-recursive accumulator helper for reverse_heads/1.
Construct a string literal syntax leaf.
Lift an Atom into a SynLit (SAtom).
Lift a Bool into a SynLit (SBool).
Lift an Int into a SynLit (SInt).
Encode a list of Syntax nodes as an SList of SSyntax literals.
Lift a String into a SynLit (SStr).
Small, total operations used by source-defined syntax macros. These keep syntax analysis in Cure instead of teaching the compiler about a macro's domain-specific declarations.
Construct a tuple expression syntax node from items.
Construct a tuple type syntax node with anonymous binders for items.
Construct a type-annotated let assignment syntax node binding name : kind = value.
Construct a typed pattern syntax node binding name at type kind.
The unit value has a two-tuple parser representation rather than an
ordinary expression node. The parser bridge recognizes this reflected
marker and restores the canonical () AST before re-elaboration.
Construct a use <name> module import syntax node.
Return true when payload is a derivable type expression (not an opaque Raw node).
Construct a locally scoped variable reference syntax leaf.
Types
struct AliasSpec
?
?
enum Attr
KV
enum AttrResult
Found
Missing
type CasesSyntax
type CodeSyntax
type DeclarationsSyntax
type Diagnostic
type ExpressionSyntax
type FieldsSyntax
struct FunctionSpec
?
?
?
?
enum MacroResult
Expanded
Rejected
type ModuleBodySyntax
type ModuleNameSyntax
struct ModuleSpec
?
?
?
type NameSyntax
Shape-specific aliases keep generated family records readable without introducing separate runtime representations or weakening the generic reflection boundary.
struct ParameterSpec
?
?
?
Typed declaration specifications keep ordinary macro authors away from positional attribute lists. They are source-level records, so a builder call reads like the declaration it produces and remains reusable by any user-defined macro.
type ParametersSyntax
enum PatternHead
ValidHead
InvalidHead
enum PatternHeads
Heads
InvalidHeads
A constructor head extracted from a reflected match arm. The arity is retained in the generic constructor key so source-defined derivations can reject unsupported payload views without compiler-owned domain knowledge.
type PatternSyntax
enum PayloadTypes
Payloads
InvalidPayload
type StatementSyntax
enum SynLit
SInt
SChar
SFloat
SStr
SBool
SAtom
SList
SSyntax
SMap
SOpaque
enum SynPair
SPair
enum Syntax
Node
Leaf
Raw
Quoted
Failure
type TokenSyntax
type TypeSyntax
Functions
fn alias_from(spec: AliasSpec) -> Syntax
Lower an AliasSpec record into a typealias syntax node.
fn alias_node(name: String, rhs: Syntax) -> Syntax
typealias is what the authored surface tags this node with, and the
elaborator's header pre-pass keys off it: only a flagged alias gets a
forward-referenceable header. Emitting the flag is therefore not cosmetic
-- without it a generated alias (Handle, Data in an fsm) is invisible
to any declaration lowered before it, including the enclosing unit's own
declarations, which module lifting inlines ahead of the generated ones.
fn alias_spec(name: String, value: Syntax) -> AliasSpec
Construct an AliasSpec record with name and right-hand side value.
fn atom_literal(value: Atom) -> Syntax
Construct an atom (symbol) literal syntax leaf.
fn attr(values: List(Attr), key: Atom) -> AttrResult
Look up attribute key in values, returning Found(value) or Missing.
fn attr_atom_is(values: List(Attr), key: Atom, expected: Atom) -> Bool
Return true when attribute key in values is SAtom(expected).
fn attr_value(name: Atom, value: SynLit) -> Attr
Construct a key-value Attr entry.
fn attrs(syntax: Syntax) -> List(Attr)
Return the attribute list of syntax (unwrapping Quoted, or [] for Raw and Failure).
fn block(items: List(Syntax)) -> Syntax
Construct a :block syntax node containing items.
fn bool_literal(value: Bool) -> Syntax
Construct a boolean literal syntax leaf.
fn call(name: String, args: List(Syntax)) -> Syntax
call is part of the compile-time reflection API. Core-evaluator macro
execution must unfold it across the Std.Syntax interface boundary, so its
body is semantic interface data rather than an opaque runtime detail.
fn caller_identifier(name: String) -> Syntax
Name-intent constructors make scope decisions explicit in macro source.
caller_identifier deliberately retains the call-site scope; the other
two are used for generated references and declaration names respectively.
fn captured_parameter_name(value: Syntax) -> Option(String)
Extract the parameter name from a reflected :param syntax node, if present.
fn captured_parameter_pattern(value: Syntax) -> Option(Syntax)
Convert a reflected parameter node into a typed_pattern, when both name and type are available.
fn captured_parameter_type(value: Syntax) -> Option(Syntax)
Extract the :type syntax attribute from a reflected parameter node, if present.
fn char_literal(value: Char) -> Syntax
Construct a character literal syntax leaf.
fn children(syntax: Syntax) -> List(Syntax)
Return the child syntax nodes of syntax (empty for Leaf and Raw, [inner] for Quoted).
fn collect_pattern_heads(arms: List(Syntax), seen: List(Syntax), keys: List(Atom)) -> PatternHeads
Collect deduplicated constructor heads from arms, preserving order and failing on invalid arms.
fn constructor_key(values: List(Attr)) -> Atom
Extract the :constructor_key atom from values, or :invalid_constructor if missing.
fn constructor_name(values: List(Attr)) -> Bool
Return true when values carries :pascal_case set to true.
fn context_attr(syntax: Syntax, key: Atom) -> AttrResult
Look up one field in the generic staged expansion context.
fn derive_pattern_heads(body: Syntax) -> PatternHeads
Derive deduplicated constructor heads from the match arms of a reflected handler body.
fn diagnostic_details(primary: Syntax, message: String, hint: String) -> Syntax
Attach user-facing content to an authored diagnostic while keeping its
stable failure name in the outer Failure. Presentation adapters consume
this record uniformly for source-defined macros.
fn diagnostic_subspan(target: Syntax, start: Int, length: Int) -> Syntax
Select a Unicode-scalar-relative range inside syntax captured from the caller. The compiler validates the range against the captured source span; an invalid or generated target falls back to the macro invocation. Macro authors therefore cannot forge a path or escape the captured syntax.
fn enum_type(name: String, variants: List(Syntax)) -> Syntax
Construct an enum container syntax node named name with variants.
fn enum_variant(name: String) -> Syntax
Construct a nullary enum variant syntax leaf named name.
fn enum_variant_payload(name: String, payloads: List(Syntax)) -> Syntax
Build a constructor variant with explicitly typed payload fields. The
parser represents enum constructors as function definitions whose params
are type expressions, so this is the same surface form as a user-written
type Message = Ping(Int) declaration.
fn expand(value: Syntax) -> MacroResult
Wrap a syntax tree as a successful Expanded MacroResult.
fn expansion_context(syntax: Syntax) -> Syntax
Read the generic staged expansion context attached to reflected syntax. A context-free use site is represented by the same opaque value used for any unavailable syntax, so a source-defined macro can inspect it without relying on a compiler-owned callback record.
fn exported_identifier(name: String) -> Syntax
Construct an exported-scope identifier syntax leaf.
fn float_literal(value: Float) -> Syntax
Construct a float literal syntax leaf.
fn fresh(name: String) -> Syntax
Mark a generated binder or reference for the parser's existing hygienic freshening pass. Use the marker at each generated occurrence that should share a binding; syntax reflected from the caller remains untouched. The marker is compile-time syntax and disappears before ordinary elaboration; it is not a runtime name generator.
fn function(name: String, params: List(Syntax), return_type: Syntax, body: Syntax) -> Syntax
Construct a :function_def syntax node with name, params, return_type, and body.
fn function_downcase_identifier(identifier: Syntax, params: List(Syntax), return_type: Syntax, body: Syntax) -> Syntax
Build a function whose name is derived from reflected identifier syntax. The generic syntax bridge performs the requested Unicode-safe transform while converting the compile-time Syntax value back to parser AST.
fn function_from(spec: FunctionSpec) -> Syntax
Lower a FunctionSpec record into a :function_def syntax node.
fn guarded_match_arm(pattern: Syntax, guard: Syntax, body: Syntax) -> Syntax
Construct a guarded :match_arm syntax node for pattern when guard -> body.
fn handler_children(body: Syntax) -> List(Syntax)
Return the child nodes of a reflected handler body.
fn handler_head(arm: Syntax) -> PatternHead
Extract the constructor head from a single unguarded :match_arm syntax node.
fn has_key(keys: List(Atom), key: Atom) -> Bool
Return true when key appears in keys.
fn has_tag(syntax: Syntax, expected: Atom) -> Bool
Return true when syntax has the given tag expected.
fn identifier_name(value: Syntax) -> Option(String)
Generic identifier transformations for declaration-producing macros. These inspect reflected identifier syntax only; domain macros decide what generated name means (for example, an actor query adapter).
fn int_literal(value: Int) -> Syntax
Lift ordinary primitive values into literal syntax. These constructors are explicit so a string can never be mistaken for an identifier or raw syntax.
fn integer(value: Int) -> Syntax
Construct an integer literal syntax leaf.
fn is_variable_named(syntax: Syntax, expected: Atom) -> Bool
Return true when syntax is a :variable node whose :variable_name attribute equals expected.
fn leaf(name: Atom, values: List(Attr), value: SynLit) -> Syntax
Construct a Leaf with tag name, attributes values, and scalar value.
fn leaf_value(syntax: Syntax) -> SynLit
Return the scalar SynLit payload of a Leaf, or SOpaque for any other node kind.
fn let_binding(name: String, value: Syntax) -> Syntax
Construct an untyped let assignment syntax node binding name to value.
fn lift_module(module: SynLit, behaviour: Atom, declarations: List(Syntax)) -> Syntax
Construct a :lift_module syntax node for module with behaviour and declarations.
fn lift_module_isolated(module: SynLit, behaviour: Atom, declarations: List(Syntax)) -> Syntax
Build a lifted unit that inherits enclosing declarations but not the imports used only to define the surrounding macro. Macro authors can use this when the generated unit declares its complete import surface.
fn linear_parameter_spec(name: String, kind: Syntax) -> ParameterSpec
Construct a linear ParameterSpec with name and type kind.
fn list(items: List(Syntax)) -> Syntax
Construct a list literal syntax node from items.
fn match_arm(pattern: Syntax, body: Syntax) -> Syntax
Construct an unguarded :match_arm syntax node for pattern -> body.
fn module_from(spec: ModuleSpec) -> Syntax
Lower a ModuleSpec record into a :lift_module syntax node.
fn node(name: Atom, values: List(Attr), terms: List(Syntax)) -> Syntax
Construct a Node with tag name, attributes values, and children terms.
fn parameter(name: String, kind: Syntax) -> Syntax
Construct a function parameter syntax node with name and type kind.
fn parameter_from(spec: ParameterSpec) -> Syntax
Lower a ParameterSpec record into a :param syntax node.
fn parameter_linear(name: String, kind: Syntax) -> Syntax
Construct a linearly graded function parameter syntax node with name and type kind.
fn parameter_literals(params: List(Syntax)) -> SynLit
Encode a list of parameter syntax nodes as an SList of SSyntax literals.
fn parameter_names(items: List(Syntax)) -> SynLit
Build a SynLit list of wildcard ("_") binder names with the same length as items.
fn parameter_spec(name: String, kind: Syntax) -> ParameterSpec
Construct a non-linear ParameterSpec with name and type kind.
fn parameters_from(specs: List(ParameterSpec)) -> List(Syntax)
Lower a list of ParameterSpec records into :param syntax nodes.
fn pattern_head(pattern: Syntax) -> PatternHead
Extract a closed constructor head from a reflected match arm. A handler whose head cannot determine a nominal constructor is rejected by the caller rather than silently widening the generated message/event type.
fn payload_types(args: List(Syntax)) -> PayloadTypes
Extract derivable payload type expressions from a constructor pattern's argument list.
fn private_identifier(name: String) -> Syntax
Construct a hygienically freshened private identifier syntax leaf.
fn reject(diagnostic: Diagnostic) -> MacroResult
Reject macro expansion with a single Diagnostic.
fn reject_all(diagnostics: List(Diagnostic)) -> MacroResult
Reject macro expansion with a list of Diagnostic values.
fn reverse_heads(items: List(Syntax)) -> List(Syntax)
Reverse a list of collected pattern-head syntax nodes.
fn reverse_heads_acc(items: List(Syntax), acc: List(Syntax)) -> List(Syntax)
Tail-recursive accumulator helper for reverse_heads/1.
fn string_literal(value: String) -> Syntax
Construct a string literal syntax leaf.
fn syntax_atom(value: Atom) -> SynLit
Lift an Atom into a SynLit (SAtom).
fn syntax_bool(value: Bool) -> SynLit
Lift a Bool into a SynLit (SBool).
fn syntax_int(value: Int) -> SynLit
Lift an Int into a SynLit (SInt).
fn syntax_list(items: List(Syntax)) -> SynLit
Encode a list of Syntax nodes as an SList of SSyntax literals.
fn syntax_string(value: String) -> SynLit
Lift a String into a SynLit (SStr).
fn tag(syntax: Syntax) -> Atom
Small, total operations used by source-defined syntax macros. These keep syntax analysis in Cure instead of teaching the compiler about a macro's domain-specific declarations.
fn tuple(items: List(Syntax)) -> Syntax
Construct a tuple expression syntax node from items.
fn tuple_type(items: List(Syntax)) -> Syntax
Construct a tuple type syntax node with anonymous binders for items.
fn typed_let_binding(name: String, kind: Syntax, value: Syntax) -> Syntax
Construct a type-annotated let assignment syntax node binding name : kind = value.
fn typed_pattern(name: String, kind: Syntax) -> Syntax
Construct a typed pattern syntax node binding name at type kind.
fn unit_literal() -> Syntax
The unit value has a two-tuple parser representation rather than an
ordinary expression node. The parser bridge recognizes this reflected
marker and restores the canonical () AST before re-elaboration.
fn use_module(name: String) -> Syntax
Construct a use <name> module import syntax node.
fn valid_payload_type(payload: Syntax) -> Bool
Return true when payload is a derivable type expression (not an opaque Raw node).
fn variable(name: String) -> Syntax
Construct a locally scoped variable reference syntax leaf.