Skip to main content

Parser

Struct Parser 

Source
pub struct Parser<'a> { /* private fields */ }
Expand description

The parser state.

Implementations§

Source§

impl<'a> Parser<'a>

Source

pub fn new(source: &'a str) -> Self

A parser over source.

Source

pub fn over(source: &'a str, tokens: Vec<Token>) -> Self

A parser over an already-lexed stream.

The preprocessor produces one: its tokens index into text it assembled from every file that contributed, so the parser lexes nothing and reads spans into that text instead.

Source

pub fn parse_file(self) -> Parse

Parse the whole file.

Source

pub fn current(&self) -> TokenKind

What the current token is.

Source

pub fn peek(&self, ahead: usize) -> TokenKind

What the token ahead positions on is.

Source

pub fn at_eof(&self) -> bool

Whether the cursor is at the end.

Source

pub fn current_span(&self) -> Span

Where the current token is.

Source

pub fn current_text(&self) -> &str

The text of the current token.

Source

pub fn bump(&mut self)

Consume the current token into the tree, trivia first.

Trivia reaches the tree through Parser::emit_leading_trivia and nowhere else, which is what keeps the round trip exact without every rule having to think about it.

Source

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

Consume the current token if it is kind.

Source

pub fn expect(&mut self, kind: TokenKind, what: &str) -> bool

Consume kind, or diagnose that it was missing.

Does not consume anything on failure: the caller’s recovery decides what to skip.

Source

pub fn start(&mut self, kind: CstKind)

Begin a node.

Source

pub fn finish(&mut self)

End the node in progress.

Source

pub fn checkpoint(&self) -> Checkpoint

Mark the current position, for wrapping already-emitted children.

Source

pub fn start_at(&mut self, checkpoint: Checkpoint, kind: CstKind)

Wrap everything since checkpoint in a node.

Source

pub fn tokens_left(&self) -> usize

How many tokens are left.

Source

pub fn split_shift_right(&mut self)

Consume the first half of a >> token, leaving the second.

sequence<sequence<long>> ends in one token that closes two argument lists. The tree records two > covering one source token, so text() still reproduces the input. Spec §2.3.

Source

pub fn diagnose( &mut self, code: DiagnosticCode, message: &str, spec_reference: &'static str, )

Record a diagnostic without consuming anything.

Source

pub fn error_token(&mut self, message: &str)

Wrap the current token in an error node and move past it.

Source

pub fn recover_to_declaration(&mut self)

Skip to the next place a declaration can begin.

Recovery points are ;, } and the top-level keywords. The skipped range becomes an error node so the round trip holds. Spec §3.2.

Source

pub fn at_recovery_point(&self) -> bool

Whether the current token can begin a declaration.

Source

pub fn diagnostics(&self) -> &[Diagnostic]

The diagnostics gathered so far.

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

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.