From 69f97dbf02e5422ee796492a3633a4e8f3f09d2d Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 31 Jul 2022 18:05:41 -0500 Subject: clippo the sequel --- azalea-brigadier/src/builder/argument_builder.rs | 8 ++++++-- azalea-brigadier/src/context/command_context.rs | 7 +++++-- azalea-brigadier/src/context/command_context_builder.rs | 13 +++++++------ azalea-brigadier/src/exceptions/command_syntax_exception.rs | 12 ++++++++---- azalea-brigadier/src/tree/mod.rs | 8 +++++--- 5 files changed, 31 insertions(+), 17 deletions(-) (limited to 'azalea-brigadier/src') diff --git a/azalea-brigadier/src/builder/argument_builder.rs b/azalea-brigadier/src/builder/argument_builder.rs index d26b2a8a..38ccc98c 100755 --- a/azalea-brigadier/src/builder/argument_builder.rs +++ b/azalea-brigadier/src/builder/argument_builder.rs @@ -1,4 +1,8 @@ -use crate::{context::CommandContext, modifier::RedirectModifier, tree::CommandNode}; +use crate::{ + context::CommandContext, + modifier::RedirectModifier, + tree::{Command, CommandNode}, +}; use super::{literal_argument_builder::Literal, required_argument_builder::Argument}; use std::{cell::RefCell, fmt::Debug, rc::Rc}; @@ -13,7 +17,7 @@ pub enum ArgumentBuilderType { pub struct ArgumentBuilder { arguments: CommandNode, - command: Option) -> i32>>, + command: Command, requirement: Rc) -> bool>, target: Option>>>, diff --git a/azalea-brigadier/src/context/command_context.rs b/azalea-brigadier/src/context/command_context.rs index 1834a73d..98609a6e 100755 --- a/azalea-brigadier/src/context/command_context.rs +++ b/azalea-brigadier/src/context/command_context.rs @@ -1,5 +1,8 @@ use super::{parsed_command_node::ParsedCommandNode, string_range::StringRange, ParsedArgument}; -use crate::{modifier::RedirectModifier, tree::CommandNode}; +use crate::{ + modifier::RedirectModifier, + tree::{Command, CommandNode}, +}; use std::{any::Any, cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc}; /// A built `CommandContextBuilder`. @@ -7,7 +10,7 @@ pub struct CommandContext { pub source: Rc, pub input: String, pub arguments: HashMap, - pub command: Option) -> i32>>, + pub command: Command, pub root_node: Rc>>, pub nodes: Vec>, pub range: StringRange, diff --git a/azalea-brigadier/src/context/command_context_builder.rs b/azalea-brigadier/src/context/command_context_builder.rs index f192f6b7..7516ab9e 100755 --- a/azalea-brigadier/src/context/command_context_builder.rs +++ b/azalea-brigadier/src/context/command_context_builder.rs @@ -2,7 +2,11 @@ use super::{ command_context::CommandContext, parsed_command_node::ParsedCommandNode, string_range::StringRange, ParsedArgument, }; -use crate::{command_dispatcher::CommandDispatcher, modifier::RedirectModifier, tree::CommandNode}; +use crate::{ + command_dispatcher::CommandDispatcher, + modifier::RedirectModifier, + tree::{Command, CommandNode}, +}; use std::{cell::RefCell, collections::HashMap, fmt::Debug, rc::Rc}; pub struct CommandContextBuilder { @@ -11,7 +15,7 @@ pub struct CommandContextBuilder { pub nodes: Vec>, pub dispatcher: Rc>, pub source: Rc, - pub command: Option) -> i32>>, + pub command: Command, pub child: Option>>, pub range: StringRange, pub modifier: Option>>, @@ -56,10 +60,7 @@ impl CommandContextBuilder { } } - pub fn with_command( - &mut self, - command: &Option) -> i32>>, - ) -> &Self { + pub fn with_command(&mut self, command: &Command) -> &Self { self.command = command.clone(); self } diff --git a/azalea-brigadier/src/exceptions/command_syntax_exception.rs b/azalea-brigadier/src/exceptions/command_syntax_exception.rs index 4bfe9cda..14376a87 100755 --- a/azalea-brigadier/src/exceptions/command_syntax_exception.rs +++ b/azalea-brigadier/src/exceptions/command_syntax_exception.rs @@ -1,7 +1,9 @@ -use std::{cmp, fmt}; - use super::builtin_exceptions::BuiltInExceptions; use crate::message::Message; +use std::{ + cmp, + fmt::{self, Write}, +}; #[derive(Clone, PartialEq)] pub struct CommandSyntaxException { @@ -36,11 +38,13 @@ impl CommandSyntaxException { let mut message = self.message.string(); let context = self.context(); if let Some(context) = context { - message.push_str(&format!( + write!( + message, " at position {}: {}", self.cursor.unwrap_or(usize::MAX), context - )); + ) + .unwrap(); } message } diff --git a/azalea-brigadier/src/tree/mod.rs b/azalea-brigadier/src/tree/mod.rs index b6181c73..ef2573b9 100755 --- a/azalea-brigadier/src/tree/mod.rs +++ b/azalea-brigadier/src/tree/mod.rs @@ -10,6 +10,8 @@ use crate::{ }; use std::{cell::RefCell, collections::HashMap, fmt::Debug, hash::Hash, ptr, rc::Rc}; +pub type Command = Option) -> i32>>; + /// An ArgumentBuilder that has been built. #[non_exhaustive] pub struct CommandNode { @@ -19,7 +21,7 @@ pub struct CommandNode { pub literals: HashMap>>>, pub arguments: HashMap>>>, - pub command: Option) -> i32>>, + pub command: Command, pub requirement: Rc) -> bool>, pub redirect: Option>>>, pub forks: bool, @@ -75,9 +77,9 @@ impl CommandNode { input.cursor = cursor; let literal = literals.get(&text); if let Some(literal) = literal { - return vec![literal.clone()]; + vec![literal.clone()] } else { - return self.arguments.values().cloned().collect(); + self.arguments.values().cloned().collect() } } else { self.arguments.values().cloned().collect() -- cgit v1.2.3