celestial_hub_compass/utils/
mod.rs

1use crate::{lexer::Lexer, parser::Parser};
2
3pub fn ast_from_code_str(code: &str, test_name: &str) -> String {
4  let ast = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
5    let lexer = Lexer::new(code, test_name).expect("Lexer to not fail in tests");
6    Parser::new().parse(lexer)
7  }));
8
9  match ast.unwrap() {
10    Ok(ast) => format!("{:#?}", ast),
11    Err(err) => format!("{:#?}", err),
12  }
13}