cratestack-parser
Parser and semantic checker for .cstack schema files.
Overview
cratestack-parser turns .cstack source text into a cratestack_core::Schema AST and runs semantic validation. The include_server_schema! / include_embedded_schema! / include_client_schema! proc-macros call this crate at compile time; the LSP and CLI call it at runtime.
Installation
[]
= "0.2.2"
Usage
Parse from a string
use parse_schema;
let source = r#"
auth Principal {
id String
role String?
}
model Post {
id String @id
title String
published Boolean @default(false)
authorId String
@@allow("read", auth() != null)
}
"#;
let schema = parse_schema?;
Parse from a file
use parse_schema_file;
let schema = parse_schema_file?;
Named source for diagnostics
use parse_schema_named;
let schema = parse_schema_named?;
Errors
SchemaError carries a source span and a line number plus an ariadne-rendered report:
use ;
match parse_schema
Supported Constructs
| Construct | Description |
|---|---|
datasource |
Database config (provider = "postgresql" or "sqlite") |
auth |
Single auth block declaring principal fields |
mixin |
Reusable field set, applied via @use(...) on a model |
model |
Entity with fields, relations, and policy attributes |
type |
Named record type (@custom fields supported) |
enum |
Untyped identifier variants |
procedure |
procedure / mutation procedure with typed args/return |
mcp |
Parsed as a config block |
See the root README for the canonical capability matrix.
Field and Model Attributes
See Field Attributes for the full list. Common attributes:
@id,@unique,@relation(...),@default(...)@readonly,@server_only,@pii,@sensitive@version(optimistic locking)@length,@range,@email,@regex,@uri,@iso4217(validators)@@allow(action, expr),@@deny(action, expr)@@audit,@@soft_delete@@emit(created, updated, deleted)
See Also
- Mixins reference
- Field Attributes
- Validators guide
cratestack-macros— the proc-macro that drives this parser at compile timecratestack-lsp— LSP frontend over the same parser
License
MIT