Trait pest::inputs::Input
[−]
[src]
pub trait Input: Debug { fn len(&self) -> usize; fn is_empty(&self) -> bool; fn file_name(&self) -> Option<OsString>; unsafe fn slice(&self, start: usize, end: usize) -> &str; unsafe fn line_col(&self, pos: usize) -> (usize, usize); unsafe fn line_of(&self, pos: usize) -> &str; unsafe fn skip(&self, n: usize, pos: usize) -> Option<usize>; unsafe fn match_string(&self, string: &str, pos: usize) -> bool; unsafe fn match_insensitive(&self, string: &str, pos: usize) -> bool; unsafe fn match_range(
&self,
range: Range<char>,
pos: usize
) -> Option<usize>; }
A trait that defines an input for a Parser. It should be implemented by custom input sources
as minimally and efficiently as possible. unsafe methods should not be called directly; in
order to parse the Input manually use Position and
ParserState.
Implementors should NOT introduce undefined behavior in these methods. Undefined behavior is
acceptable ONLY when the positions are either out of bounds or don't match UTF-8 indices,
since these cases are avoided by using the Position API.
Required Methods
fn len(&self) -> usize
Returns length of the input.
fn is_empty(&self) -> bool
Returns whether the input is empty.
fn file_name(&self) -> Option<OsString>
Returns the file name of the input or None in the case where it doesn't have one.
unsafe fn slice(&self, start: usize, end: usize) -> &str
Slices the input.
Safety
This method can cause undefined behavior when start or end are either out of bounds or
don't match UTF-8 indices.
unsafe fn line_col(&self, pos: usize) -> (usize, usize)
Returns the line - and column number of the input at pos.
Safety
This method can cause undefined behavior when pos is either out of bounds or doesn't match
UTF-8 indices.
unsafe fn line_of(&self, pos: usize) -> &str
Returns the line of the input at pos.
Safety
This method can cause undefined behavior when pos is either out of bounds or doesn't match
UTF-8 indices.
unsafe fn skip(&self, n: usize, pos: usize) -> Option<usize>
Tries to skip n chars at pos. Returns Some(len) with the UTF-8 length of the skipped
chars position or None if there are not enough chars left to skip.
Safety
This method can cause undefined behavior when pos is either out of bounds or doesn't match
UTF-8 indices.
unsafe fn match_string(&self, string: &str, pos: usize) -> bool
Matches string at pos and returns whether it matched.
Safety
This method can cause undefined behavior when pos is either out of bounds or doesn't match
UTF-8 indices.
unsafe fn match_insensitive(&self, string: &str, pos: usize) -> bool
Matches string at pos case insensitively and returns whether it matched.
Safety
This method can cause undefined behavior when pos is either out of bounds or doesn't match
UTF-8 indices.
unsafe fn match_range(&self, range: Range<char>, pos: usize) -> Option<usize>
Matches if the char is within the range and returns Some(len) with the matching
char's UTF-8 length if it matched or None otherwise.
Safety
This method can cause undefined behavior when pos is either out of bounds or doesn't match
UTF-8 indices.
Implementors
impl Input for FileInputimpl Input for StringInput