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/context | |
| parent | cb4d871f6f56a484dc87151ea3ad55f7e3bbed97 (diff) | |
| download | azalea-drasl-60b129b3a62b66dd389d1775892405fe735b9540.tar.xz | |
progress
Diffstat (limited to 'azalea-brigadier/src/context')
5 files changed, 45 insertions, 54 deletions
diff --git a/azalea-brigadier/src/context/command_context.rs b/azalea-brigadier/src/context/command_context.rs index 7a2189d9..36741906 100644 --- a/azalea-brigadier/src/context/command_context.rs +++ b/azalea-brigadier/src/context/command_context.rs @@ -3,27 +3,25 @@ use super::{ string_range::StringRange, }; use crate::{ - arguments::argument_type::{ArgumentResult, ArgumentType}, - command::Command, - redirect_modifier::RedirectModifier, + arguments::argument_type::ArgumentType, command::Command, redirect_modifier::RedirectModifier, tree::command_node::CommandNode, }; use std::collections::HashMap; -pub struct CommandContext<S> { +pub struct CommandContext<'a, S, T> { source: S, input: String, - command: dyn Command<S>, - arguments: HashMap<String, ParsedArgument<dyn ArgumentType<dyn ArgumentResult>>>, - root_node: dyn CommandNode<S>, - nodes: Vec<ParsedCommandNode<S>>, + command: &'a dyn Command<S, T>, + arguments: HashMap<String, ParsedArgument<T>>, + root_node: &'a dyn CommandNode<S, T>, + nodes: Vec<ParsedCommandNode<'a, S, T>>, range: StringRange, - child: Option<CommandContext<S>>, - modifier: Option<dyn RedirectModifier<S>>, + child: Option<CommandContext<'a, S, T>>, + modifier: Option<&'a dyn RedirectModifier<S, T>>, forks: bool, } -impl<S> CommandContext<S> { +impl<S, T> CommandContext<'_, S, T> { pub fn clone_for(&self, source: S) -> Self { if self.source == source { return self.clone(); @@ -42,11 +40,11 @@ impl<S> CommandContext<S> { } } - fn child(&self) -> &Option<CommandContext<S>> { + fn child(&self) -> &Option<CommandContext<S, T>> { &self.child } - fn last_child(&self) -> &CommandContext<S> { + fn last_child(&self) -> &CommandContext<S, T> { let mut result = self; while result.child.is_some() { result = result.child.as_ref().unwrap(); @@ -54,7 +52,7 @@ impl<S> CommandContext<S> { result } - fn command(&self) -> &dyn Command<S> { + fn command(&self) -> &dyn Command<S, T> { &self.command } diff --git a/azalea-brigadier/src/context/command_context_builder.rs b/azalea-brigadier/src/context/command_context_builder.rs index 5766ea9a..878d7692 100644 --- a/azalea-brigadier/src/context/command_context_builder.rs +++ b/azalea-brigadier/src/context/command_context_builder.rs @@ -25,16 +25,16 @@ use super::{ // private boolean forks; #[derive(Clone)] -pub struct CommandContextBuilder<S> { - arguments: HashMap<String, ParsedArgument<dyn ArgumentType<dyn ArgumentResult>>>, - root_node: dyn CommandNode<S>, - nodes: Vec<ParsedCommandNode<S>>, - dispatcher: CommandDispatcher<S>, +pub struct CommandContextBuilder<'a, S, T> { + arguments: HashMap<String, ParsedArgument<T>>, + root_node: &'a dyn CommandNode<S, T>, + nodes: Vec<ParsedCommandNode<'a, S, T>>, + dispatcher: CommandDispatcher<'a, S, T>, source: S, - command: Box<dyn Command<S>>, - child: Option<CommandContextBuilder<S>>, + command: Box<dyn Command<S, T>>, + child: Option<CommandContextBuilder<'a, S, T>>, range: StringRange, - modifier: Option<Box<dyn RedirectModifier<S>>>, + modifier: Option<Box<dyn RedirectModifier<S, T>>>, forks: bool, } @@ -45,15 +45,15 @@ pub struct CommandContextBuilder<S> { // this.range = StringRange.at(start); // } -impl<S> CommandContextBuilder<S> { +impl<S, T> CommandContextBuilder<'_, S, T> { pub fn new( - dispatcher: CommandDispatcher<S>, + dispatcher: CommandDispatcher<S, T>, source: S, - root_node: dyn CommandNode<S>, + root_node: dyn CommandNode<S, T>, start: usize, ) -> Self { Self { - root_node, + root_node: &root_node, dispatcher, source, range: StringRange::at(start), @@ -70,31 +70,25 @@ impl<S> CommandContextBuilder<S> { &self.source } - pub fn root_node(&self) -> &dyn CommandNode<S> { + pub fn root_node(&self) -> &dyn CommandNode<S, T> { &self.root_node } - pub fn with_argument( - mut self, - name: String, - argument: ParsedArgument<dyn ArgumentType<dyn ArgumentResult>>, - ) -> Self { + pub fn with_argument(mut self, name: String, argument: ParsedArgument<T>) -> Self { self.arguments.insert(name, argument); self } - pub fn arguments( - &self, - ) -> &HashMap<String, ParsedArgument<dyn ArgumentType<dyn ArgumentResult>>> { + pub fn arguments(&self) -> &HashMap<String, ParsedArgument<T>> { &self.arguments } - pub fn with_command(mut self, command: Box<dyn Command<S>>) -> Self { + pub fn with_command(mut self, command: &dyn Command<S, T>) -> Self { self.command = command; self } - pub fn with_node(mut self, node: dyn CommandNode<S>, range: StringRange) -> Self { + pub fn with_node(mut self, node: dyn CommandNode<S, T>, range: StringRange) -> Self { self.nodes.push(ParsedCommandNode::new(node, range)); self.range = StringRange::encompassing(&self.range, &range); self.modifier = node.redirect_modifier(); @@ -102,16 +96,16 @@ impl<S> CommandContextBuilder<S> { self } - pub fn with_child(mut self, child: CommandContextBuilder<S>) -> Self { + pub fn with_child(mut self, child: CommandContextBuilder<S, T>) -> Self { self.child = Some(child); self } - pub fn child(&self) -> Option<&CommandContextBuilder<S>> { + pub fn child(&self) -> Option<&CommandContextBuilder<S, T>> { self.child.as_ref() } - pub fn last_child(&self) -> Option<&CommandContextBuilder<S>> { + pub fn last_child(&self) -> Option<&CommandContextBuilder<S, T>> { let mut result = self; while let Some(child) = result.child() { result = child; @@ -119,15 +113,15 @@ impl<S> CommandContextBuilder<S> { Some(result) } - pub fn command(&self) -> &dyn Command<S> { + pub fn command(&self) -> &dyn Command<S, T> { &*self.command } - pub fn nodes(&self) -> &Vec<ParsedCommandNode<S>> { + pub fn nodes(&self) -> &Vec<ParsedCommandNode<S, T>> { &self.nodes } - pub fn build(self, input: &str) -> CommandContext<S> { + pub fn build(self, input: &str) -> CommandContext<S, T> { CommandContext { source: self.source, input, @@ -142,7 +136,7 @@ impl<S> CommandContextBuilder<S> { } } - pub fn dispatcher(&self) -> &CommandDispatcher<S> { + pub fn dispatcher(&self) -> &CommandDispatcher<S, T> { &self.dispatcher } @@ -150,7 +144,7 @@ impl<S> CommandContextBuilder<S> { &self.range } - pub fn find_suggestion_context(&self, cursor: i32) -> Result<SuggestionContext<S>, String> { + pub fn find_suggestion_context(&self, cursor: i32) -> Result<SuggestionContext<S, T>, 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 77a47078..75c07784 100644 --- a/azalea-brigadier/src/context/parsed_argument.rs +++ b/azalea-brigadier/src/context/parsed_argument.rs @@ -1,10 +1,9 @@ -use std::marker::PhantomData; - use super::string_range::StringRange; #[derive(PartialEq, Eq, Hash)] pub struct ParsedArgument<T> { range: StringRange, + // T is an item in an enum result: T, } diff --git a/azalea-brigadier/src/context/parsed_command_node.rs b/azalea-brigadier/src/context/parsed_command_node.rs index 98e99959..a006aa4b 100644 --- a/azalea-brigadier/src/context/parsed_command_node.rs +++ b/azalea-brigadier/src/context/parsed_command_node.rs @@ -2,17 +2,17 @@ use super::string_range::StringRange; use crate::tree::command_node::CommandNode; #[derive(Hash, PartialEq, Eq, Debug, Clone)] -pub struct ParsedCommandNode<S> { - node: dyn CommandNode<S>, +pub struct ParsedCommandNode<'a, S, T> { + node: &'a dyn CommandNode<S, T>, range: StringRange, } -impl<S> ParsedCommandNode<S> { - fn new(node: dyn CommandNode<S>, range: StringRange) -> Self { +impl<S, T> ParsedCommandNode<'_, S, T> { + fn new(node: &dyn CommandNode<S, T>, range: StringRange) -> Self { Self { node, range } } - fn node(&self) -> &dyn CommandNode<S> { + fn node(&self) -> &dyn CommandNode<S, T> { &self.node } diff --git a/azalea-brigadier/src/context/suggestion_context.rs b/azalea-brigadier/src/context/suggestion_context.rs index 540a5f23..42bc550e 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<S> { - parent: dyn CommandNode<S>, +pub struct SuggestionContext<'a, S, T> { + parent: &'a dyn CommandNode<S, T>, start_pos: usize, } |
