pub struct Parser { /* private fields */ }Implementations§
Source§impl Parser
impl Parser
pub fn new(input: &str) -> Result<Self, String>
pub fn new_with_validation( input: &str, use_validation: bool, ) -> Result<Self, String>
Sourcepub fn parse(&mut self) -> Result<Schema, String>
pub fn parse(&mut self) -> Result<Schema, String>
Parse the input into a Schema, running the full positioned semantic
validation (crate::validate::validate_schema) and failing fast on the
first diagnostic to preserve the historical Result<Schema, String>
contract. Naming diagnostics are gated by the parser’s use_validation
flag (see Self::new_with_validation); structural/reference diagnostics
always run.
Sourcepub fn parse_unvalidated(&mut self) -> Result<Schema, String>
pub fn parse_unvalidated(&mut self) -> Result<Schema, String>
Parse the input into a Schema performing only structural parsing:
tokens are assembled into the AST and enum field-type references are
resolved, but no schema-level semantic validation is run. Syntactic
errors (unexpected tokens, malformed directives, empty models/structs,
composite-index arity) are still fatal.
The returned schema may therefore contain semantic defects (duplicate
names, dangling relations, bad casing). Callers that want those reported —
the CLI forgedb validate command and the LSP — run
crate::validate::validate_schema on the result to collect all
positioned diagnostics instead of only the first. (Error recovery for
mid-keystroke buffers is #173 WS2c.)
Sourcepub fn parse_recover(&mut self) -> ParsedSchema
pub fn parse_recover(&mut self) -> ParsedSchema
Resilient parse (#173 WS2c): parse the input into a best-effort
ParsedSchema — a partial Schema plus all diagnostics — instead
of aborting on the first error. This is the entry point for the LSP, where
a buffer is usually mid-edit and blanking every diagnostic/symbol on a
single typo is unacceptable.
Recovery is two-tier: a malformed field or model directive is recorded and
skipped to the next line (the rest of its model still parses); a malformed
declaration is recorded and skipped as a whole balanced block (the rest
of the file still parses). After the partial AST is assembled it is run
through crate::validate::validate_schema, so the returned diagnostics
contain both recovered syntax errors and every semantic error, positioned
and sorted by source location.
Unlike Self::parse, this always succeeds — an empty or unparseable
buffer yields an empty schema and (possibly) diagnostics rather than an
error. (Lexer errors are still fatal at Self::new; the LSP surfaces
those as a single diagnostic.)