use super::{Token, Class}; use std::collections::HashMap; pub fn format(tree: Vec) -> HashMap { let mut output = HashMap::new(); let mut current_key = "".to_string(); let mut current_index = 0; let mut i = 0; while i < tree.len() { if tree[i].class == Class::IDENTIFIER { current_key = tree[i].value.clone().unwrap_or("".to_string()); i = i + 1; continue; } if tree[i].class == Class::LITERAL && current_key != "".to_string() { output.insert(current_key, tree[i].value.clone().unwrap_or("".to_string())); current_key = "".to_string(); i = i + 1; continue; } if tree[i].class == Class::SEPARATOR && current_key != "".to_string() && tree[i].value.clone().unwrap_or("".to_string()) == "[".to_string() { current_index = 0; loop { i = i + 1; output.insert(format!("{}[{}]", current_key, current_index), tree[i].value.clone().unwrap_or("".to_string())); current_index = current_index + 1; i = i + 1; if tree[i].class == Class::SEPARATOR && tree[i].value.clone().unwrap_or("".to_string()) == ",".to_string() { continue; } else { break; } } } i = i + 1; } return output; }