Skip to main content

AdamAstParser

Struct AdamAstParser 

Source
pub struct AdamAstParser { /* private fields */ }
Expand description

Parses adam-lang source strings into ast::Sheet trees, instead of executing into a live adam_rs::Sheet (see crate::AdamParser for that path).

§Example

use adam_lang::AdamAstParser;

let sheet = AdamAstParser::new().parse_str("sheet s { cell x: i32 = 0; }").unwrap();
assert_eq!(sheet.name, "s");

Implementations§

Source§

impl AdamAstParser

Source

pub fn new() -> Self

Creates a new AST-building parser.

Unlike crate::AdamParser::new, this takes no TypeRegistry/OpLookup — AstContext resolves no identifiers and validates nothing during parsing (see this plan’s Architecture section), so there is nothing for either to configure.

Source

pub fn parse_str(&mut self, source: &str) -> Result<Sheet, ParseError>

Parses an adam-lang source string into an ast::Sheet.

A syntax error inside one cell/relationship/conditional item is recorded in Sheet.errors and replaced by a SheetItem::Error placeholder covering the skipped tokens; parsing resumes at the next sheet item instead of aborting (see TokenCursor::skip_to_recovery_point). This recovery is declaration-level only: a malformed binding inside a relationship/conditional block causes the whole enclosing item to become one SheetItem::Error.

Recovery is reliable for syntax errors adam-lang’s own grammar detects directly (malformed cell declarations; relationship/conditional/binding structure outside their CEL expression bodies, including a malformed type_expr’s own dangling (/)) and for CEL expression errors, including one that leaves a dangling, unmatched delimiter of a kind CEL reuses for its own internal grouping — e.g. an if/else expression’s braces, the same Delimiter::Brace kind adam-lang uses for its own relationship/conditional blocks (if a { } is one such case), or a tuple/group literal’s or call’s parens, the same Delimiter::Parenthesis kind type_expr uses ((+) is one such case): see TokenCursor::absorb_unbalanced_delimiters.

§Errors

Returns Err for structural errors outside any sheet item (e.g. a missing sheet keyword, missing sheet name, missing top-level braces, or trailing tokens after the sheet closes) — these can’t be attributed to a single recoverable item.

Trait Implementations§

Source§

impl Default for AdamAstParser

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Same for T

Source§

type Output = T

Should always be Self
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.