Struct ilex::testing::Matcher

source ·
pub struct Matcher { /* private fields */ }
Expand description

A matcher for a token stream.

For usage examples, see the ilex/tests directory.

Implementations§

source§

impl Matcher

source

pub fn new() -> Self

Creates a new matcher.

source

pub fn then1<R: Match<(A1,)>, A1>(self, lexeme: Lexeme<R>, a1: A1) -> Self

Adds a new expected token for this matcher, from a lexeme and an argument.

What is allowed for arg for a particular rule type is specified by the Match trait. You can even define your own!

source

pub fn then2<R: Match<(A1, A2)>, A1, A2>( self, lexeme: Lexeme<R>, a1: A1, a2: A2 ) -> Self

Adds a new expected token for this matcher, from a lexeme and two arguments.

What is allowed for arg for a particular rule type is specified by the Match trait. You can even define your own!

source

pub fn prefix1<R: Match<(A1,)>, A1>( self, lexeme: Lexeme<R>, prefix: impl Into<Text>, a1: A1 ) -> Self

Like Matcher::then1(), but adds a prefix matcher too.

source

pub fn prefix2<R: Match<(A1, A2)>, A1, A2>( self, lexeme: Lexeme<R>, prefix: impl Into<Text>, a1: A1, a2: A2 ) -> Self

Like Matcher::then2(), but adds a prefix matcher too.

source

pub fn suffix1<R: Match<(A1,)>, A1>( self, lexeme: Lexeme<R>, a1: A1, suffix: impl Into<Text> ) -> Self

Like Matcher::then1(), but adds a suffix matcher too.

source

pub fn suffix2<R: Match<(A1, A2)>, A1, A2>( self, lexeme: Lexeme<R>, a1: A1, a2: A2, suffix: impl Into<Text> ) -> Self

Like Matcher::then2(), but adds a suffix matcher too.

source

pub fn affix1<R: Match<(A1,)>, A1>( self, lexeme: Lexeme<R>, prefix: impl Into<Text>, a1: A1, suffix: impl Into<Text> ) -> Self

Like Matcher::then1(), but adds a prefix matcher and a suffix matcher too.

source

pub fn affix2<R: Match<(A1, A2)>, A1, A2>( self, lexeme: Lexeme<R>, prefix: impl Into<Text>, a1: A1, a2: A2, suffix: impl Into<Text> ) -> Self

Like Matcher::then2(), but adds a prefix matcher and a suffix matcher too.

source

pub fn eof(self) -> Self

Adds an EOF matcher.

Every token stream ends with an EOF token, so you always need to include one.

source

pub fn assert_matches<'lex>( &self, ctx: &Context, that: impl IntoIterator<Item = Any<'lex>> )

Matches cursor against this matcher, and panics if it doesn’t.

source

pub fn span(self, text: impl Into<Text>) -> Self

Sets an expectation for the overall span of the most recently added token matcher.

§Panics

Panics if none of the matcher-adding methods has been called yet.

source

pub fn comments<I>(self, iter: I) -> Self
where I: IntoIterator, I::Item: Into<Text>,

Adds some expected comments to the most recently added token matcher.

§Panics

Panics if none of the matcher-adding methods has been called yet.

source

pub fn matches<'lex>( &self, ctx: &Context, that: impl IntoIterator<Item = Any<'lex>> ) -> Result<(), impl Debug>

Matches cursor against this matcher.

If matching fails, returns an error describing why.

Trait Implementations§

source§

impl Default for Matcher

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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, 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.