|
|
@ -1,11 +1,12 @@
|
|
|
|
use std::{collections::HashMap, rc::Rc};
|
|
|
|
|
|
|
|
use debug_cell::RefCell;
|
|
|
|
use debug_cell::RefCell;
|
|
|
|
|
|
|
|
use std::{collections::HashMap, rc::Rc};
|
|
|
|
|
|
|
|
|
|
|
|
use super::{
|
|
|
|
use super::{
|
|
|
|
command::{parse_command, Command},
|
|
|
|
command::{parse_command, Command},
|
|
|
|
control::{parse_control, Control},
|
|
|
|
control::{parse_control, Control},
|
|
|
|
|
|
|
|
event::Event,
|
|
|
|
token::Token,
|
|
|
|
token::Token,
|
|
|
|
Pair, Rule, event::Event,
|
|
|
|
Pair, Rule,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
pub struct CommandBlock {
|
|
|
|
pub struct CommandBlock {
|
|
|
@ -35,24 +36,21 @@ impl CommandContext {
|
|
|
|
if let Token::Keyword(_) = value {
|
|
|
|
if let Token::Keyword(_) = value {
|
|
|
|
todo!("assignment variable interpolation isn't implemented");
|
|
|
|
todo!("assignment variable interpolation isn't implemented");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let root = self.context
|
|
|
|
let root = self.context.borrow().get_root(&self.context);
|
|
|
|
.borrow()
|
|
|
|
|
|
|
|
.get_root(&self.context);
|
|
|
|
|
|
|
|
// Don't want to re-borrow if root is self
|
|
|
|
// Don't want to re-borrow if root is self
|
|
|
|
let root = if Rc::ptr_eq(&self.context, &root) {
|
|
|
|
let root = if Rc::ptr_eq(&self.context, &root) {
|
|
|
|
&self.context
|
|
|
|
&self.context
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
&root
|
|
|
|
&root
|
|
|
|
};
|
|
|
|
};
|
|
|
|
root
|
|
|
|
root.borrow_mut()
|
|
|
|
.borrow_mut()
|
|
|
|
|
|
|
|
.variables
|
|
|
|
.variables
|
|
|
|
.as_ref()
|
|
|
|
.as_ref()
|
|
|
|
.unwrap()
|
|
|
|
.unwrap()
|
|
|
|
.borrow_mut()
|
|
|
|
.borrow_mut()
|
|
|
|
.insert(variable.clone(), value.clone());
|
|
|
|
.insert(variable.clone(), value.clone());
|
|
|
|
return None;
|
|
|
|
return None;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
Eat { .. } => return None,
|
|
|
|
Eat { .. } => return None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.process(&self.context),
|
|
|
|
.process(&self.context),
|
|
|
@ -118,7 +116,7 @@ impl CommandBlock {
|
|
|
|
None => HashMap::new(),
|
|
|
|
None => HashMap::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn get_root(&self, self_rc: &Rc<RefCell<Self>>) -> Rc<RefCell<Self>> {
|
|
|
|
pub fn get_root(&self, self_rc: &Rc<RefCell<Self>>) -> Rc<RefCell<Self>> {
|
|
|
|
if let Some(parent) = &self.parent {
|
|
|
|
if let Some(parent) = &self.parent {
|
|
|
|
parent.borrow().get_root(&parent)
|
|
|
|
parent.borrow().get_root(&parent)
|
|
|
|