Struct Scanner

Source
pub struct Scanner<C: CharSource> { /* private fields */ }
Expand description

Reader of master file tokens.

A scanner reads characters from a source and converts them into tokens or errors.

Implementations§

Source§

impl<C: CharSource> Scanner<C>

§Creation

Source

pub fn new(chars: C) -> Self

Creates a new scanner.

Source

pub fn with_pos(chars: C, pos: Pos) -> Self

Creates a new scanner using the given character source and position.

The scanner will assume that the current position of chars corresponds to the human-friendly position pos.

Source§

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.

Source

pub fn origin(&self) -> &Option<Dname>

Returns the current origin if any.

Source

pub fn set_origin(&mut self, origin: Option<Dname>)

Sets the origin to the given value.

Source§

impl<C: CharSource> Scanner<C>

§Fundamental Scanning

Source

pub fn is_eof(&mut self) -> bool

Returns whether the scanner has reached the end of data.

Source

pub fn pos(&self) -> Pos

Returns the current position of the scanner.

Source

pub fn scan_word<T, U, F, G>( &mut self, target: T, symbolop: F, finalop: G, ) -> Result<U, ScanError>

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.

Source

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.

Source

pub fn scan_quoted<T, U, F, G>( &mut self, target: T, symbolop: F, finalop: G, ) -> Result<U, ScanError>

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.

Source

pub fn scan_phrase<T, U, F, G>( &mut self, target: T, symbolop: F, finalop: G, ) -> Result<U, ScanError>

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn scan_opt_space(&mut self) -> Result<(), ScanError>

Scans over an optional sequence of space.

Source

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.

Source

pub fn skip_literal(&mut self, literal: &str) -> Result<(), ScanError>

Skips over the word with the content literal.

The content indeed needs to be literally the literal. Escapes are not translated before comparison and case has to be as is.

Source§

impl<C: CharSource> Scanner<C>

§Complex Scanning

Source

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.

Source

pub fn scan_hex_words<U, G>(&mut self, finalop: G) -> Result<U, ScanError>
where G: FnOnce(Bytes) -> Result<U, SyntaxError>,

Source

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.

Source

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§

Source§

impl<C: Clone + CharSource> Clone for Scanner<C>

Source§

fn clone(&self) -> Scanner<C>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C: Debug + CharSource> Debug for Scanner<C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<C> !Freeze for Scanner<C>

§

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§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.