27 lines
914 B
Rust
27 lines
914 B
Rust
|
|
use super::runtime::*;
|
||
|
|
use super::parser::*;
|
||
|
|
use std::error::Error;
|
||
|
|
use std::collections::HashMap;
|
||
|
|
use std::rc::Rc;
|
||
|
|
|
||
|
|
fn cat_vec(arr: Vec<String>) -> String {
|
||
|
|
let total_len: usize = arr.iter().map(|s| { s.len() }).sum();
|
||
|
|
arr.into_iter().fold(String::with_capacity(total_len), |mut acc, p| { acc.push_str(p.as_str()); acc })
|
||
|
|
}
|
||
|
|
|
||
|
|
/* This function is supposed to compile all elements in one particular file */
|
||
|
|
pub fn plemege_to_value(mut x: Plemege, file_path: &str) -> Result<Value, Box<dyn Error>> {
|
||
|
|
match x {
|
||
|
|
Plemege::Package(map) => {
|
||
|
|
let mut new_dict: HashMap<String, Value> = HashMap::new();
|
||
|
|
for (key, thing) in map {
|
||
|
|
new_dict.insert(key, plemege_to_value(thing, file_path)?);
|
||
|
|
}
|
||
|
|
Ok(Value::Dict(Rc::new(new_dict)))
|
||
|
|
},
|
||
|
|
Plemege::Element(el) => {
|
||
|
|
// todo
|
||
|
|
Ok(Value::default())
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|