Syntax.Query
A source query over a decoded prism-syntax-tokens-v1 artifact.
This is a consumer of the public token representation, not part of the compiler. Given a TokensDoc (the exact source text plus the compiler’s own raw stream, layout-resolved parse stream, and trivia), it reports a stable, machine-readable inventory of the source: the content digest, the ordered imports, the comment spans, the ordered top-level declaration heads, and a token-kind histogram in first-seen order.
Every field is a pure function of the artifact bytes. Nothing here reads ambient workspace state: the same artifact always yields the same report, byte for byte. The inventory is a source-identity view. Two programs that differ only in comments or formatting have different digests and different comment spans here, yet elaborate to the identical Core; that duality is the point of the query.
Types
DeclHead
type DeclHead = DeclHead {
keyword: String,
name: String,
lo: Int
} deriving (Eq, Show)
The head of a top-level declaration: its leading keyword, the first name it binds, and the keyword’s start offset.
KindCount
type KindCount = KindCount { kind: String, count: Int } deriving (Eq, Show)
One bucket of the token-kind histogram: a wire kind and how many raw tokens carried it.
QueryReport
type QueryReport = QueryReport {
digest: String,
imports: List(String),
comments: List(Span),
decls: List(DeclHead),
kinds: List(KindCount)
} deriving (Eq)
The full source inventory of an artifact.
Functions and Values
query
query : (Syntax.Codec.TokensDoc) -> Syntax.Query.QueryReport
The full source inventory of a decoded artifact.
query_lines
query_lines : (Syntax.Query.QueryReport) -> List(String)
The inventory rendered as one stable line per fact: a digest line, then an import line per module, a comment line per span, a decl line per declaration head, and a kind line per histogram bucket. The ordering is deterministic, so the text is a machine-readable fingerprint of the source’s surface identity.
query_text
query_text : (Syntax.Query.QueryReport) -> String
The inventory rendered as one newline-joined block, ready to print in a single call. Same content and ordering as query_lines.