pub(super) struct Lexer<'input, const VERSION: u8, const OWNED: bool> {
input: &'input [u8],
depth: u8,
byte_pos: u32,
}alloc and (crate features formatting or parsing) only.Expand description
An iterator over the lexed tokens.
Fields§
§input: &'input [u8]§depth: u8§byte_pos: u32Implementations§
Source§impl<'input, const VERSION: u8, const OWNED: bool> Lexer<'input, VERSION, OWNED>
impl<'input, const VERSION: u8, const OWNED: bool> Lexer<'input, VERSION, OWNED>
Sourcepub(super) const fn new(input: &'input str) -> Self
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
VERSIONis 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 namedoptionalwith the nested componentday. - When
VERSIONis 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.
Sourceconst fn context(&self) -> Context
const fn context(&self) -> Context
Whether the lexer is currently parsing a component or a literal.
Sourcefn consume_whitespace(&mut self) -> Option<Spanned<&'input str>>
fn consume_whitespace(&mut self) -> Option<Spanned<&'input str>>
Consume the next token if it is a component item that is whitespace.
Sourcefn consume_component_part(&mut self) -> Option<Spanned<&'input str>>
fn consume_component_part(&mut self) -> Option<Spanned<&'input str>>
Consume the next token if it is a component item that is not whitespace.
Sourcefn consume_closing_bracket(&mut self) -> Option<Location>
fn consume_closing_bracket(&mut self) -> Option<Location>
Consume the next token if it is a closing bracket.
Sourcefn consume_component_name(
&mut self,
opening_bracket: Location,
) -> Result<Spanned<&'input str>, Error>
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.
fn consume_modifier(&mut self) -> Result<NextModifier<'input>, Error>
Sourcefn consume_component(
&mut self,
opening_bracket: Location,
) -> Result<<() as ParseTarget<'input, VERSION, OWNED>>::ItemWithLiteralLifetime, Error>where
(): ParseTarget<'input, VERSION, OWNED>,
fn consume_component(
&mut self,
opening_bracket: Location,
) -> Result<<() as ParseTarget<'input, VERSION, OWNED>>::ItemWithLiteralLifetime, Error>where
(): ParseTarget<'input, VERSION, OWNED>,
Parse a component.
Sourcefn consume_nested(
&mut self,
last_location: Location,
) -> Result<NestedFormatDescription<'input, <() as ParseTarget<'input, VERSION, OWNED>>::ItemWithLiteralLifetime>, Error>where
(): ParseTarget<'input, VERSION, OWNED>,
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.
fn modifier_from_token( &self, token: Spanned<&'input str>, ) -> Result<Modifier<'input>, Error>
Sourcefn is_nested_description_start(&self) -> bool
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.
fn consume_literal(&mut self) -> &'input str
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>
impl<'input, const VERSION: u8, const OWNED: bool> Lexer<'input, VERSION, OWNED>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read more