6. The @document and gathering
How one root schema collects every block instance into a single validated document.
After this lesson you can
- Declare a @document root with @child / @children slots - Gather several block kinds into one document - Explain how document schemas merge per namespace
Before you start: Declaring types and decorators
@document marks the root schema. The toolchain *gathers*: every top-level block instance whose kind matches a @child/@children field is collected into that field, and every top-level field must be declared — that is what wcl check checks. Paths like servers.api.port then address the gathered tree from the root.
Document schemas merge per namespace: when several @document types are visible — say a library's (via import <wdoc.wcl>) and your own — a top-level item is legal if any of them declares it. Only a second root-authored @document in the same namespace is an error, so libraries compose without ceremony.
§ 1Exercise: Two kinds, one document
Gather two block kinds under one root and address values through the gathered paths.
@block("server")
type Server {
@inline(0) name: identifier
port: u16
}
@block("cache")
type Cache {
@inline(0) name: identifier
size_mb: u32
}
@document
type Infra {
@children("server") servers: list<Server>
@children("cache") caches: list<Cache>
}
server web { port = 8080u16 }
server api { port = 9090u16 }
cache hot { size_mb = 512u32 }
Expected result
wcl check prints OK; wcl eval infra.wcl servers.api.port prints 9090u16 and wcl eval infra.wcl caches.hot.size_mb prints 512u32.
Hint
Author a block kind the root doesn't declare (say queue jobs {}) and wcl check rejects it — gathering is also the membership check.