main
Elnu 2 years ago
parent 2735a391b8
commit 77bc3b4b09

@ -7,7 +7,7 @@ use std::{
use renrs::State;
use egui_sfml::{SfEgui, egui};
use egui_sfml::{egui, SfEgui};
use sfml::{
graphics::{Color, RectangleShape, RenderTarget, RenderWindow, Transformable},
system::Vector2f,

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

@ -38,7 +38,7 @@ pub fn parse_command(pair: Pair) -> Command {
variable: variable.clone(),
value: value.clone(),
}
},
}
[Keyword(keyword), Keyword(variable), Keyword(equals), value]
if keyword.eq("$") && equals.eq("=") =>
{
@ -46,7 +46,7 @@ pub fn parse_command(pair: Pair) -> Command {
variable: variable.clone(),
value: value.clone(),
}
},
}
[Keyword(keyword), Str(food), tail @ ..] if keyword.eq("eat") => Eat {
food: food.to_owned(),
politely: match tail {

@ -1,5 +1,5 @@
use std::{collections::HashMap, rc::Rc};
use debug_cell::RefCell;
use std::{collections::HashMap, rc::Rc};
use regex::Regex;
@ -28,7 +28,7 @@ impl Event {
.as_deref()
.map(|name| interpolate_string(&name, &variables));
*text = interpolate_string(&text, &variables);
},
}
}
self
}

@ -7,8 +7,8 @@ mod utils;
pub type Pair<'a> = pest::iterators::Pair<'a, Rule>;
use std::{fs, path::PathBuf, rc::Rc};
use debug_cell::RefCell;
use std::{fs, path::PathBuf, rc::Rc};
pub use pest::Parser;
use pest_derive::Parser;

Loading…
Cancel
Save