aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-04-18 19:38:08 -0500
committermat <github@matdoes.dev>2022-04-18 19:38:08 -0500
commitb8ceb56e7141320d5ba23a946fe3eceee43f51f5 (patch)
tree6cabb2ec6b47a0f6da26919869f839c1aa343978
parent8d71fbf813391783531a9f7c70e75e105fabaf03 (diff)
downloadazalea-drasl-b8ceb56e7141320d5ba23a946fe3eceee43f51f5.tar.xz
move `parsers` into `arguments`
-rw-r--r--azalea-brigadier/src/arguments/argument_type.rs7
-rw-r--r--azalea-brigadier/src/arguments/integer_argument_type.rs (renamed from azalea-brigadier/src/parsers.rs)8
-rw-r--r--azalea-brigadier/src/arguments/mod.rs4
-rw-r--r--azalea-brigadier/src/builder/argument_builder.rs2
-rw-r--r--azalea-brigadier/src/builder/required_argument_builder.rs10
-rw-r--r--azalea-brigadier/src/command_dispatcher.rs2
-rw-r--r--azalea-brigadier/src/lib.rs4
7 files changed, 24 insertions, 13 deletions
diff --git a/azalea-brigadier/src/arguments/argument_type.rs b/azalea-brigadier/src/arguments/argument_type.rs
new file mode 100644
index 00000000..029e4696
--- /dev/null
+++ b/azalea-brigadier/src/arguments/argument_type.rs
@@ -0,0 +1,7 @@
+use std::{any::Any, rc::Rc};
+
+use crate::{exceptions::CommandSyntaxException, string_reader::StringReader};
+
+pub trait ArgumentType {
+ fn parse(&self, reader: &mut StringReader) -> Result<Rc<dyn Any>, CommandSyntaxException>;
+}
diff --git a/azalea-brigadier/src/parsers.rs b/azalea-brigadier/src/arguments/integer_argument_type.rs
index 18ee9119..336046a7 100644
--- a/azalea-brigadier/src/parsers.rs
+++ b/azalea-brigadier/src/arguments/integer_argument_type.rs
@@ -6,9 +6,7 @@ use crate::{
string_reader::StringReader,
};
-pub trait Parser {
- fn parse(&self, reader: &mut StringReader) -> Result<Rc<dyn Any>, CommandSyntaxException>;
-}
+use super::ArgumentType;
#[derive(Default)]
struct Integer {
@@ -16,7 +14,7 @@ struct Integer {
pub maximum: Option<i32>,
}
-impl Parser for Integer {
+impl ArgumentType for Integer {
fn parse(&self, reader: &mut StringReader) -> Result<Rc<dyn Any>, CommandSyntaxException> {
let start = reader.cursor;
let result = reader.read_int()?;
@@ -44,7 +42,7 @@ impl Parser for Integer {
}
}
-pub fn integer() -> impl Parser {
+pub fn integer() -> impl ArgumentType {
Integer::default()
}
pub fn get_integer<S>(context: &CommandContext<S>, name: &str) -> Option<i32> {
diff --git a/azalea-brigadier/src/arguments/mod.rs b/azalea-brigadier/src/arguments/mod.rs
new file mode 100644
index 00000000..dec39297
--- /dev/null
+++ b/azalea-brigadier/src/arguments/mod.rs
@@ -0,0 +1,4 @@
+mod argument_type;
+pub mod integer_argument_type;
+
+pub use argument_type::ArgumentType;
diff --git a/azalea-brigadier/src/builder/argument_builder.rs b/azalea-brigadier/src/builder/argument_builder.rs
index dee6ccfe..14d41f4e 100644
--- a/azalea-brigadier/src/builder/argument_builder.rs
+++ b/azalea-brigadier/src/builder/argument_builder.rs
@@ -141,8 +141,8 @@ mod tests {
use std::rc::Rc;
use crate::{
+ arguments::integer_argument_type::integer,
builder::{literal_argument_builder::literal, required_argument_builder::argument},
- parsers::integer,
};
use super::ArgumentBuilder;
diff --git a/azalea-brigadier/src/builder/required_argument_builder.rs b/azalea-brigadier/src/builder/required_argument_builder.rs
index a50f7ea9..9d4d9e0a 100644
--- a/azalea-brigadier/src/builder/required_argument_builder.rs
+++ b/azalea-brigadier/src/builder/required_argument_builder.rs
@@ -1,5 +1,7 @@
use super::argument_builder::{ArgumentBuilder, ArgumentBuilderType};
-use crate::{exceptions::CommandSyntaxException, parsers::Parser, string_reader::StringReader};
+use crate::{
+ arguments::ArgumentType, exceptions::CommandSyntaxException, string_reader::StringReader,
+};
use std::{any::Any, fmt::Debug, rc::Rc};
/// An argument node type. The `T` type parameter is the type of the argument,
@@ -7,10 +9,10 @@ use std::{any::Any, fmt::Debug, rc::Rc};
#[derive(Clone)]
pub struct Argument {
pub name: String,
- parser: Rc<dyn Parser>,
+ parser: Rc<dyn ArgumentType>,
}
impl Argument {
- pub fn new(name: &str, parser: Rc<dyn Parser>) -> Self {
+ pub fn new(name: &str, parser: Rc<dyn ArgumentType>) -> Self {
Self {
name: name.to_string(),
parser,
@@ -38,6 +40,6 @@ impl Debug for Argument {
}
/// Shortcut for creating a new argument builder node.
-pub fn argument<S>(name: &str, parser: impl Parser + 'static) -> ArgumentBuilder<S> {
+pub fn argument<S>(name: &str, parser: impl ArgumentType + 'static) -> ArgumentBuilder<S> {
ArgumentBuilder::new(Argument::new(name, Rc::new(parser)).into())
}
diff --git a/azalea-brigadier/src/command_dispatcher.rs b/azalea-brigadier/src/command_dispatcher.rs
index ea788130..fc3f3d50 100644
--- a/azalea-brigadier/src/command_dispatcher.rs
+++ b/azalea-brigadier/src/command_dispatcher.rs
@@ -301,8 +301,8 @@ impl<S> Clone for CommandDispatcher<S> {
mod tests {
use super::*;
use crate::{
+ arguments::integer_argument_type::integer,
builder::{literal_argument_builder::literal, required_argument_builder::argument},
- parsers::integer,
};
#[derive(Debug, PartialEq)]
diff --git a/azalea-brigadier/src/lib.rs b/azalea-brigadier/src/lib.rs
index cffaac12..db46d46e 100644
--- a/azalea-brigadier/src/lib.rs
+++ b/azalea-brigadier/src/lib.rs
@@ -1,3 +1,4 @@
+pub mod arguments;
pub mod builder;
pub mod command_dispatcher;
pub mod context;
@@ -5,7 +6,6 @@ pub mod exceptions;
pub mod message;
pub mod modifier;
pub mod parse_results;
-pub mod parsers;
pub mod string_reader;
pub mod tree;
@@ -15,10 +15,10 @@ mod tests {
use std::rc::Rc;
use crate::{
+ arguments::integer_argument_type::{get_integer, integer},
builder::{literal_argument_builder::literal, required_argument_builder::argument},
command_dispatcher::CommandDispatcher,
context::CommandContext,
- parsers::{get_integer, integer},
};
struct CommandSourceStack {