diff options
| author | Ubuntu <github@matdoes.dev> | 2022-01-13 00:43:09 +0000 |
|---|---|---|
| committer | Ubuntu <github@matdoes.dev> | 2022-01-13 00:43:09 +0000 |
| commit | eb111be1f107696939b994f5de6e060cf972a732 (patch) | |
| tree | 055deab4179088c5e91a179bfe465a7859c45ab6 /azalea-brigadier/src/context | |
| parent | 270507736af57aae6801dc9eb3c3132139d0d07b (diff) | |
| download | azalea-drasl-eb111be1f107696939b994f5de6e060cf972a732.tar.xz | |
a
Diffstat (limited to 'azalea-brigadier/src/context')
5 files changed, 48 insertions, 57 deletions
diff --git a/azalea-brigadier/src/context/command_context.rs b/azalea-brigadier/src/context/command_context.rs index 68144a40..4f0b4d49 100644 --- a/azalea-brigadier/src/context/command_context.rs +++ b/azalea-brigadier/src/context/command_context.rs @@ -6,22 +6,22 @@ use crate::{ arguments::argument_type::ArgumentType, command::Command, redirect_modifier::RedirectModifier, tree::command_node::CommandNode, }; -use std::collections::HashMap; +use std::{any::Any, collections::HashMap}; -pub struct CommandContext<'a, S, T> { +pub struct CommandContext<'a, S> { source: S, input: String, - command: &'a dyn Command<S, T>, - arguments: HashMap<String, ParsedArgument<T>>, - root_node: &'a dyn CommandNode<S, T>, - nodes: Vec<ParsedCommandNode<S, T>>, + command: &'a dyn Command<S>, + arguments: HashMap<String, ParsedArgument<Box<dyn Any>>>, + root_node: &'a dyn CommandNode<S>, + nodes: Vec<ParsedCommandNode<S>>, range: StringRange, - child: Option<&'a CommandContext<'a, S, T>>, - modifier: Option<&'a dyn RedirectModifier<S, T>>, + child: Option<&'a CommandContext<'a, S>>, + modifier: Option<&'a dyn RedirectModifier<S>>, forks: bool, } -impl<S, T> CommandContext<'_, S, T> +impl<S> CommandContext<'_, S> where S: PartialEq, { @@ -43,11 +43,11 @@ where } } - fn child(&self) -> &Option<CommandContext<S, T>> { + fn child(&self) -> &Option<CommandContext<S>> { &self.child } - fn last_child(&self) -> &CommandContext<S, T> { + fn last_child(&self) -> &CommandContext<S> { let mut result = self; while result.child.is_some() { result = result.child.as_ref().unwrap(); @@ -55,7 +55,7 @@ where result } - fn command(&self) -> &dyn Command<S, T> { + fn command(&self) -> &dyn Command<S> { &self.command } diff --git a/azalea-brigadier/src/context/command_context_builder.rs b/azalea-brigadier/src/context/command_context_builder.rs index 639a97ee..95da4064 100644 --- a/azalea-brigadier/src/context/command_context_builder.rs +++ b/azalea-brigadier/src/context/command_context_builder.rs @@ -1,10 +1,8 @@ -use std::collections::HashMap; +use std::{any::Any, collections::HashMap}; use crate::{ - arguments::argument_type::{ArgumentType, Types}, - command::Command, - command_dispatcher::CommandDispatcher, - redirect_modifier::RedirectModifier, + arguments::argument_type::ArgumentType, command::Command, + command_dispatcher::CommandDispatcher, redirect_modifier::RedirectModifier, tree::command_node::CommandNode, }; @@ -27,19 +25,16 @@ use super::{ // private boolean forks; #[derive(Clone)] -pub struct CommandContextBuilder<'a, S, T> -where - T: ArgumentType<dyn Types>, -{ - arguments: HashMap<String, ParsedArgument<T>>, - root_node: &'a dyn CommandNode<S, T>, - nodes: Vec<ParsedCommandNode<S, T>>, - dispatcher: CommandDispatcher<'a, S, T>, +pub struct CommandContextBuilder<'a, S> { + arguments: HashMap<String, ParsedArgument<Box<dyn Any>>>, + root_node: &'a dyn CommandNode<S>, + nodes: Vec<ParsedCommandNode<S>>, + dispatcher: CommandDispatcher<'a, S>, source: S, - command: Box<dyn Command<S, T>>, - child: Option<CommandContextBuilder<'a, S, T>>, + command: Box<dyn Command<S>>, + child: Option<CommandContextBuilder<'a, S>>, range: StringRange, - modifier: Option<Box<dyn RedirectModifier<S, T>>>, + modifier: Option<Box<dyn RedirectModifier<S>>>, forks: bool, } @@ -50,14 +45,11 @@ where // this.range = StringRange.at(start); // } -impl<S, T> CommandContextBuilder<'_, S, T> -where - T: ArgumentType<dyn Types>, -{ +impl<S> CommandContextBuilder<'_, S> { pub fn new( - dispatcher: CommandDispatcher<S, T>, + dispatcher: CommandDispatcher<S>, source: S, - root_node: dyn CommandNode<S, T>, + root_node: dyn CommandNode<S>, start: usize, ) -> Self { Self { @@ -78,25 +70,25 @@ where &self.source } - pub fn root_node(&self) -> &dyn CommandNode<S, T> { + pub fn root_node(&self) -> &dyn CommandNode<S> { &self.root_node } - pub fn with_argument(mut self, name: String, argument: ParsedArgument<T>) -> Self { + pub fn with_argument(mut self, name: String, argument: ParsedArgument<Box<dyn Any>>) -> Self { self.arguments.insert(name, argument); self } - pub fn arguments(&self) -> &HashMap<String, ParsedArgument<T>> { + pub fn arguments(&self) -> &HashMap<String, ParsedArgument<Box<dyn Any>>> { &self.arguments } - pub fn with_command(mut self, command: &dyn Command<S, T>) -> Self { + pub fn with_command(mut self, command: &dyn Command<S>) -> Self { self.command = command; self } - pub fn with_node(mut self, node: dyn CommandNode<S, T>, range: StringRange) -> Self { + pub fn with_node(mut self, node: dyn CommandNode<S>, range: StringRange) -> Self { self.nodes.push(ParsedCommandNode::new(node, range)); self.range = StringRange::encompassing(&self.range, &range); self.modifier = node.redirect_modifier(); @@ -104,16 +96,16 @@ where self } - pub fn with_child(mut self, child: CommandContextBuilder<S, T>) -> Self { + pub fn with_child(mut self, child: CommandContextBuilder<S>) -> Self { self.child = Some(child); self } - pub fn child(&self) -> Option<&CommandContextBuilder<S, T>> { + pub fn child(&self) -> Option<&CommandContextBuilder<S>> { self.child.as_ref() } - pub fn last_child(&self) -> Option<&CommandContextBuilder<S, T>> { + pub fn last_child(&self) -> Option<&CommandContextBuilder<S>> { let mut result = self; while let Some(child) = result.child() { result = child; @@ -121,15 +113,15 @@ where Some(result) } - pub fn command(&self) -> &dyn Command<S, T> { + pub fn command(&self) -> &dyn Command<S> { &*self.command } - pub fn nodes(&self) -> &Vec<ParsedCommandNode<S, T>> { + pub fn nodes(&self) -> &Vec<ParsedCommandNode<S>> { &self.nodes } - pub fn build(self, input: &str) -> CommandContext<S, T> { + pub fn build(self, input: &str) -> CommandContext<S> { CommandContext { source: self.source, input, @@ -144,7 +136,7 @@ where } } - pub fn dispatcher(&self) -> &CommandDispatcher<S, T> { + pub fn dispatcher(&self) -> &CommandDispatcher<S> { &self.dispatcher } @@ -152,7 +144,7 @@ where &self.range } - pub fn find_suggestion_context(&self, cursor: i32) -> Result<SuggestionContext<S, T>, String> { + pub fn find_suggestion_context(&self, cursor: i32) -> Result<SuggestionContext<S>, String> { if self.range.start() <= cursor { if self.range.end() < cursor { if let Some(child) = self.child() { diff --git a/azalea-brigadier/src/context/parsed_argument.rs b/azalea-brigadier/src/context/parsed_argument.rs index 447a1223..e0bdf97b 100644 --- a/azalea-brigadier/src/context/parsed_argument.rs +++ b/azalea-brigadier/src/context/parsed_argument.rs @@ -3,12 +3,11 @@ use super::string_range::StringRange; #[derive(PartialEq, Eq, Hash, Clone)] pub struct ParsedArgument<T> { range: StringRange, - // T is an item in an enum result: T, } impl<T> ParsedArgument<T> { - fn new(start: usize, end: usize, result: T) -> Self { + fn new(start: usize, end: usize, result: &T) -> Self { Self { range: StringRange::between(start, end), result, diff --git a/azalea-brigadier/src/context/parsed_command_node.rs b/azalea-brigadier/src/context/parsed_command_node.rs index c0be355c..16c6ed8b 100644 --- a/azalea-brigadier/src/context/parsed_command_node.rs +++ b/azalea-brigadier/src/context/parsed_command_node.rs @@ -1,17 +1,17 @@ use super::string_range::StringRange; use crate::tree::command_node::CommandNode; -pub struct ParsedCommandNode<S, T> { - node: Box<dyn CommandNode<S, T>>, +pub struct ParsedCommandNode<S> { + node: Box<dyn CommandNode<S>>, range: StringRange, } -impl<S, T> ParsedCommandNode<S, T> { - fn new(node: dyn CommandNode<S, T>, range: StringRange) -> Self { +impl<S> ParsedCommandNode<S> { + fn new(node: dyn CommandNode<S>, range: StringRange) -> Self { Self { node, range } } - fn node(&self) -> &dyn CommandNode<S, T> { + fn node(&self) -> &dyn CommandNode<S> { &self.node } @@ -20,7 +20,7 @@ impl<S, T> ParsedCommandNode<S, T> { } } -impl<S, T> Clone for ParsedCommandNode<S, T> { +impl<S> Clone for ParsedCommandNode<S> { fn clone_from(&mut self, source: &Self) { Self { node: self.node.clone(), diff --git a/azalea-brigadier/src/context/suggestion_context.rs b/azalea-brigadier/src/context/suggestion_context.rs index 42bc550e..252cb6ed 100644 --- a/azalea-brigadier/src/context/suggestion_context.rs +++ b/azalea-brigadier/src/context/suggestion_context.rs @@ -1,6 +1,6 @@ use crate::tree::command_node::CommandNode; -pub struct SuggestionContext<'a, S, T> { - parent: &'a dyn CommandNode<S, T>, +pub struct SuggestionContext<'a, S> { + parent: &'a dyn CommandNode<S>, start_pos: usize, } |
