Struct wca::Parser

source ·
pub struct Parser {
    pub command_prefix: char,
    pub prop_delimeter: char,
    pub namespace_delimeter: Cow<'static, str>,
}
Expand description

Parser provides parsing command strings into ParsedCommand objects. It allows you to specify the symbols that will be used to interpret the command string, such as the command delimiter, property delimiter, and namespace delimiter.

use wca::{ Parser, CommandParser };
/// Configure the parser
let parser = Parser::former()
.command_prefix( '.' )
.prop_delimeter( ':' )
.form();

/// Parse a command from a` string
let raw_command = parser.command( ".command subject_value prop_name:prop_value" )?;

In the above example, a Parser object is created and configured to accept commands with a . prefix and : delimiters for properties.

Note that Parser uses CommandParser trait to parse commands from user input( You can also use NamespaceParser to parse namespaces, or ProgramParser to parse programs from string ).

Fields§

§command_prefix: char

Symbol that will be interpreted as the beginning of a command

command_delimiter = .

“.command” -> Command( “command” )

§prop_delimeter: char

Symbol that will be interpreted as a separator for the name and value of the property

prop_delimiter = :

“prop:value” -> ( “prop”, “value” )

§namespace_delimeter: Cow<'static, str>

String that will be interpreted as a separator for namespaces

namespace_delimiter = “.also”

“< commands1 > .also < commands2 >” -> Namespace( < commands1 > ), Namespace( < commands2 > )

Implementations§

source§

impl Parser

source

pub fn former() -> ParserFormer<Parser, ReturnContainer>

Make former, variation of builder pattern to form structure defining values of fields step by step.

Trait Implementations§

source§

impl CommandParser for Parser

source§

fn command<'a>(&'a self, input: &'a str) -> Result<Command>

Parses first command from string Read more
source§

impl CommandParserFn for Parser

source§

fn command_fn(&self) -> Box<dyn Fn(&str) -> IResult<&str, ParsedCommand> + '_>

Returns function that can parse a Command
source§

impl Debug for Parser

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl ProgramParser for Parser

source§

fn program<'a>(&'a self, input: &'a str) -> Result<Program<ParsedCommand>>

Parses program from string

Auto Trait Implementations§

§

impl Freeze for Parser

§

impl RefUnwindSafe for Parser

§

impl Send for Parser

§

impl Sync for Parser

§

impl Unpin for Parser

§

impl UnwindSafe for Parser

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<S> SetWithType for S

source§

fn set_with_type<T, IntoT>(&mut self, component: IntoT)
where IntoT: Into<T>, S: SetComponent<T, IntoT>,

Function to set value of a component by its type.
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Any for T
where T: Any,