Skip to main content

Parser

Struct Parser 

Source
pub struct Parser { /* private fields */ }

Implementations§

Source§

impl Parser

Source

pub fn new(input: &str) -> Result<Self, String>

Source

pub fn new_with_validation( input: &str, use_validation: bool, ) -> Result<Self, String>

Source

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.

Source

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.)

Source

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.)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.