Module ast
Expand description
Abstract syntax tree types for Bynk v0 (spec §9.2).
Structs§
- Actor
Decl - An actor declaration (v0.45 §3.7). An actor is a nominal contract type
describing an external party at a boundary — not a runnable entity. A
handler consumes an actor on its
byclause; the boundary verifies the declaredauthscheme and mints a sealed identity (name.identity). - Actor
Refinement - The reserved refinement form
actor Admin = User where <predicate>(Q3). Parsed in Foundations so the grammar is fixed; admission is a later slice. - Adapter
Decl - An
adapter qualified.name { … }declaration (v0.17 §3.1). An adapter co-locates a capability contract with a non-Bynk binding: it may declare capabilities, the boundary types they reference, inline pure helpertype/fn(anduses), external (bodiless) providers,exports capability, and exactly onebindingclause. It may not declare services, agents, or bodied providers. Like commons/contexts it may be split across files in a directory. - Agent
Decl - An agent declaration (v0.5 §3.6). Agents are state-bearing entities with their own handlers.
- Annotation
- A storage annotation on a
storefield (v0.85, storage track; ADR 0111):@<name>(<args>). Thenameis matched against the closed registry (@indexed/@ttl/@retain/@bounded) by the checker; the grammar accepts any identifier so an unknown name is a checker diagnostic, not a parse error. Arguments are compile-time metadata, restricted to literals (and theby:field-name labels of@indexed) by the checker per ADR 0111 D4. - Annotation
Arg - A single annotation argument (v0.85; ADR 0111): an optional
label:followed by a value expression —by: orderId(labelled) or5.minutes(positional). The value is parsed as an ordinaryExprso the duration-literal form (5.minutes, landing with theDurationslice) needs no special grammar; the checker restricts it to a literal where the annotation is functional. - Assign
Stmt name := expr— aCellstore write (v0.81, storage track).targetis theCellfield being written (a bare name for now; the checker resolves it to astorefield).valueis the new value.- Binding
Decl - A
binding "<module>" requires { "pkg": "range", … }clause inside an adapter (v0.17 §3.5).moduleis the TypeScript module supplying the adapter’s external provider symbols, resolved relative to the adapter’s source file.requiresdeclares npm dependencies folded into the generatedpackage.json. - Block
- A brace-delimited block of statements ending in a tail expression whose value is the block’s value (spec v0.1 §3.1).
- ByClause
- The
by (<binder>:)? <Actor>clause on a handler (v0.45; binder optional in v0.50). Names the actor contract the handler consumes; when abinderis given, the verified identity binds to it and is read asbinder.identity. Omitting the binder (by <Actor>) declares-and-verifies the contract without capturing the identity — for anonymous or verify-and-discard handlers. Sits after the protocol config and before the parameters. - CapRef
- A capability reference in a
givenclause (v0.15 §3.2). A bare name is a local capability (given Cap); a dotted name refers to a capability a consumed context provides (given B.Cap/given Alias.Cap). - Capability
Decl - A capability declaration (v0.5 §3.3). Capabilities are interface-like
contracts for external dependencies, used inside contexts. They may only
appear inside a
contextdeclaration. - Capability
Op - One operation in a capability (signature only; no body).
- Case
- A
test "name" { body }block inside a test declaration (v0.7 §3.3). - Commons
- A whole parsed commons source file.
- Consumes
Decl - A
consumes other.contextdeclaration (v0.4 §3.2). May optionally carry an alias introduced byconsumes other.context as Alias(v0.6 §3.1). - Context
- A whole parsed context source file (v0.4 §3.1).
- Expect
Stmt - Exports
Decl - An
exports visibility { names }clause (v0.4 §3.3) or, v0.15, anexports capability { names }clause. - Expr
- Field
Init - One field-initialiser inside a record construction expression:
either
name: expror the shorthandname(which requires a binding of the same name in scope and uses its value). - Float
Bound - A float refinement bound (v0.21): the parsed value plus the signed source
lexeme (for byte-stable emission). v0.40 (ADR 0073): also the source span,
for the
InRange-swap quick-fix. - FnDecl
- ForAll
- The
for all x: T, … [where <pred>] { … }binder inside aPropertyDecl. - ForAll
Binding - One
for allbinding:name: T, where the runner generates inhabitants ofTfrom its refinements. - Handler
- A handler block —
on call(args) -> T given C1, C2 { body }. Used by both services and agents. - Http
Variant - One variant of the built-in
HttpResult[T]sum (v0.9 §3.3). - Ident
- An identifier with its source span.
- IntBound
- An integer refinement bound (v0.40, ADR 0073): the parsed value plus the
bound’s source span (covering a leading
-). Value-only beyond the span — ints have one canonical printed form, so the formatter stays idempotent without a stored lexeme. The span backs theInRange-swap quick-fix. - Integration
Decl - A
test integration "name" { wires C1, C2, … ; cases }declaration (v0.16 §3.1). Unlike a unit test, an integration test names a set of participating contexts (wires), stands each up as its own Worker, and exercises a flow across the real Worker boundary. It carries nomocks. - Invariant
- An agent invariant (v0.80 §14). A named predicate over the agent’s state
fields that must hold of every committed state; a commit that would violate
it faults (
InvariantViolation) before the state is persisted. The predicate references state fields by bare name, mirroring the design-notes worked examples (status == Paid implies paymentRef.isSome()). - Lambda
Expr - A lambda expression (v0.20a):
(params) => expror(params) => { … }.=>is the value arrow (shared withmatch); param annotations are optional where an expected function type supplies them. - Lambda
Param - A lambda parameter. A separate type from
Parambecause its annotation is optional —Param.type_refstays mandatory at every signature site. - LetStmt
- Match
Arm - One arm of a
matchexpression:pattern => body. - Mock
Decl - A
mocks Name = Impl { ops }declaration inside a test body (v0.7 §3.2). - MockOp
- One operation inside a mock declaration:
fn name(params) -> T { body }. - Param
- Pattern
Binding - A single binding inside a variant pattern. Two surface forms:
name(positional — bind the i-th payload field) andfieldName: bindName(named — bind the named payload field). Both forms also accept_as the bind name to discard. - Property
Decl - A
property "name" { for all <bindings> [where <pred>] { body } }block inside a suite (v0.114, testing track slice 2, ADR 0149). The generative sibling ofCase: the runner draws inhabitants of each binding’s type from its refinement domain and evaluates the body’sexpects over them. - Provider
Decl - A provider declaration (v0.5 §3.4). Supplies an implementation for a capability.
- Provider
Op - One operation in a provider (signature plus body).
- Qualified
Name - A dotted name like
fitness.units. - Queue
Variant - One variant of the built-in
QueueResultsum (v0.44). - Record
Body - Body of a record-type declaration (v0.2 §3.1).
- Record
Field - One field of a record type declaration. Each field may carry inline refinement, which is enforced at construction time on the field’s value.
- Refinement
- Refinement
Pred - Requires
Dep - One
"pkg": "range"entry in a binding’srequires { … }map. - Scheme
Arg - One
key = valueargument in a scheme config (Scheme(key = value, …)). - Send
Stmt - Service
Decl - A service declaration (v0.5 §3.5). Services are the boundary interface of a context.
- Store
Field - A
storefield (v0.81, storage track). Each is an access-pattern slot of a declared storage kind:store <name>: <Kind>[…] [@annotations] [= <init>]. The kind and its element type are carried as an ordinaryTypeRef(Cell[Int],Map[K, V]); the checker restricts which heads are storage kinds. Access-pattern annotations (@indexed, …) parse intoannotations(v0.85, ADR 0111); the checker validates them against the closed registry. - Store
Kind - A storage kind applied to its element type(s) (v0.81):
Cell[Int],Map[ReservationId, Reservation]. Theheadis the kind name (Cell,Map,Set,Log,Queue,Cache); the checker validates it against the closed catalogue. Element types are ordinaryTypeRefs. Refined element types (Cell[Int where NonNegative]) ride a later slice (parse_type_ref does not yet accept an inline refinement in type-argument position). - Suite
Decl - A
test <qualified-name> { ... }declaration (v0.7 §3.1). - SumBody
- Body of a sum-type declaration (v0.2 §3.2).
- Trivia
- Comment trivia attached to a declaration or statement (v1.1 LSP spec §3.5). The parser collects line comments from the token stream and attaches them to nearby AST nodes so the formatter can re-emit them.
- Type
Decl - Type
Param - A function type parameter (v0.20a,
fn name[A, B](…)). A struct rather than a bare Ident so the ADR-0028 “bound-capable” promise is a later field addition, not a representation change. - Uses
Decl - A
uses other.commonsdeclaration (v0.3 §3.3). - Variant
- One variant of a sum type. Variants may have payload fields; a payload-less variant is a simple tag.
- Variant
Field - One payload field of a sum variant. Variant payload fields use named declarations like record fields, but do not carry refinement in v0.2.
Enums§
- Base
Type - BinOp
- Commons
Form - The two surface forms in which a commons body may be parsed (v0.3 §3.1).
- Commons
Item - Duration
Unit - A
Durationliteral unit (v0.86, ADR 0112) — the closed set of suffixes in a<int>.<unit>literal. Each maps to a fixed millisecond factor (Durationerases toIntmilliseconds). - Export
Kind - What an
exportsclause exposes: types (with a visibility) or, v0.15, capabilities offered for cross-context consumption. - Expr
Kind - FnName
- A function-declaration name: either a free function
for a methodT.method(v0.2 §3.6). - Handler
Kind - Http
Method - HTTP methods supported by
on httphandlers (v0.9). - Http
Variant Payload - Payload shape of an
HttpResult[T]variant (v0.9 §3.3). - Interp
Part - One part of an interpolated string (v0.43, ADR 0075). An
ExprKind::InterpStrholds an alternating run of these. - Match
Body - The right-hand side of a match arm — either a single expression or a block.
- Pattern
- A pattern (v0.2 §3.8). Patterns appear in
matcharms and as the right-hand side of theisoperator. - Pattern
Binding Kind - Pred
Kind - Queue
Variant Payload - Payload shape of a
QueueResultvariant (v0.44). Non-generic — a verdict carries no value;Retrycarries aStringreason for the log path. - Scheme
ArgValue - A scheme config arg value — a string literal or an integer.
- Service
Protocol - The protocol a service conforms to — declared on the header via
from <protocol>(v0.44).Callis the default (nofromclause): a contract-mediated internal-RPC surface, not a wire protocol. Multi-endpoint protocols (Http,Cron) carry no binding — the endpoint lives on each handler; single-bindingQueuecarries its queue name. - Source
Unit - Either a commons or a context — the two declaration kinds at the file level (v0.4 §3.1). v0.7 adds the test declaration kind; v0.17 the adapter.
- Statement
- Block-level statement.
- Type
Body - The right-hand side of a
typedeclaration. In v0/v0.1 only theRefinedvariant existed; v0.2 adds records and sums; v0.3 adds opaque. - TypeRef
- UnaryOp
- Visibility
- Visibility level for an exports clause (v0.4 §3.3).
Constants§
- HTTP_
VARIANTS - All
HttpResult[T]variants, in declaration order (ascending status). The vocabulary tracks the common, modern HTTP status codes (RFC 9110): success and created/accepted (Value), redirects carrying aLocationURL, and the client/server failures that handlers routinely return (Messagewhen an explanation helps the caller,Nonefor self-describing statuses). - QUEUE_
VARIANTS - All
QueueResultvariants, in declaration order.Ackconfirms the message;Retryredelivers it, carrying a reason for observability.
Functions§
- http_
variant - Find an
HttpResult[T]variant by name. Returns the variant info orNoneif the name doesn’t match. - queue_
variant - Find a
QueueResultvariant by name.