Skip to main content

Parser

Struct Parser 

Source
pub(super) struct Parser<'a> {
    tokens: Vec<Token<'a>>,
    index: usize,
    end: usize,
}

Fields§

§tokens: Vec<Token<'a>>§index: usize§end: usize

Implementations§

Source§

impl<'a> Parser<'a>

Source

pub(super) fn parse( source: &'a str, dialect: Dialect, ) -> Result<Document, JsonError>

Parse source as one JSON5 document.

Source

fn peek(&self) -> Option<&Token<'a>>

Source

const fn advance(&mut self)

Source

fn at(&self, kind: &TokenKind) -> bool

Source

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

Source

fn unexpected(&self) -> JsonError

The error for the current token, or for the end of input.

Source

fn expect(&mut self, kind: &TokenKind) -> Result<(), JsonError>

Source

fn trivia(&mut self) -> String

Consume a run of trivia tokens.

Source

fn split_line(&mut self) -> (String, String)

Consume a run of trivia tokens and split it before its first line terminator that is not inside a comment.

Source

fn tail(&mut self) -> (Tail, Next)

Read what follows a value: an optional comma and the rest of the line.

Source

fn value(&mut self, depth: usize, leading: Trivia) -> Result<Value, JsonError>

Source

fn kind(&mut self, depth: usize) -> Result<Kind, JsonError>

Source

fn scalar(&mut self, text: &str, offset: usize) -> Kind

Source

fn key(&mut self) -> Result<Key, JsonError>

Source

fn elements( &mut self, close: &TokenKind, element: impl FnMut(&mut Self, Trivia) -> Result<Next, JsonError>, ) -> Result<Trivia, JsonError>

Parse elements through the close token and return the trivia before it. element reads one element, given the trivia before it.

Source

fn object(&mut self, depth: usize) -> Result<Object, JsonError>

Parse after the opening brace, through the closing brace.

Source

fn array(&mut self, depth: usize) -> Result<Array, JsonError>

Parse after the opening bracket, through the closing bracket.

Auto Trait Implementations§

§

impl<'a> Freeze for Parser<'a>

§

impl<'a> RefUnwindSafe for Parser<'a>

§

impl<'a> Send for Parser<'a>

§

impl<'a> Sync for Parser<'a>

§

impl<'a> Unpin for Parser<'a>

§

impl<'a> UnsafeUnpin for Parser<'a>

§

impl<'a> UnwindSafe for Parser<'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.