pub struct LexerOfStr<'a, P, T, E>where
P: PosnInCharStream,{ /* private fields */ }
Expand description
A Lexer of a str, using an arbitrary stream position type, lexer token, and lexer error.
This provides implementations of Lexer and CharStream.
The Lexer implementation means that a LexerOfStr has a ‘parse’ method that can be invoked to parse a single token at a position within the str, and another ‘iter’ method that can be invoked to generate an iterator that returns all the tokens in the str
If the iterator or parser return an Err, the that error is of the generic type ‘E’ supplied to the LexerOfStr which must implement LexerError of the generic position ‘P’ - so a failure to parse a character in the string can be indicated at a particular location (byte offset, with line number and column potentially).
The actual parsing of tokens is supported through the Lexer trait for both the ‘parser’ and ‘iter’ trait methods using a &BoxDynLexerParseFn. These must be boxed functions with the signature like:
fn parse(stream: &LexerOfStr<P, T, E>, pos:P, ch:char) ->
LexerParseResult<P, T, E>
where
LexerParseResult<P, T, E> = Result<Option<P, T>, E>
See the Lexer trait for more details on these parse functions
The LexerOfStr also provides a CharStream implementation, which provides methods that are can be used by the parse functions.
This provides methods to match strings, get
Implementations§
Source§impl<'a, P, T, E> LexerOfStr<'a, P, T, E>where
P: PosnInCharStream,
impl<'a, P, T, E> LexerOfStr<'a, P, T, E>where
P: PosnInCharStream,
Sourcepub fn new(text: &'a str) -> Self
pub fn new(text: &'a str) -> Self
Create a new LexerOfStr by borrowing a str
Trait Implementations§
Source§impl<'a, P, T, E> CharStream<P> for LexerOfStr<'a, P, T, E>where
P: PosnInCharStream,
impl<'a, P, T, E> CharStream<P> for LexerOfStr<'a, P, T, E>where
P: PosnInCharStream,
Source§fn range_as_bytes(&self, ofs: usize, n: usize) -> &[u8] ⓘ
fn range_as_bytes(&self, ofs: usize, n: usize) -> &[u8] ⓘ
Borrow some bytes of the stream from an offset
Return None if the bytes are out of range
Source§fn get_text_span(&self, span: &StreamCharSpan<P>) -> &str
fn get_text_span(&self, span: &StreamCharSpan<P>) -> &str
Get the text of a StreamCharSpan provided by a parser
§Safety
The StreamCharSpan must have been provided by a parser and so the byte offsets are indeed utf8 character boundaries
Source§fn get_text(&self, start: P, end: P) -> &str
fn get_text(&self, start: P, end: P) -> &str
Get the text between two crate::StreamCharPos provided by a parser
§Safety
The crate::StreamCharPos must have been provided by a parser and so the byte offsets are indeed utf8 character boundaries