parse

Function parse 

Source
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:

  1. Lexing: The code is tokenized into a flat list of CirruLexItems.
  2. Indentation Resolution: The flat list of tokens is transformed into a tree structure by handling indentation.
  3. Tree Building: The token tree is converted into a tree of Cirru expressions.
  4. 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);