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
impl Matcher
sourcepub fn then1<R: Match<(A1,)>, A1>(self, lexeme: Lexeme<R>, a1: A1) -> Self
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!
sourcepub fn then2<R: Match<(A1, A2)>, A1, A2>(
self,
lexeme: Lexeme<R>,
a1: A1,
a2: A2
) -> Self
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!
sourcepub fn prefix1<R: Match<(A1,)>, A1>(
self,
lexeme: Lexeme<R>,
prefix: impl Into<Text>,
a1: A1
) -> Self
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.
sourcepub fn prefix2<R: Match<(A1, A2)>, A1, A2>(
self,
lexeme: Lexeme<R>,
prefix: impl Into<Text>,
a1: A1,
a2: A2
) -> Self
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.
sourcepub fn suffix1<R: Match<(A1,)>, A1>(
self,
lexeme: Lexeme<R>,
a1: A1,
suffix: impl Into<Text>
) -> Self
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.
sourcepub fn suffix2<R: Match<(A1, A2)>, A1, A2>(
self,
lexeme: Lexeme<R>,
a1: A1,
a2: A2,
suffix: impl Into<Text>
) -> Self
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.
sourcepub fn affix1<R: Match<(A1,)>, A1>(
self,
lexeme: Lexeme<R>,
prefix: impl Into<Text>,
a1: A1,
suffix: impl Into<Text>
) -> Self
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.
sourcepub 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
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.
sourcepub fn eof(self) -> Self
pub fn eof(self) -> Self
Adds an EOF matcher.
Every token stream ends with an EOF token, so you always need to include one.
sourcepub fn assert_matches<'lex>(
&self,
ctx: &Context,
that: impl IntoIterator<Item = Any<'lex>>
)
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.
sourcepub fn span(self, text: impl Into<Text>) -> Self
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.