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 performs no semantic validation during parsing.
§Examples
See Self for parsing an annotated cell without an operation environment.
Sourcepub fn parse_str(&mut self, source: &str) -> Result<Sheet, ParseError>
pub fn parse_str(&mut self, source: &str) -> Result<Sheet, ParseError>
Parses exactly one root sheet 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), imports, multiple definitions, or a component signature. Use
Self::parse_module_str for complete modules.
- Complexity: O(n) source scanning and AST storage for n source bytes, plus delegated CEL expression parsing.
§Examples
let mut parser = adam_lang::AdamAstParser::new();
assert_eq!(parser.parse_str("sheet root {}").unwrap().name, "root");
assert!(parser.parse_str("sheet helper() {}").is_err());
assert!(parser.parse_str("sheet a {} sheet b {}").is_err());Sourcepub fn parse_module_str(&mut self, source: &str) -> Result<Module, ParseError>
pub fn parse_module_str(&mut self, source: &str) -> Result<Module, ParseError>
Parses module = { use_decl | sheet }, recovering at the next file declaration.
Names and types remain unresolved; expressions are parsed without execution.
§Errors
Returns an error when tokenization fails. Grammar errors populate Module.errors.
- Complexity: O(n) in source and AST size, excluding embedded CEL parsing.
§Examples
let module = adam_lang::AdamAstParser::new()
.parse_module_str("use lib::helper; sheet helper() {} sheet root {}").unwrap();
assert_eq!(module.items.len(), 3);
assert!(module.errors.is_empty());