1use std::error::Error;
2use crate::token::Token;
3
4pub struct Parser<'a> {
5 data: Vec<Token<'a>>
6}
7
8impl<'a> Parser<'a> {
9 pub fn new(data: Vec<Token<'a>>) -> Self {
10 Parser {
11 data
12 }
13 }
14
15 pub fn run(&mut self) -> Result<(), Box<dyn Error>> {
16 let count = 0;
17 let iter = self.data.iter().clone();
18 for i in iter.clone() {
19 if i.to_string() == "export" {
21 let mut token = self.data[count + 1].to_string();
22 token = token.strip_prefix("Text(\"").unwrap().to_string();
23 token = token.strip_suffix("\")").unwrap().to_string();
24 token = token.replace("\\\"", "\"");
25
26 let key = token.rsplit_once("=").unwrap().0;
27 let text = token.rsplit_once("=").unwrap().1
28 .strip_prefix("\"").unwrap()
29 .strip_suffix("\"").unwrap();
30
31 std::env::set_var(key, text);
32 }
33
34 }
35 Ok(())
36 }
37}