Skip to content

docs(grammar): ratify spec block, use spec, refines#44

Merged
koolamusic merged 2 commits into
mainfrom
feat/grammar-spec
May 8, 2026
Merged

docs(grammar): ratify spec block, use spec, refines#44
koolamusic merged 2 commits into
mainfrom
feat/grammar-spec

Conversation

@koolamusic

Copy link
Copy Markdown
Contributor

Summary

Ratifies the language constructs discussed in PR #42's review thread
and proven out by the canonical types in PR #43.

The grammar gains three things:

  1. `spec` block — a `type` with prose, examples, and reuse
    semantics. Reads like `policy` (`intent:` + `examples:`);
    produces a type. Same fixed set of underlying primitives.
  2. `use spec X, Y, Z` — top-level line that brings one or more
    specs into a file's scope. Supports parameterization via
    `use spec Money(currency: USD)`.
  3. `spec X primitive refines { ... }` — extend or override an
    imported spec; meta-fields not mentioned carry over.

What changed

  • `GRAMMAR.md`:
    • `spec` added to the ENTITY word-axis; `refines` added as an
      ENTITY modifier.
    • `spec` added to the "Block types at a glance" table.
    • New §`spec` section covering the block shape, required
      parameters, `use spec` resolution rules, `refines` semantics,
      and the compilation contract.
  • `prompts/codegen-base.md`:
    • New §`spec` row in the type/enum mapping table.
    • Codegen rules: `spec`, `use spec`, `refines` all compile
      identically to a `type` block before target overlays run.
    • Examples on a spec produce unit tests the same way `policy`
      examples do.
    • Unresolved `use spec` is a refusal condition.

Resolution rules (locked)

For `use spec X`:

  1. Project-local `spec X` declaration wins.
  2. Otherwise, `candy.toml` `[deps]` projects, in declaration order.
  3. Unresolved → refuse generation with a clear error.

The dep-fetch resolver is future tooling — v0.1 is local-only.

What this enables

Out of scope

Test plan

Refs

koolamusic added 2 commits May 7, 2026 14:34
Adds the language constructs discussed in PR #42's review thread and
proven out by the canonical types in PR #43.

A `spec` block is a `type` with prose, examples, and reuse semantics —
mechanically identical to a `type` after compilation, but
prose-rich and shareable across projects. Reads like `policy`
(`intent:` + `examples:`); produces a type. Same fixed set of
underlying primitives (`int`, `string`, `opaque`, `bool`, `bytes`,
`instant`, `decimal`).

A consumer brings specs into scope with `use spec X, Y, Z`, optionally
pinning required parameters: `use spec Money(currency: USD)`. The
toolchain resolves `X` against project-local `spec X` declarations
first, then `candy.toml` `[deps]`. Local always shadows imported.

A consumer extends or overrides an imported spec with `spec X primitive
refines { ... }` — meta-fields not mentioned carry over from the
original; the underlying primitive must match.

Adds `spec` to the ENTITY word-axis and `refines` as an ENTITY
modifier. Both updates land in §"The five word-axes" and the
"Block types at a glance" table.

The dep-fetch resolver is future tooling — v0.1 is local-only. The
grammar is the contract; tooling lands later.

Refs #42, #43.
Adds a §spec subsection to the universal block-mapping contract.
Codegen now compiles `spec X primitive { ... }`, `use spec X`, and
`spec X primitive refines { ... }` identically to a `type` block —
the prose and examples produce unit tests the same way `policy`
examples do.

Resolution rules mirror GRAMMAR.md: project-local declarations win,
then `candy.toml` `[deps]`, in declaration order. Unresolved
`use spec` references refuse generation with a clear error.

A spec with a `parameter` field cannot be used as a type until the
parameter is pinned at the consumption site (`use spec X(field: value)`)
or substituted via `refines`. Generation fails otherwise.

Target overlays remain spec-unaware — translation to `type` happens
before the overlay runs.

Refs #42, #43.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant