pub fn parse(code: &str) -> Result<Vec<Cirru>, String>Expand description
Parses a string of Cirru code into a tree of Cirru expressions.
This is the main entry point for the parser. It performs the following steps:
- Lexing: The code is tokenized into a flat list of
CirruLexItems. - Indentation Resolution: The flat list of tokens is transformed into a tree structure by handling indentation.
- Tree Building: The token tree is converted into a tree of
Cirruexpressions. - Syntax Resolution: Special syntax like
$and,is resolved.
ยงExamples
let code = "defn main\n println \"Hello, world!\"";
let expected = Ok(vec![
Cirru::List(vec![
Cirru::Leaf("defn".into()),
Cirru::Leaf("main".into()),
Cirru::List(vec![
Cirru::Leaf("println".into()),
Cirru::Leaf("Hello, world!".into()),
]),
]),
]);
assert_eq!(parse(code), expected);