Expand description
Source parser for .whip programs.
The v0 grammar is still stabilizing, so this crate uses a small hand-written parser. It preserves source spans and keeps rule/effect bodies as source text until the typed IR is ready to lower them.
Modules§
- body
- Rule and flow body parsing: a real AST over body text.
Structs§
- Action
Decl action <name>(<param: type>, …) { <effect chain> }(DR-0023): a static, hygienic, inline-expanded template over rule-body effect chains. Consumed byexpand_action_callsbefore lowering; never a runtime construct.- Action
Param - One typed parameter of an
actiontemplate (DR-0023). - Agent
Decl - Apply
Decl - Assert
Decl - Block
Source - Campaign
Decl campaign <name> { ascend … [reach …] [guard …] [sacrifice …] }(improve design note §3): versioned, diffable objective intent at higher ceremony than a CLI invocation — the partition of the gauge vector. Unnamed gauges are guarded by default;guardwidens a band,sacrificereleases a gauge,reachsets a target that becomes a hard bound.- Campaign
Guard guard <gauge> within 2 percent: an indifference-band override.- Campaign
Reach reach <gauge> at least 0.9/reach std.latency at most 800ms.- Channel
Decl channel <name> { provider <p> [workspace <w>] [destination "<d>"] }(std.messaging): a named communication route through a provider. The barechannelconstruct shape is reserved by the platform forstd.messaging(spec/messaging.md), so third-party packages cannot author channel-like semantics with weaker guarantees. Lowers to ametadata_onlydeclaration (likequeue); the runtime messaging provider is later-stage work.- Channel
Provider Report - std.messaging v1 provider capability report (spec/std-messaging.md
“Capability reports + conditioned checks”). Reports are DATA, never code
(M8): these compiled constants are mirrored by the embedded std.messaging
manifest’s
bindings[].config.reportrows, and the conditioned static checks below admit syntax only when the selected provider’s report supports it. Report axes are messaging.md “Provider Capability Report” narrowed for v1:delivery_receipts⊆ {accepted, failed};identity⊆ {anonymous, claimed_actor} (no verified_actor provider exists, so any check demanding verified identity fails closed);content⊆ {text, markdown}. - Class
Decl - Class
Field - Clock
Policy - Coerce
Decl - Comment
- A source comment captured by the lexer. Comments are kept out of the token
stream (so the parser is unaffected) but retained here so tooling —
whip fmt, the LSP — can preserve them.textis the trimmed content after the marker;spancovers the marker through end of line (exclusive of the newline). - Compile
Output - Counter
Decl - Credential
Decl credential <name> { kind <kind> }(std.custody; DR-0053 §5): a bare handle naming a custodian entry — governance supplies reality viagrant credential … -> credential:<addr>, and material never appears in source.kindexists so the checker can statically reject an operation the credential cannot perform (sign … withabearer); the custodian’s registered kind is authoritative and mismatch is a check error. Kinds are spelled with underscores in source (hmac_sha256) and normalize to the protocol’s kebab-case.- Decl
Canon - One declaration’s canonical identity and content hash.
- Decl
Symbol - One top-level declaration for an editor outline (
whip lsp’stextDocument/documentSymbol): its name, a coarse kind tag, and source span. - Diagnostic
- Enum
Decl - Enum
Variant Decl - One enum variant: bare (
Accept) or data-carrying with a brace body that reuses the class field grammar (sum types, spec/sum-types.md). - Event
Decl - A typed external-signal declaration (
signal deploy.finished { ... }): the ingress manifest naming a dotted event and its payload schema (spec/event-ingress.md). - Expect
Clause - Expr
Object Field - File
Store Decl file store <name> { root "<dir>" }(std.files): a capability-scoped file store identity with a literal root directory. v0 is a local storage boundary.- Format
Output - Gauge
Bar - An optional bar: the default decision bar for settle/campaign gates.
expect P(<field>) at least 0.9(chance-shaped) orexpect p10 at least 0.7/expect mean at most 800(stat-shaped). Thresholds keep their exact source text (Eq-safe, format-exact); consumers parse. - Gauge
Decl gauge <name> [on <site>] { judge via ... [expect ...] [inputs ...] }(experimentation subsystem §4.2): a named quality dimension — a site, a judge, optionally a bar. The sibling oftest: deterministic expectation vs. stochastic expectation, one family. Core grammar (hand-parsed): thejudge viatagged union and the bar form are outside the declaration family’s shape. Bars use the word formsat least/at mostbecause the declaration tokenizer deliberately steps over>=/<=(the same reason field presence conditions useis).- Gauge
Ref - A (possibly dotted) gauge reference: user gauges are bare idents, the
built-in resource gauges are namespaced (
std.spend/std.latency/std.tokens). - Harness
Decl - Ident
- Include
Decl - IrAccess
Grant - A lowered turn-access grant: the granted operations narrow the turn’s effective
authority on
resource(modeled inmodels/maude/turn-access-grant.maude). - IrAccess
Grant Op - IrAgent
- IrAssertion
- IrBounded
Egress - A bounded-type projection egress (
record <T> from <src>): the recorded fact keeps exactlyT‘s fields, copied fromsrc, so the egress carries only the kept fields’ per-field labels — the “bounded-type” auto-redaction reading (DR-0027). The bound is the declared target typeT; the labels are the SOURCE schema’s (a target field mislabelled public is still caught against the source’s label). The IFC engine governs it exactly like an explicitredact. - IrCampaign
- A lowered
campaigndeclaration (improve design note §3): the named, versioned partition of the gauge vector.metadata_only; consumed bywhip improve <name>. - IrCampaign
Guard - IrCampaign
Reach - IrChannel
- A lowered
channeldeclaration (std.messaging): the channel identity, its provider, and optional workspace/destination config. Lowering class ismetadata_only; the runtime messaging provider consumes it later. - IrClass
- IrClass
Field - IrCoerce
- IrConstruct
Use - IrCounter
- IrCredential
- A lowered
credentialdeclaration (DR-0053 §5): a handle plus its declared kind, normalized to the custody protocol’s kebab-case. Metadata only — reality (material, sealing rung, grants) lives with the custodian and governance, never in the program. - IrEffect
Dependency - IrEffect
Node - IrEnum
- IrEvent
- A declared external event: the typed ingress manifest (spec/event-ingress.md). Dotted name, class-shaped payload.
- IrExpression
- IrFile
Store - A lowered
file storedeclaration (std.files): the store identity + its literal local root directory, consumed by the runtime file provider. - IrGauge
- A lowered
gaugedeclaration (experimentation subsystem): the binding of a judge to a quality dimension, versioning with the program. Lowering class ismetadata_only; the evidence engine (whip evidence/whip improve) consumes it at runtime. - IrGauge
Bar - A lowered gauge bar.
formischance(P(field)) orstat(p10/mean/…);opis>=(at least) or<=(at most);thresholdkeeps its exact source text — consumers parse. - IrHarness
- IrInclude
- IrLease
- Coordination resources (spec/coordination.md), lowered.
- IrLedger
- IrMark
- A lowered
markdeclaration: a named cut point riding a committing site.metadata_only; the runtime stampsmark.reachedevents, the improve store pins scenarios at them. - IrMemory
Pool - A lowered
memory pooldeclaration (std.memory, MEM-1): the pool identity + its optional recall context-limit budget.metadata_only— providesResource<MemoryPool>; providers readcontext_limitfrom the effect input. - IrParam
- IrPattern
Application - IrPattern
Argument - IrProgram
- IrProjection
Read - IrRecord
Source - IrRedaction
- A
redact <source> keep [..] as <binding>projection, surfaced for the information-flow value-flow engine (DR-0027).sourceis the binding being projected,keepthe kept field names,bindingthe projected output. - IrRegion
- DR-0043 Decision 5: a rule’s
during/untilregion, pre-rendered as the three body variants the kernel lowers against.IrRule.bodyitself is the condition-HOLDS variant (region spliced inline), so every existing text scanner and effect-id derivation is untouched; the kernel swaps inbody_removed(region gone – post-lapse suppression) orbody_lapsed(region replaced by its arm) per the region’s durable state. NOT rendered into the .ir snapshot (derived, deterministic). - IrRegion
Effect - DR-0043 Decision 5: one effect the region contains, with the level-1
afterscope the kernel keys its effect id under. - IrRule
- IrRule
Case Branch - IrRule
Dependency - IrRule
Metadata - IrShared
Coordination Usage - IrSource
- A lowered source declaration (spec/std-time.md).
is_clockselects theclock_sourcelowering; otherwisesignal_source. Both lower through thesource_declarationconstruct family and admit a durable signal fact. - IrSource
Description - IrSource
Emit Field - IrSource
Tag - IrStream
- One lowered
streamdeclaration (std.vcs): the workstream tier’s declared membership + staleness bound. Runtime homing reads this. - IrTerminal
Alternative - IrTerminal
Case Branch - IrTerminal
Output - IrTest
- A lowered test scenario (spec/workflow-testing.md). Tests are excluded from
the executable IR (
compile/runignore them);whip checkvalidates them andwhip testruns them. The clause detail is retained for the harness. - IrTracker
- IrUse
- IrWhen
- IrWorkflow
Contract - Lease
Decl - Coordination resources (spec/coordination.md): a closed family of shared,
workspace-scoped resources with typed keys, atomic branchable operations,
and mandatory bounds (
ttl/retain/cap+reset). - Ledger
Decl - Mark
Decl mark "<name>" after <site>(experimentation subsystem §4.2): a named cut point. The runtime stamps amark.reachedevent when the named site commits on any run, so every run’s meaningful moments are addressable —whip pin <run> at <mark>freezes the prefix as a scenario, and regeneration replays that prefix and re-executes only the suffix. Names are stable across edits (event offsets shift, marks don’t). Deliberately a separate declaration frommilestone(child→parent lifecycle signaling vs. event-log position).- Memory
Pool Decl memory pool <name> { context limit <n> }(std.memory, MEM-1): a named durable memory place. Mirrorsfile storeas adeclaration_block/metadata_onlyconstruct providingResource<MemoryPool>. v1 pools are provider-less;context limit <n>(optional, non-negative) is the recall packing budget. Unknown clauses are rejected (file-store precedent).- Param
Decl - Parse
Output - Pattern
Decl - Program
- Proj
Query - A projection query:
<noun> exists | count <predicate> is <N> | where <predicate>. The predicate reuses the guard expression kernel, restricted to projection fields. The noun is a dotted fact name, so a scenario can assert over runtime facts such asagent.turn.completedas well as single-identifier user facts. - Related
Info - A secondary span + short label attached to a
Diagnosticas related information (never a top-level diagnostic of its own). - Rule
Decl - RunClause
- Source
Decl - A top-level source declaration:
source <provider> as <name> { ... }orsource clock as <name> { ... }. Lowers through thesource_declarationconstruct family to asignal_source(generic provider) orclock_source(theclockprovider) admission template (spec/std-time.md, spec/construct-grammar.md). A source admits a durable signal fact; it never fires a rule directly. - Source
Emit - Source
Emit Field - Source
Span - Stream
Decl stream <name> { members [<agent>, ...] [staleness <duration>] }(std.vcs; DR-0052 Decision 5): a declared collaboration — a named shared line whose member agents’ session lines home to it, syncing greedily in-stream and promoting to mainline through one gated boundary. Members are agent declarations (every session of that agent homes here);stalenessis the §7.1 bound. Metadata-only lowering, likequeue/channel; the runtime workstream tier is the enforcement seam.- String
Literal - Stub
Clause stub <surface…> <outcome> [record | string]. The surface path and outcome are kept as tokens; provider-specific validation happens in the harness.- Table
Decl - Table
Row - TagDecl
- Test
Decl - A deterministic test scenario (spec/workflow-testing.md). Validated by
whip check; excluded from compile/run IR; executed bywhip test. - Test
Field - A
<field> <expr>mapping inside agivenrecord body.valueis the source text of the expression (parsed viaparse_expressionwhen validated), matching how guards and assertions capture expressions. - Time
OfDay - Tracker
Decl - UseDecl
- When
Clause - Workflow
Contract Decl - Workflow
Decl
Enums§
- Agent
Field - Binary
Op - Calendar
Pattern - Comment
Marker - The marker that introduced a comment, preserved so a formatter can re-emit it faithfully.
- Dependency
Predicate - Effect
Status - Expect
Target - Expr
- Expr
Literal - Gauge
BarSubject - Gauge
Judge - The generalized judge slot:
judge via coerce <Name>(<args>) | prompt "<t>" | exec "<cmd>" | labels "<source>". Coerce judges carry EXPLICIT argument paths (settled 2026-07-14): each names the record value feeding the parameter (input.ticket.title,facts.Assessment.priority), or the single reservedrecordpasses the whole judge-input record — the binding is written down and versioned, never inferred. - Given
Clause - Harness
Class - The harness class (DR-0034).
Managed= WhippleScript is the agent runtime (owned; hermetic context, full provenance, reproducible).Delegated= a foreign runtime WhippleScript invokes, which assembles its own context. The guarantee is two-valued, so the class is too. - IrCase
Pattern - IrEffect
Kind - IrExec
Target - The two
execsource forms (spec/std-script.md): a raw command string (exec "cmd", dev-profile only) or an operator-manifest capability (exec <name> with <record>). - IrPrimitive
Type - IrSchema
- IrType
- IrUse
Kind - IrWorkflow
Contract Kind - Item
- Missed
Policy - Missed-occurrence policy from spec/std-time.md. No silent default: a recurring source must declare one (enforced by the checker).
- Proj
Query Kind - Query
Kind - Recurrence
- Recurrence forms from spec/std-time.md (conservative first surface).
- Rule
Status - RunKind
- Source
Value - A value mapped into an emitted signal field: an observation path
(
tick.scheduled_at) or a literal. - Stub
Payload - Test
Clause - Type
Syntax - UnaryOp
- Weekday
- Workflow
Contract Kind
Constants§
- BUILTIN_
GAUGES - The built-in resource gauges: deterministic observables already in the
effect ledger, present without declaration (improve design note §3).
std.cache_hitis the provider prompt-cache hit rate (cache-read tokens / total input-side tokens) — present only when the provider reports cache usage (spec/inference-cache-note.md G2). - CHANNEL_
PROVIDER_ REPORTS - The four v1 std.messaging providers (spec/std-messaging.md “Providers”).
- FILE_
STORE_ PROVIDERS - The v1 std.files store providers (spec/std-files.md “Providers”):
localis the FileStore host-projection seam (native + DO) and the default when afile storedeclares noproviderclause. Non-filesystem providers (S3/GitHub/Drive) are deferred with cause; an unknown identifier is a check error at the declaration. - STD_
PACKAGE_ IDS - The complete standard-package universe (the 13 std packages of the
standard-package campaign).
use std.<name>outside this list is a check error: std resolution is a built-in registry, so an unknown name can never resolve later — a typo’duse std.coerconwould otherwise silently import nothing (and downstream missing-import bite is advisory only).
Functions§
- canonical_
declarations - Canonicalize every top-level declaration of
source.Nonewhen the source does not parse or the declaration identities are ambiguous (duplicates) — callers fail closed to their pre-DR behavior. A multi-workflow program’sworkflow X { … }blocks are single units (matching merge’s depth-0 split), with alpha applied to their nested rules. - canonical_
program_ hash - The canonical program hash: SHA-256/128 over the sorted
(identity, canon_hash)pairs — insensitive to formatting, comments, declaration order, and rule-binding names.Nonewhen the source has no canonical form. - channel_
provider_ report - Resolve a channel’s declared
provider <p>identifier against the v1 provider reports: the short name (local) or the full binding provider id (std.messaging.local) both resolve.None= unknown identifier, a check error (spec/std-messaging.md open question 2 resolved: short names resolved against contributed provider kinds, unknown = check error). - compile_
program - Parses and lowers a source file into deterministic typed IR.
- compile_
program_ with_ root - Parses and lowers a source bundle into deterministic typed IR with an optional explicit root workflow selection.
- document_
symbols - Top-level declarations of
sourcein source order, for an editor outline. On a parse error it returns whatever declarations parsed (best-effort outline). - format_
program - Formats the syntax tree without lowering or analyzing rule bodies.
- format_
program_ preserving_ comments - Format
sourcewhile preserving comments where they can be placed safely: top-level leading comments (a# …or// …line above a declaration, or a file-header block) and trailing comments on a single-line top-level declaration (workflow Demo # …, attached to that element’s line); comments inside raw-body declarations (rule/apply/coerce/table/flow, carried by the body substring); and comments insideclass/agent/enumbodies, including a data-carryingenumvariant’s nested field block — both own-line (interleaved by source position) and trailing comments on a field/variant line (appended to it), andsignal/queue/file storebodies the same way — even though those bodies rebuild from the AST. ReturnsNonewhen the program does not parse, or when a comment has nowhere to attach — e.g. one trailing a declaration’s opening-brace line, with no field on that line. The caller refuses such files rather than dropping comments. - harness_
class - Classify a harness kind (DR-0034 Decision 6). Total over the supported kinds:
ownedand the credential-freefixturemodel client are Managed; every other kind (codex/claude sidecars, thenative-fixturedelegated adapter,command) is Delegated. An unrecognized kind — validated registry-side by the CLI (spec/std-agent.md “Open provider registry”) — defaults to Delegated, never granting the Managed guarantee to something unknown. - inline_
decide_ schema_ name - The hygienic class name synthesized for an inline
decide -> { … } as <binding>. Dots are illegal in user class names (like theflow.<name>.seg*rule convention), sodecide.<rule>.<binding>can never collide with a declared schema. The lowering pass, the type checker, and the runtime fixture all derive the same name, so the anonymous result shape flows exactly like a namedcoerce -> Schema:after <binding> succeeds as rresolvesr’s fields forcasedispatch and field access. - lex_
comments - Extract the comments from a source program, in source order. Comments are not
part of the token stream or AST; this is the entry point tooling (
whip fmt, the LSP) uses to preserve them. - parse_
duration_ seconds - parse_
expression - Parses a deterministic expression used by guards, assertions, and branch guards.
- parse_
program - Parses a source file into a recoverable AST plus diagnostics.
- parse_
time_ epoch_ seconds - parser_
stage - Stage marker retained for the CLI scaffold.
- redact_
schema_ name - The hygienic synthetic class name for a
redact … as <binding>projection:redact.<rule>.<binding>, holding only the kept fields of the source schema. - runtime_
fact_ name_ for_ pattern - The single lowering table for readiness sugar: maps a
whenpattern to the runtime fact name it matches. The general form iswhen fact <name> as x; the English phrases are documented abbreviations of it. - string_
and_ comment_ spans - Byte-span regions of string literals and comments in
source. A tool that edits identifier occurrences (e.g.whip lsprename) consults these to avoid touching text inside a prompt string or a comment — only code identifiers are real references.