Struct proclet::OpParser

source ·
pub struct OpParser<P: PunctExt, F: MatchOpFn>(/* private fields */);
Expand description

Parser for specific sets of operators. Ops can be parsed via Parser or manually from Puncts.

Implementations§

source§

impl<P: PunctExt, F: MatchOpFn> OpParser<P, F>

source

pub const fn new(match_op: F) -> Self

Create a new OpParser using match_op to define the valid operators. Usually you wouldn’t call this directly, but create the OpParser using a function generated by the define_ops macro in the proclet-utils crate. If you want to parse a single Op using Parser, use Op instead.

See OpParser::match_op for details of how match_op should work.

source

pub fn create(&self) -> OpParserInstance<P, F>

Create a new OpParserInstance for this OpParser. You only need this if you don’t use Parser::parse or parse_ops.

source

pub fn parse_ops<I: Iterator<Item = P>>( &self, puncts: I ) -> ParseOps<P::Span, I, F>

Use this OpParser to parse operators from an iterator of Puncts.

source

pub fn match_op( &self, str: &str, next: Option<char> ) -> Match<Cow<'static, str>>

Check if str is a valid op.

For example, if + and += are valid ops and +- is invalid:

  • match_op("+", Some('=')) returns Match::Partial("+")
  • match_op("+", Some('-')) returns Match::Complete("+")
  • match_op("+", None) returns Match::Complete("+")
  • match_op("+=", None) returns Match::Complete("+=")
  • match_op("+-", None) returns Match::None

If -= is a valid op, and - and -+ are invalid:

  • match_op("-", Some('=')) returns Match::NeedMore
  • match_op("-", Some('+')) returns Match::None
  • match_op("-", None) returns Match::None
  • match_op("-=", None) returns Match::Complete("-=")

Trait Implementations§

source§

impl<P: Clone + PunctExt, F: Clone + MatchOpFn> Clone for OpParser<P, F>

source§

fn clone(&self) -> OpParser<P, F>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<P: PunctExt, F: MatchOpFn> Parser<<P as ProcMacro>::TokenTree> for OpParser<P, F>

§

type Output<'p, 'b> = Op<<P as ProcMacro>::Span> where Self: 'p

The output type of this parser.
source§

fn parse<'p, 'b>( &'p self, buf: &mut &'b TokenBuf<P::TokenTree> ) -> Result<Self::Output<'p, 'b>, Error<P::Span>>

Parse a value from a TokenBuf using this parser. Read more
source§

fn parse_all<'p, 'b>( &'p self, buf: &mut &'b TokenBuf<T> ) -> Result<Self::Output<'p, 'b>, Error<T::Span>>

Parse a value from a TokenBuf buffer, but return an error if there’s any tokens left in the buffer after parsing. Read more
source§

fn optional(self) -> Optional<Self>
where Self: Sized,

Wrap this parser in Optional to make it always succeed and return an option.

Auto Trait Implementations§

§

impl<P, F> Freeze for OpParser<P, F>
where F: Freeze,

§

impl<P, F> RefUnwindSafe for OpParser<P, F>
where F: RefUnwindSafe,

§

impl<P, F> Send for OpParser<P, F>
where F: Send,

§

impl<P, F> Sync for OpParser<P, F>
where F: Sync,

§

impl<P, F> Unpin for OpParser<P, F>
where F: Unpin,

§

impl<P, F> UnwindSafe for OpParser<P, F>
where F: UnwindSafe,

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<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.