1mod ast;
2mod compute;
3mod parser;
4mod prelude;
5mod require_dynamic_lib;
6mod string_parser;
7use std::collections::BTreeMap;
8
9use adana_script_core::TreeNodeValue;
10pub use compute::compute;
11
12use slab_tree::Tree;
13
14use crate::ast::to_ast;
15use crate::parser::parse_instructions;
16
17pub fn print_ast(script: &str) -> anyhow::Result<()> {
18 let (rest, instructions) = parse_instructions(script).map_err(|e| {
19 anyhow::Error::msg(format!(
20 "PRINT AST ERROR: could not parse instructions. {e}",
21 ))
22 })?;
23
24 anyhow::ensure!(
25 rest.trim().is_empty(),
26 format!(
27 "PRINT AST ERROR: rest is not empty! {instructions:#?} => {rest}",
28 )
29 );
30
31 let mut dummy_ctx = BTreeMap::new();
32 for instruction in instructions {
33 let mut tree: Tree<TreeNodeValue> = Tree::new();
34
35 println!("==================INSTRUCTION================");
36 println!("{instruction:#?}");
37 to_ast(&mut dummy_ctx, instruction, &mut tree, &None)?;
38
39 let mut tree_fmt = String::new();
40 tree.write_formatted(&mut tree_fmt)?;
41 println!("===================AST TREE==================");
42 print!("{tree_fmt}");
43 }
44 Ok(())
45}
46
47#[cfg(test)]
49mod tests;