Skip to main content

Lexer

Struct Lexer 

Source
pub(super) struct Lexer<'input, const VERSION: u8, const OWNED: bool> {
    input: &'input [u8],
    depth: u8,
    byte_pos: u32,
}
Available on crate feature alloc and (crate features formatting or parsing) only.
Expand description

An iterator over the lexed tokens.

Fields§

§input: &'input [u8]§depth: u8§byte_pos: u32

Implementations§

Source§

impl<'input, const VERSION: u8, const OWNED: bool> Lexer<'input, VERSION, OWNED>

Source

pub(super) const fn new(input: &'input str) -> Self

Parse the string into a series of [Token]s.

VERSION controls the version of the format description that is being parsed.

  • When VERSION is 1, [[ is the only escape sequence, resulting in a literal [. For the start of a nested format description, a single [ is used and is never part of the escape sequence. For example, [optional [[day]]] will lex successfully, ultimately resulting in a component named optional with the nested component day.
  • When VERSION is 2 or 3, all escape sequences begin with \. The only characters that may currently follow are \, [, and ], all of which result in the literal character. All other characters result in a lex error.
Source

fn advance(&mut self, bytes: u32)

Advance the input by the given number of bytes.

Source

const fn context(&self) -> Context

Whether the lexer is currently parsing a component or a literal.

Source

fn consume_whitespace(&mut self) -> Option<Spanned<&'input str>>

Consume the next token if it is a component item that is whitespace.

Source

fn consume_component_part(&mut self) -> Option<Spanned<&'input str>>

Consume the next token if it is a component item that is not whitespace.

Source

fn consume_closing_bracket(&mut self) -> Option<Location>

Consume the next token if it is a closing bracket.

Source

fn consume_component_name( &mut self, opening_bracket: Location, ) -> Result<Spanned<&'input str>, Error>

Consume the next token if it is a component name. The caller is expected to be inside a component header.

Source

fn consume_modifier(&mut self) -> Result<NextModifier<'input>, Error>

Source

fn consume_component( &mut self, opening_bracket: Location, ) -> Result<<() as ParseTarget<'input, VERSION, OWNED>>::ItemWithLiteralLifetime, Error>
where (): ParseTarget<'input, VERSION, OWNED>,

Parse a component.

Source

fn consume_nested( &mut self, last_location: Location, ) -> Result<NestedFormatDescription<'input, <() as ParseTarget<'input, VERSION, OWNED>>::ItemWithLiteralLifetime>, Error>
where (): ParseTarget<'input, VERSION, OWNED>,

Parse a nested format description. The location provided is the most recent one consumed.

Source

fn modifier_from_token( &self, token: Spanned<&'input str>, ) -> Result<Modifier<'input>, Error>

Source

fn is_nested_description_start(&self) -> bool

Check whether the next tokens start a nested format description. Does not consume any input.

Note that this call is strictly an optimization, as checking the error path on parse_nested is sufficient for knowing if a nested format description is present. This method avoids the overhead of constructing an error only to throw it away.

Source

fn consume_literal(&mut self) -> &'input str

Source

fn consume_backslash_escape_sequence( &mut self, location: Location, ) -> Result<&'input str, Error>

Source§

impl<'input, const VERSION: u8, const OWNED: bool> Lexer<'input, VERSION, OWNED>

Source

fn parse_next_item( &mut self, ) -> Result<<() as ParseTarget<'input, VERSION, OWNED>>::ItemWithLiteralLifetime, Error>
where (): ParseTarget<'input, VERSION, OWNED>,

Auto Trait Implementations§

§

impl<'input, const VERSION: u8, const OWNED: bool> Freeze for Lexer<'input, VERSION, OWNED>

§

impl<'input, const VERSION: u8, const OWNED: bool> RefUnwindSafe for Lexer<'input, VERSION, OWNED>

§

impl<'input, const VERSION: u8, const OWNED: bool> Send for Lexer<'input, VERSION, OWNED>

§

impl<'input, const VERSION: u8, const OWNED: bool> Sync for Lexer<'input, VERSION, OWNED>

§

impl<'input, const VERSION: u8, const OWNED: bool> Unpin for Lexer<'input, VERSION, OWNED>

§

impl<'input, const VERSION: u8, const OWNED: bool> UnsafeUnpin for Lexer<'input, VERSION, OWNED>

§

impl<'input, const VERSION: u8, const OWNED: bool> UnwindSafe for Lexer<'input, VERSION, OWNED>

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> 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> SizedTypeProperties for T

Source§

#[doc(hidden)]
const SIZE: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGNMENT: Alignment = _

🔬This is a nightly-only experimental API. (ptr_alignment_type)
Source§

#[doc(hidden)]
const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
Source§

#[doc(hidden)]
const LAYOUT: Layout = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const MAX_SLICE_LEN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
The largest safe length for a [Self]. 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.