pub struct Scanner<C: CharSource> { /* private fields */ }
master
only.Expand description
Reader of master file tokens.
A scanner reads characters from a source and converts them into tokens or errors.
Implementations
sourceimpl<C: CharSource> Scanner<C>
impl<C: CharSource> Scanner<C>
sourceimpl<C: CharSource> Scanner<C>
impl<C: CharSource> Scanner<C>
Access to Origin
Domain names in a master file that do not end in a dot are relative to some origin. This origin is simply appened to them to form an absolute name.
Since domain names can appear all over the place and we don’t want to have to pass around the origin all the time, it is part of the scanner and can be set and retrieved any time.
sourceimpl<C: CharSource> Scanner<C>
impl<C: CharSource> Scanner<C>
sourcepub fn eof_reached(&mut self) -> bool
pub fn eof_reached(&mut self) -> bool
Returns whether the scanner has reached the end of data.
sourcepub fn scan_word<T, U, F, G>(
&mut self,
target: T,
symbolop: F,
finalop: G
) -> Result<U, ScanError>where
F: FnMut(&mut T, Symbol) -> Result<(), SyntaxError>,
G: FnOnce(T) -> Result<U, SyntaxError>,
pub fn scan_word<T, U, F, G>(
&mut self,
target: T,
symbolop: F,
finalop: G
) -> Result<U, ScanError>where
F: FnMut(&mut T, Symbol) -> Result<(), SyntaxError>,
G: FnOnce(T) -> Result<U, SyntaxError>,
Scans a word token.
A word is a sequence of non-special characters and escape sequences followed by a non-empty sequence of space unless it is followed directly by a newline. If successful, the method will position at the end of the space sequence if it is required. That is, you can scan for two subsequent word tokens without worrying about the space between them.
The method starts out with a target
value and two closures. The
first closure, symbolop
, is being fed symbols of the word one by one
and should feed them into the target. Once the word ended, the
second closure is called to convert the target into the final result.
Both can error out at any time stopping processing and leading the
scanner to revert to the beginning of the token.
sourcepub fn scan_string_word<U, G>(&mut self, finalop: G) -> Result<U, ScanError>where
G: FnOnce(String) -> Result<U, SyntaxError>,
pub fn scan_string_word<U, G>(&mut self, finalop: G) -> Result<U, ScanError>where
G: FnOnce(String) -> Result<U, SyntaxError>,
Scans a word with Unicode text into a String
.
The method scans a word that consists of characters and puts these
into a String
. Once the word ends, the caller is given a chance
to convert the value into something else via the closure finalop
.
This closure can fail, resulting in an error and back-tracking to
the beginning of the phrase.
sourcepub fn scan_quoted<T, U, F, G>(
&mut self,
target: T,
symbolop: F,
finalop: G
) -> Result<U, ScanError>where
F: FnMut(&mut T, Symbol) -> Result<(), SyntaxError>,
G: FnOnce(T) -> Result<U, SyntaxError>,
pub fn scan_quoted<T, U, F, G>(
&mut self,
target: T,
symbolop: F,
finalop: G
) -> Result<U, ScanError>where
F: FnMut(&mut T, Symbol) -> Result<(), SyntaxError>,
G: FnOnce(T) -> Result<U, SyntaxError>,
Scans a quoted word.
A quoted word starts with a double quote "
, followed by all sorts
of characters or escape sequences until the next (unescaped) double
quote. It may contain line feeds. Like a regular word, a quoted word
is followed by a non-empty space sequence unless it is directly
followed by a newline. This space is not
part of the content but quietly skipped over.
The method starts out with a target
value and two closures. The
first closure, symbolop
, is being fed symbols of the word one by one
and should feed them into the target. Once the word ended, the
second closure is called to convert the target into the final result.
Both can error out at any time stopping processing and leading the
scanner to revert to the beginning of the token.
sourcepub fn scan_phrase<T, U, F, G>(
&mut self,
target: T,
symbolop: F,
finalop: G
) -> Result<U, ScanError>where
F: FnMut(&mut T, Symbol) -> Result<(), SyntaxError>,
G: FnOnce(T) -> Result<U, SyntaxError>,
pub fn scan_phrase<T, U, F, G>(
&mut self,
target: T,
symbolop: F,
finalop: G
) -> Result<U, ScanError>where
F: FnMut(&mut T, Symbol) -> Result<(), SyntaxError>,
G: FnOnce(T) -> Result<U, SyntaxError>,
Scans a phrase: a normal word or a quoted word.
This method behaves like scan_quoted() if the next character is a double quote or like scan_word() otherwise.
sourcepub fn scan_byte_phrase<U, G>(&mut self, finalop: G) -> Result<U, ScanError>where
G: FnOnce(Bytes) -> Result<U, SyntaxError>,
pub fn scan_byte_phrase<U, G>(&mut self, finalop: G) -> Result<U, ScanError>where
G: FnOnce(Bytes) -> Result<U, SyntaxError>,
Scans a phrase with byte content into a Bytes
value.
The method scans a phrase that consists of byte only and puts these
bytes into a Bytes
value. Once the phrase ends, the caller is given
a chance to convert the value into something else via the closure
finalop
. This closure can fail, resulting in an error and
back-tracking to the beginning of the phrase.
sourcepub fn scan_string_phrase<U, G>(&mut self, finalop: G) -> Result<U, ScanError>where
G: FnOnce(String) -> Result<U, SyntaxError>,
pub fn scan_string_phrase<U, G>(&mut self, finalop: G) -> Result<U, ScanError>where
G: FnOnce(String) -> Result<U, SyntaxError>,
Scans a phrase with Unicode text into a String
.
The method scans a phrase that consists of characters and puts these
into a String
. Once the phrase ends, the caller is given
a chance to convert the value into something else via the closure
finalop
. This closure can fail, resulting in an error and
back-tracking to the beginning of the phrase.
sourcepub fn scan_newline(&mut self) -> Result<(), ScanError>
pub fn scan_newline(&mut self) -> Result<(), ScanError>
Scans over a mandatory newline.
A newline is either an optional comment followed by a newline sequence or the end of file. The latter is so that a file lacking a line feed after its last line is still parsed successfully.
sourcepub fn scan_space(&mut self) -> Result<(), ScanError>
pub fn scan_space(&mut self) -> Result<(), ScanError>
Scans over a mandatory sequence of space.
There are two flavors of space. The simple form is any sequence
of a space character ' '
or a horizontal tab ’\t'
. However,
a parenthesis can be used to turn newlines
into normal space. This method recognises parentheses and acts
accordingly.
sourcepub fn scan_opt_space(&mut self) -> Result<(), ScanError>
pub fn scan_opt_space(&mut self) -> Result<(), ScanError>
Scans over an optional sequence of space.
sourcepub fn skip_entry(&mut self) -> Result<(), ScanError>
pub fn skip_entry(&mut self) -> Result<(), ScanError>
Skips over an entry.
Keeps reading until it successfully scans a newline. The method tries to be smart about that and considers parentheses, quotes, and escapes but also tries its best to not fail.
sourceimpl<C: CharSource> Scanner<C>
impl<C: CharSource> Scanner<C>
sourcepub fn scan_hex_word<U, G>(&mut self, finalop: G) -> Result<U, ScanError>where
G: FnOnce(Bytes) -> Result<U, SyntaxError>,
pub fn scan_hex_word<U, G>(&mut self, finalop: G) -> Result<U, ScanError>where
G: FnOnce(Bytes) -> Result<U, SyntaxError>,
Scans a word containing a sequence of pairs of hex digits.
The word is returned as a Bytes
value with each byte representing
the decoded value of one hex digit pair.
pub fn scan_hex_words<U, G>(&mut self, finalop: G) -> Result<U, ScanError>where
G: FnOnce(Bytes) -> Result<U, SyntaxError>,
sourcepub fn scan_base32hex_phrase<U, G>(&mut self, finalop: G) -> Result<U, ScanError>where
G: FnOnce(Bytes) -> Result<U, SyntaxError>,
pub fn scan_base32hex_phrase<U, G>(&mut self, finalop: G) -> Result<U, ScanError>where
G: FnOnce(Bytes) -> Result<U, SyntaxError>,
Scans a phrase containing base32hex encoded data.
In particular, this decodes the “base32hex” decoding definied in RFC 4648 without padding.
sourcepub fn scan_base64_phrases<U, G>(&mut self, finalop: G) -> Result<U, ScanError>where
G: FnOnce(Bytes) -> Result<U, SyntaxError>,
pub fn scan_base64_phrases<U, G>(&mut self, finalop: G) -> Result<U, ScanError>where
G: FnOnce(Bytes) -> Result<U, SyntaxError>,
Scans a sequence of phrases containing base64 encoded data.
Trait Implementations
sourceimpl<C: Clone + CharSource> Clone for Scanner<C>
impl<C: Clone + CharSource> Clone for Scanner<C>
Auto Trait Implementations
impl<C> RefUnwindSafe for Scanner<C>where
C: RefUnwindSafe,
impl<C> Send for Scanner<C>where
C: Send,
impl<C> Sync for Scanner<C>where
C: Sync,
impl<C> Unpin for Scanner<C>where
C: Unpin,
impl<C> UnwindSafe for Scanner<C>where
C: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Source, Target> OctetsInto<Target> for Sourcewhere
Target: OctetsFrom<Source>,
impl<Source, Target> OctetsInto<Target> for Sourcewhere
Target: OctetsFrom<Source>,
sourcefn octets_into(self) -> Result<Target, ShortBuf>
fn octets_into(self) -> Result<Target, ShortBuf>
Performs the conversion.