pub struct Parser<'a> {
    pub input: &'a str,
    tokens: Lexer<'a, TokenKind>,
    peeked_tokens: VecDeque<Token>,
    current: Token,
    pub st: SyntaxTree,
    pub stack: Vec<(NodeKind, Vec<NodeChild>, usize)>,
}

Fields§

§input: &'a str§tokens: Lexer<'a, TokenKind>§peeked_tokens: VecDeque<Token>§current: Token§st: SyntaxTree§stack: Vec<(NodeKind, Vec<NodeChild>, usize)>

Implementations§

source§

impl<'a> Parser<'a>

source

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

source

fn bump(&mut self) -> Token

Consumes the current token

source

fn skip(&mut self)

Skips the current token and goes to the next. The skipped token MUST NOT be discarded. It must always be possible to reconstruct the input string from the Ast.

source

fn nth_next(&mut self, n: usize) -> Token

source

fn nth_non_whitespace(&mut self, index: &mut usize) -> Token

source

fn _next_token(&mut self) -> Token

Should only be used by nth_next and skip

source

fn current_stripped(&mut self) -> Token

source

fn expect(&mut self, kind: TokenKind) -> ParseResult<Token>

Consumes all consecutive whitespace and expects that the current token has given kind. Errors if that is not the case.

source

fn consume(&mut self, kind: TokenKind) -> ParseResult<Token>

Consume all consecutive whitespace and then consumes the next token if it equals kind. Returns whether the first non-whitespace token was consumed.

Panics

panics if the passed kind is a whitespace

source

fn consume_first_of(&mut self, options: &[TokenKind]) -> ParseResult<Token>

Consumes the first matching token of options Returns Err if no option matches

source

fn consume_first_with( &mut self, predicate: impl Fn(TokenKind) -> bool ) -> Option<Token>

source

fn consume_whitespace(&mut self)

Consumes a single whitespace token or does nothing

source

fn replace_stack(&mut self, kind: NodeKind)

source

pub fn begin(&mut self, kind: NodeKind) -> usize

Begins a node

source

pub fn begin_with(&mut self, kind: NodeKind, children_for_flat: usize) -> usize

source

pub fn end(&mut self)

Ends a node

source

fn end_inline(&mut self)

Discards the current stack kind and appends the elements to the previous node

source

fn end_to_new(&mut self, node_kind: NodeKind, children_for_flat: usize)

Creates a new node of kind node_kind and ends the current node as the first child into it

source

fn insert_full_node( &mut self, children_for_flat: usize, kind: NodeKind, children: Box<[NodeChild]> )

source

fn end_root(&mut self)

Ends the root node and sets ast.root_node accordingly

source

pub fn insert(&mut self, kind: impl Into<NodeChild>)

Adds a NodeChild to the current node

source

fn recover<const N: usize>( &mut self, to_stack_idx: usize, safety_tokens: [TokenKind; N] ) -> ParseResult<()>

Tries to advance the parser to a known safe state, so that parsing can continue

to_node is the node in the parsers stack that should be closed on success. safety_tokens is a list of tokens that, when encountered, allow successful recovery.

source

fn recover_with<const N: usize>( &mut self, to_stack_idx: usize, safety_tokens: [TokenKind; N], options: RecoveryOptions ) -> ParseResult<()>

Trait Implementations§

source§

impl Debug for Parser<'_>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.