|
|
@ -2,7 +2,7 @@ use debug_cell::RefCell;
|
|
|
|
use std::{collections::HashMap, rc::Rc};
|
|
|
|
use std::{collections::HashMap, rc::Rc};
|
|
|
|
|
|
|
|
|
|
|
|
use super::{
|
|
|
|
use super::{
|
|
|
|
command::{parse_command, Command, AssignType},
|
|
|
|
command::{parse_command, AssignType, Command},
|
|
|
|
control::{parse_control, Control},
|
|
|
|
control::{parse_control, Control},
|
|
|
|
event::Event,
|
|
|
|
event::Event,
|
|
|
|
token::Token,
|
|
|
|
token::Token,
|
|
|
@ -24,15 +24,19 @@ pub struct CommandContext {
|
|
|
|
|
|
|
|
|
|
|
|
impl CommandContext {
|
|
|
|
impl CommandContext {
|
|
|
|
pub fn execute(&self) -> Option<Event> {
|
|
|
|
pub fn execute(&self) -> Option<Event> {
|
|
|
|
use Command::*;
|
|
|
|
|
|
|
|
use AssignType::*;
|
|
|
|
use AssignType::*;
|
|
|
|
|
|
|
|
use Command::*;
|
|
|
|
Some(
|
|
|
|
Some(
|
|
|
|
match &self.command {
|
|
|
|
match &self.command {
|
|
|
|
Say { name, text } => Event::Say {
|
|
|
|
Say { name, text } => Event::Say {
|
|
|
|
name: name.clone(),
|
|
|
|
name: name.clone(),
|
|
|
|
text: text.clone(),
|
|
|
|
text: text.clone(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Command::Assign { assign_type, variable, value } => match assign_type {
|
|
|
|
Command::Assign {
|
|
|
|
|
|
|
|
assign_type,
|
|
|
|
|
|
|
|
variable,
|
|
|
|
|
|
|
|
value,
|
|
|
|
|
|
|
|
} => match assign_type {
|
|
|
|
Define => panic!("define command should not be executed at runtime!"),
|
|
|
|
Define => panic!("define command should not be executed at runtime!"),
|
|
|
|
GlobalAssign => {
|
|
|
|
GlobalAssign => {
|
|
|
|
if let Token::Keyword(_) = value {
|
|
|
|
if let Token::Keyword(_) = value {
|
|
|
@ -51,7 +55,7 @@ impl CommandContext {
|
|
|
|
.borrow_mut()
|
|
|
|
.borrow_mut()
|
|
|
|
.insert(variable.clone(), value.clone());
|
|
|
|
.insert(variable.clone(), value.clone());
|
|
|
|
return None;
|
|
|
|
return None;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
Let => {
|
|
|
|
Let => {
|
|
|
|
if let Token::Keyword(_) = value {
|
|
|
|
if let Token::Keyword(_) = value {
|
|
|
|
todo!("assignment variable interpolation isn't implemented");
|
|
|
|
todo!("assignment variable interpolation isn't implemented");
|
|
|
@ -62,14 +66,14 @@ impl CommandContext {
|
|
|
|
.borrow_mut()
|
|
|
|
.borrow_mut()
|
|
|
|
.insert(variable.clone(), value.clone());
|
|
|
|
.insert(variable.clone(), value.clone());
|
|
|
|
return None;
|
|
|
|
return None;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
Assign => {
|
|
|
|
Assign => {
|
|
|
|
if let Token::Keyword(_) = value {
|
|
|
|
if let Token::Keyword(_) = value {
|
|
|
|
todo!("assignment variable interpolation isn't implemented");
|
|
|
|
todo!("assignment variable interpolation isn't implemented");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
todo!("local variable assignment isn't implemented")
|
|
|
|
todo!("local variable assignment isn't implemented")
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Eat { .. } => return None,
|
|
|
|
Eat { .. } => return None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.process(&self.context),
|
|
|
|
.process(&self.context),
|
|
|
@ -187,7 +191,11 @@ pub fn parse_block(
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Rule::Line => BlockElement::Command(match parse_command(pair) {
|
|
|
|
Rule::Line => BlockElement::Command(match parse_command(pair) {
|
|
|
|
Command::Assign { variable, value, assign_type: AssignType::Define } => {
|
|
|
|
Command::Assign {
|
|
|
|
|
|
|
|
variable,
|
|
|
|
|
|
|
|
value,
|
|
|
|
|
|
|
|
assign_type: AssignType::Define,
|
|
|
|
|
|
|
|
} => {
|
|
|
|
let mut value = value;
|
|
|
|
let mut value = value;
|
|
|
|
if let Token::Keyword(keyword) = value {
|
|
|
|
if let Token::Keyword(keyword) = value {
|
|
|
|
value = definitions
|
|
|
|
value = definitions
|
|
|
|