|
|
@ -31,13 +31,28 @@ use Token::*;
|
|
|
|
|
|
|
|
|
|
|
|
// Parsed script commands
|
|
|
|
// Parsed script commands
|
|
|
|
#[derive(Debug)]
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Command {
|
|
|
|
#[allow(dead_code)]
|
|
|
|
|
|
|
|
enum Command {
|
|
|
|
Say { name: Option<String>, text: String },
|
|
|
|
Say { name: Option<String>, text: String },
|
|
|
|
Eat { food: String, politely: bool },
|
|
|
|
Eat { food: String, politely: bool },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
use Command::*;
|
|
|
|
use Command::*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Command {
|
|
|
|
|
|
|
|
fn is_blocking(&self) -> bool {
|
|
|
|
|
|
|
|
match self {
|
|
|
|
|
|
|
|
Say { .. } => true,
|
|
|
|
|
|
|
|
_ => false,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
|
|
|
pub enum Event {
|
|
|
|
|
|
|
|
Say { name: Option<String>, text: String },
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Tokenize raw script string
|
|
|
|
// Tokenize raw script string
|
|
|
|
fn tokenize(script: &str) -> Vec<Vec<Token>> {
|
|
|
|
fn tokenize(script: &str) -> Vec<Vec<Token>> {
|
|
|
|
let file = RpyParser::parse(Rule::file, script)
|
|
|
|
let file = RpyParser::parse(Rule::file, script)
|
|
|
@ -159,7 +174,19 @@ impl State {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn next_command(&mut self) -> Option<Command> {
|
|
|
|
pub fn next(&mut self) -> Option<Event> {
|
|
|
|
|
|
|
|
while let Some(command) = self.next_command() {
|
|
|
|
|
|
|
|
if command.is_blocking() {
|
|
|
|
|
|
|
|
return Some(match command {
|
|
|
|
|
|
|
|
Say { name, text } => Event::Say { name, text },
|
|
|
|
|
|
|
|
_ => unimplemented!(),
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
None
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn next_command(&mut self) -> Option<Command> {
|
|
|
|
if self.command_queue.len() == 0 {
|
|
|
|
if self.command_queue.len() == 0 {
|
|
|
|
None
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|