Implement importing of specific names
This commit is contained in:
parent
d11d5ce755
commit
dab95136c4
42
src/main.rs
42
src/main.rs
|
@ -149,14 +149,44 @@ impl Program {
|
||||||
let contents = fs::read_to_string(filename).expect("Something went wrong reading the file");
|
let contents = fs::read_to_string(filename).expect("Something went wrong reading the file");
|
||||||
let mut prog = Program::from_string(contents);
|
let mut prog = Program::from_string(contents);
|
||||||
prog.run();
|
prog.run();
|
||||||
|
|
||||||
for (key, value) in prog.vars.iter() {
|
|
||||||
self.vars.insert(*key, value.to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (key, value) in prog.funcs.iter() {
|
if argument_vec.len() > 1 {
|
||||||
self.funcs.insert(*key, value.to_string());
|
for name in argument_vec[1..].iter() {
|
||||||
|
let kind = name.chars().nth(0).unwrap();
|
||||||
|
let name_to_import = name.chars().nth(1).unwrap();
|
||||||
|
if kind == 'v' {
|
||||||
|
let key = prog.vars.get(&name_to_import);
|
||||||
|
match key {
|
||||||
|
Some(value) => self.vars.insert(name_to_import, value.to_string()),
|
||||||
|
None => panic!("ValueError: variable {} has not been defined in {}!", name_to_import, filename)
|
||||||
|
};
|
||||||
|
} else if kind == 'f' {
|
||||||
|
let key = prog.funcs.get(&name_to_import);
|
||||||
|
match key {
|
||||||
|
Some(value) => {self.funcs.insert(name_to_import, value.to_string());()},
|
||||||
|
None => panic!("ValueError: function {} has not been defined in {}!", name_to_import, filename)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// implied catch-all
|
||||||
|
for (key, value) in prog.vars.iter() {
|
||||||
|
self.vars.insert(*key, value.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (key, value) in prog.funcs.iter() {
|
||||||
|
self.funcs.insert(*key, value.to_string());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// for (key, value) in prog.vars.iter() {
|
||||||
|
// self.vars.insert(*key, value.to_string());
|
||||||
|
// }
|
||||||
|
|
||||||
|
// for (key, value) in prog.funcs.iter() {
|
||||||
|
// self.funcs.insert(*key, value.to_string());
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse(&mut self, instruction: &String) {
|
fn parse(&mut self, instruction: &String) {
|
||||||
|
|
Loading…
Reference in New Issue