Skip to main content

Lexer

Struct Lexer 

Source
pub(super) struct Lexer<'a> {
    source: &'a str,
    position: usize,
}

Fields§

§source: &'a str§position: usize

Implementations§

Source§

impl<'a> Lexer<'a>

Source

pub(super) fn tokenize(source: &'a str) -> Result<Vec<Token<'a>>, JsonError>

Split source into tokens that cover it completely.

§Errors

Returns the first lexical error.

Source

pub(super) const fn is_line_terminator(character: char) -> bool

Source

const fn is_whitespace(character: char) -> bool

Source

fn is_identifier_start(character: char) -> bool

Source

fn is_identifier_part(character: char) -> bool

Source

const fn error(offset: usize, kind: JsonErrorKind) -> JsonError

Source

fn rest(&self) -> &'a str

Source

fn peek(&self) -> Option<char>

Source

fn peek_at(&self, index: usize) -> Option<char>

Source

fn bump(&mut self) -> Option<char>

Source

fn eat(&mut self, expected: char) -> bool

Source

fn eat_while(&mut self, accept: impl Fn(char) -> bool) -> usize

Consume characters while accept holds and count them.

Source

fn token(&mut self) -> Result<Option<Token<'a>>, JsonError>

Source

fn punctuation(&mut self, kind: TokenKind) -> TokenKind

Source

fn comment(&mut self) -> Result<TokenKind, JsonError>

Source

fn string(&mut self, quote: char) -> Result<Option<String>, JsonError>

Source

fn push(decoded: &mut Option<String>, character: char)

Source

fn escape( &mut self, string_start: usize, decoded: &mut Option<String>, ) -> Result<(), JsonError>

Read the rest of an escape in a string. The backslash is consumed.

Source

fn surrogate_pair(&mut self, high: u32) -> Option<char>

Combine a high surrogate with a following \uXXXX low surrogate.

Source

fn hex_digits(&mut self, count: usize) -> Option<u32>

Source

fn identifier(&mut self) -> Result<String, JsonError>

Source

fn number(&mut self) -> Result<TokenKind, JsonError>

Source

fn decimal(&mut self) -> bool

Decimal digits with optional fraction and exponent. Returns false when the literal is malformed.

Auto Trait Implementations§

§

impl<'a> Freeze for Lexer<'a>

§

impl<'a> RefUnwindSafe for Lexer<'a>

§

impl<'a> Send for Lexer<'a>

§

impl<'a> Sync for Lexer<'a>

§

impl<'a> Unpin for Lexer<'a>

§

impl<'a> UnsafeUnpin for Lexer<'a>

§

impl<'a> UnwindSafe for Lexer<'a>

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.