diff options
| author | mat <github@matdoes.dev> | 2022-01-10 20:29:46 -0600 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-01-10 20:29:46 -0600 |
| commit | 60b129b3a62b66dd389d1775892405fe735b9540 (patch) | |
| tree | b6d977c8256ffbda97c3822e571ef7c65003750b /azalea-brigadier/src/tree | |
| parent | cb4d871f6f56a484dc87151ea3ad55f7e3bbed97 (diff) | |
| download | azalea-drasl-60b129b3a62b66dd389d1775892405fe735b9540.tar.xz | |
progress
Diffstat (limited to 'azalea-brigadier/src/tree')
| -rw-r--r-- | azalea-brigadier/src/tree/argument_command_node.rs | 24 | ||||
| -rw-r--r-- | azalea-brigadier/src/tree/command_node.rs | 28 | ||||
| -rw-r--r-- | azalea-brigadier/src/tree/literal_command_node.rs | 26 | ||||
| -rw-r--r-- | azalea-brigadier/src/tree/root_command_node.rs | 12 |
4 files changed, 51 insertions, 39 deletions
diff --git a/azalea-brigadier/src/tree/argument_command_node.rs b/azalea-brigadier/src/tree/argument_command_node.rs index 51add3d5..4d38b41f 100644 --- a/azalea-brigadier/src/tree/argument_command_node.rs +++ b/azalea-brigadier/src/tree/argument_command_node.rs @@ -1,7 +1,7 @@ use std::fmt::{Display, Formatter}; use crate::{ - arguments::argument_type::{ArgumentResult, ArgumentType}, + arguments::argument_type::ArgumentType, builder::required_argument_builder::RequiredArgumentBuilder, context::{ command_context::CommandContext, command_context_builder::CommandContextBuilder, @@ -21,25 +21,25 @@ const USAGE_ARGUMENT_OPEN: &str = "<"; const USAGE_ARGUMENT_CLOSE: &str = ">"; #[derive(Hash, PartialEq, Eq, Debug, Clone)] -pub struct ArgumentCommandNode<S, T> { +pub struct ArgumentCommandNode<'a, S, T> { name: String, - type_: Box<dyn ArgumentType<dyn ArgumentResult>>, - custom_suggestions: dyn SuggestionProvider<S>, + type_: &'a T, + custom_suggestions: &'a dyn SuggestionProvider<S, T>, // Since Rust doesn't have extending, we put the struct this is extending as the "base" field - pub base: BaseCommandNode<S>, + pub base: BaseCommandNode<'a, S, T>, } -impl<S, T> ArgumentCommandNode<S, T> { - fn get_type(&self) -> &dyn ArgumentType<dyn ArgumentResult> { +impl<S, T> ArgumentCommandNode<'_, S, T> { + fn get_type(&self) -> &T { &self.type_ } - fn custom_suggestions(&self) -> &dyn SuggestionProvider<S> { + fn custom_suggestions(&self) -> &dyn SuggestionProvider<S, T> { &self.custom_suggestions } } -impl<S, T> CommandNode<S> for ArgumentCommandNode<S, T> { +impl<S, T> CommandNode<S, T> for ArgumentCommandNode<'_, S, T> { fn name(&self) -> &str { &self.name } @@ -47,7 +47,7 @@ impl<S, T> CommandNode<S> for ArgumentCommandNode<S, T> { fn parse( &self, reader: &mut StringReader, - context_builder: CommandContextBuilder<S>, + context_builder: CommandContextBuilder<S, T>, ) -> Result<(), CommandSyntaxException> { // final int start = reader.getCursor(); // final T result = type.parse(reader); @@ -68,7 +68,7 @@ impl<S, T> CommandNode<S> for ArgumentCommandNode<S, T> { fn list_suggestions( &self, - context: CommandContext<S>, + context: CommandContext<S, T>, builder: &mut SuggestionsBuilder, ) -> Result<Suggestions, CommandSyntaxException> { if self.custom_suggestions.is_none() { @@ -112,7 +112,7 @@ impl<S, T> CommandNode<S> for ArgumentCommandNode<S, T> { } } -impl Display for ArgumentCommandNode<String, String> { +impl Display for ArgumentCommandNode<'_, String, String> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "<argument {}: {}>", self.name, self.type_) } diff --git a/azalea-brigadier/src/tree/command_node.rs b/azalea-brigadier/src/tree/command_node.rs index 0d9212aa..bcba9c03 100644 --- a/azalea-brigadier/src/tree/command_node.rs +++ b/azalea-brigadier/src/tree/command_node.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use crate::{ - arguments::argument_type::{ArgumentResult, ArgumentType}, + arguments::argument_type::ArgumentType, builder::argument_builder::ArgumentBuilder, command::Command, context::{command_context::CommandContext, command_context_builder::CommandContextBuilder}, @@ -13,33 +13,33 @@ use crate::{ use super::{argument_command_node::ArgumentCommandNode, literal_command_node::LiteralCommandNode}; -pub struct BaseCommandNode<S> { - children: HashMap<String, dyn CommandNode<S>>, - literals: HashMap<String, LiteralCommandNode<S>>, - arguments: HashMap<String, ArgumentCommandNode<S, dyn ArgumentType<ArgumentResult>>>, - requirement: Option<dyn Fn(&S) -> bool>, - redirect: Option<dyn CommandNode<S>>, - modifier: Option<dyn RedirectModifier<S>>, +pub struct BaseCommandNode<'a, S, T> { + children: HashMap<String, &'a dyn CommandNode<S, T>>, + literals: HashMap<String, LiteralCommandNode<'a, S, T>>, + arguments: HashMap<String, ArgumentCommandNode<'a, S, T>>, + requirement: Option<&'a dyn Fn(&S) -> bool>, + redirect: Option<&'a dyn CommandNode<S, T>>, + modifier: Option<&'a dyn RedirectModifier<S, T>>, forks: bool, - command: Option<dyn Command<S>>, + command: Option<&'a dyn Command<S, T>>, } -impl<S> BaseCommandNode<S> {} +impl<S, T> BaseCommandNode<'_, S, T> {} -pub trait CommandNode<S> { +pub trait CommandNode<S, T> { fn name(&self) -> &str; fn usage_text(&self) -> &str; fn parse( &self, reader: StringReader, - context_builder: CommandContextBuilder<S>, + context_builder: CommandContextBuilder<S, T>, ) -> Result<(), CommandSyntaxException>; fn list_suggestions( &self, - context: CommandContext<S>, + context: CommandContext<S, T>, builder: SuggestionsBuilder, ) -> Result<Suggestions, CommandSyntaxException>; fn is_valid_input(&self, input: &str) -> bool; - fn create_builder<T>(&self) -> dyn ArgumentBuilder<S, T>; + fn create_builder(&self) -> dyn ArgumentBuilder<S, T>; fn get_examples(&self) -> Vec<String>; } diff --git a/azalea-brigadier/src/tree/literal_command_node.rs b/azalea-brigadier/src/tree/literal_command_node.rs index bb0e613c..fe933669 100644 --- a/azalea-brigadier/src/tree/literal_command_node.rs +++ b/azalea-brigadier/src/tree/literal_command_node.rs @@ -1,8 +1,11 @@ use crate::{ + builder::literal_argument_builder::LiteralArgumentBuilder, + command::Command, context::{command_context::CommandContext, command_context_builder::CommandContextBuilder}, exceptions::{ builtin_exceptions::BuiltInExceptions, command_syntax_exception::CommandSyntaxException, }, + redirect_modifier::RedirectModifier, string_reader::StringReader, suggestion::{suggestions::Suggestions, suggestions_builder::SuggestionsBuilder}, }; @@ -10,14 +13,23 @@ use crate::{ use super::command_node::{BaseCommandNode, CommandNode}; #[derive(Hash, PartialEq, Eq, Debug, Clone)] -pub struct LiteralCommandNode<S> { +pub struct LiteralCommandNode<'a, S, T> { literal: String, literal_lowercase: String, // Since Rust doesn't have extending, we put the struct this is extending as the "base" field - pub base: BaseCommandNode<S>, + pub base: BaseCommandNode<'a, S, T>, } -impl<S> LiteralCommandNode<S> { +impl<'a, S, T> LiteralCommandNode<'a, S, T> { + pub fn new(literal: String, base: BaseCommandNode<S, T>) -> Self { + let literal_lowercase = literal.to_lowercase(); + Self { + literal, + literal_lowercase, + base, + } + } + pub fn literal(&self) -> &String { &self.literal } @@ -39,7 +51,7 @@ impl<S> LiteralCommandNode<S> { } } -impl<S> CommandNode<S> for LiteralCommandNode<S> { +impl<S, T> CommandNode<S, T> for LiteralCommandNode<'_, S, T> { fn name(&self) -> &str { &self.literal } @@ -47,7 +59,7 @@ impl<S> CommandNode<S> for LiteralCommandNode<S> { fn parse( &self, reader: StringReader, - context_builder: CommandContextBuilder<S>, + context_builder: CommandContextBuilder<S, T>, ) -> Result<(), CommandSyntaxException> { let start = reader.get_cursor(); let end = self.parse(reader); @@ -63,7 +75,7 @@ impl<S> CommandNode<S> for LiteralCommandNode<S> { fn list_suggestions( &self, - context: CommandContext<S>, + context: CommandContext<S, T>, builder: SuggestionsBuilder, ) -> Result<Suggestions, CommandSyntaxException> { if self @@ -84,7 +96,7 @@ impl<S> CommandNode<S> for LiteralCommandNode<S> { self.literal } - fn create_builder(&self) -> LiteralArgumentBuilder<S> { + fn create_builder(&self) -> LiteralArgumentBuilder<S, T> { let builder = LiteralArgumentBuilder::literal(self.literal()); builder.requires(self.requirement()); builder.forward(self.redirect(), self.redirect_modifier(), self.is_fork()); diff --git a/azalea-brigadier/src/tree/root_command_node.rs b/azalea-brigadier/src/tree/root_command_node.rs index 004ab6a8..25a5a4b2 100644 --- a/azalea-brigadier/src/tree/root_command_node.rs +++ b/azalea-brigadier/src/tree/root_command_node.rs @@ -12,12 +12,12 @@ use crate::{ use super::command_node::{BaseCommandNode, CommandNode}; #[derive(Hash, PartialEq, Eq, Debug, Clone)] -pub struct RootCommandNode<S> { +pub struct RootCommandNode<'a, S, T> { // Since Rust doesn't have extending, we put the struct this is extending as the "base" field - pub base: BaseCommandNode<S>, + pub base: BaseCommandNode<'a, S, T>, } -impl<S> CommandNode<S> for RootCommandNode<S> { +impl<S, T> CommandNode<S, T> for RootCommandNode<'_, S, T> { fn name(&self) -> &str { "" } @@ -25,13 +25,13 @@ impl<S> CommandNode<S> for RootCommandNode<S> { fn parse( &self, reader: StringReader, - context_builder: CommandContextBuilder<S>, + context_builder: CommandContextBuilder<S, T>, ) -> Result<(), CommandSyntaxException> { } fn list_suggestions( &self, - context: CommandContext<S>, + context: CommandContext<S, T>, builder: SuggestionsBuilder, ) -> Result<Suggestions, CommandSyntaxException> { Suggestions::empty() @@ -54,7 +54,7 @@ impl<S> CommandNode<S> for RootCommandNode<S> { } } -impl Display for RootCommandNode<()> { +impl<S, T> Display for RootCommandNode<'_, S, T> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "<root>") } |
