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 Punct
s.
Implementations§
source§impl<P: PunctExt, F: MatchOpFn> OpParser<P, F>
impl<P: PunctExt, F: MatchOpFn> OpParser<P, F>
sourcepub const fn new(match_op: F) -> Self
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.
sourcepub fn create(&self) -> OpParserInstance<P, F>
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
.
sourcepub fn parse_ops<I: Iterator<Item = P>>(
&self,
puncts: I
) -> ParseOps<P::Span, I, F>
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 Punct
s.
sourcepub fn match_op(
&self,
str: &str,
next: Option<char>
) -> Match<Cow<'static, str>>
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('='))
returnsMatch::Partial("+")
match_op("+", Some('-'))
returnsMatch::Complete("+")
match_op("+", None)
returnsMatch::Complete("+")
match_op("+=", None)
returnsMatch::Complete("+=")
match_op("+-", None)
returnsMatch::None
If -=
is a valid op, and -
and -+
are invalid:
match_op("-", Some('='))
returnsMatch::NeedMore
match_op("-", Some('+'))
returnsMatch::None
match_op("-", None)
returnsMatch::None
match_op("-=", None)
returnsMatch::Complete("-=")
Trait Implementations§
source§impl<P: PunctExt, F: MatchOpFn> Parser<<P as ProcMacro>::TokenTree> for OpParser<P, F>
impl<P: PunctExt, F: MatchOpFn> Parser<<P as ProcMacro>::TokenTree> for OpParser<P, F>
source§fn parse<'p, 'b>(
&'p self,
buf: &mut &'b TokenBuf<P::TokenTree>
) -> Result<Self::Output<'p, 'b>, Error<P::Span>>
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 moreAuto 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more