From 149842c121851ad6bc9e005ade264ccc37b6ddbf Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Tue, 30 May 2023 12:34:50 -0700 Subject: [PATCH] cargo fmt --- renrs/src/lib.rs | 2 +- renrs/src/parser/block.rs | 24 ++++++++++++++++-------- renrs/src/parser/command.rs | 22 +++++++++------------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/renrs/src/lib.rs b/renrs/src/lib.rs index ffff5ec..4824cf7 100644 --- a/renrs/src/lib.rs +++ b/renrs/src/lib.rs @@ -33,4 +33,4 @@ impl Iterator for State { } None } -} \ No newline at end of file +} diff --git a/renrs/src/parser/block.rs b/renrs/src/parser/block.rs index 5dab512..e355b25 100644 --- a/renrs/src/parser/block.rs +++ b/renrs/src/parser/block.rs @@ -2,7 +2,7 @@ use debug_cell::RefCell; use std::{collections::HashMap, rc::Rc}; use super::{ - command::{parse_command, Command, AssignType}, + command::{parse_command, AssignType, Command}, control::{parse_control, Control}, event::Event, token::Token, @@ -24,15 +24,19 @@ pub struct CommandContext { impl CommandContext { pub fn execute(&self) -> Option { - use Command::*; use AssignType::*; + use Command::*; Some( match &self.command { Say { name, text } => Event::Say { name: name.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!"), GlobalAssign => { if let Token::Keyword(_) = value { @@ -51,7 +55,7 @@ impl CommandContext { .borrow_mut() .insert(variable.clone(), value.clone()); return None; - }, + } Let => { if let Token::Keyword(_) = value { todo!("assignment variable interpolation isn't implemented"); @@ -62,14 +66,14 @@ impl CommandContext { .borrow_mut() .insert(variable.clone(), value.clone()); return None; - }, + } Assign => { if let Token::Keyword(_) = value { todo!("assignment variable interpolation isn't implemented"); } todo!("local variable assignment isn't implemented") - }, - } + } + }, Eat { .. } => return None, } .process(&self.context), @@ -187,7 +191,11 @@ pub fn parse_block( continue; } 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; if let Token::Keyword(keyword) = value { value = definitions diff --git a/renrs/src/parser/command.rs b/renrs/src/parser/command.rs index 99c886e..0c3cba6 100644 --- a/renrs/src/parser/command.rs +++ b/renrs/src/parser/command.rs @@ -64,19 +64,15 @@ pub fn parse_command(pair: Pair) -> Command { name: Some(name.clone()), text: text.clone(), }, - // https://github.com/rust-lang/rust/issues/51114 - [Keyword(keyword), Keyword(variable), Keyword(equals), value] - if equals.eq("=") => - { - Assign { - assign_type: match keyword.parse() { - Ok(assign_type) => assign_type, - Err(_) => unknown!(), - }, - variable: variable.clone(), - value: value.clone(), - } - } + // https://github.com/rust-lang/rust/issues/51114 + [Keyword(keyword), Keyword(variable), Keyword(equals), value] if equals.eq("=") => Assign { + assign_type: match keyword.parse() { + Ok(assign_type) => assign_type, + Err(_) => unknown!(), + }, + variable: variable.clone(), + value: value.clone(), + }, [Keyword(keyword), Str(food), tail @ ..] if keyword.eq("eat") => Eat { food: food.to_owned(), politely: match tail {