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
impl AdamAstParser
Sourcepub fn new() -> Self
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.
Sourcepub fn parse_str(&mut self, source: &str) -> Result<Sheet, ParseError>
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.