Trait biome_parser::Parser

source ·
pub trait Parser: Sized {
    type Kind: SyntaxKind;
    type Source: TokenSource<Kind = Self::Kind>;

Show 34 methods // Required methods fn context(&self) -> &ParserContext<Self::Kind>; fn context_mut(&mut self) -> &mut ParserContext<Self::Kind>; fn source(&self) -> &Self::Source; fn source_mut(&mut self) -> &mut Self::Source; // Provided methods fn is_speculative_parsing(&self) -> bool { ... } fn text(&self, span: TextRange) -> &str { ... } fn cur(&self) -> Self::Kind { ... } fn cur_range(&self) -> TextRange { ... } fn has_preceding_line_break(&self) -> bool { ... } fn cur_text(&self) -> &str { ... } fn at(&self, kind: Self::Kind) -> bool { ... } fn at_ts(&self, kinds: TokenSet<Self::Kind>) -> bool { ... } fn nth(&mut self, n: usize) -> Self::Kind where Self::Source: NthToken { ... } fn nth_at(&mut self, n: usize, kind: Self::Kind) -> bool where Self::Source: NthToken { ... } fn has_nth_preceding_line_break(&mut self, n: usize) -> bool where Self::Source: NthToken { ... } fn bump(&mut self, kind: Self::Kind) { ... } fn bump_ts(&mut self, kinds: TokenSet<Self::Kind>) { ... } fn bump_remap_with_context( &mut self, kind: Self::Kind, context: <Self::Source as BumpWithContext>::Context ) where Self::Source: BumpWithContext { ... } fn bump_remap(&mut self, kind: Self::Kind) { ... } fn bump_any(&mut self) { ... } fn bump_with_context( &mut self, kind: Self::Kind, context: <Self::Source as BumpWithContext>::Context ) where Self::Source: BumpWithContext { ... } fn eat_with_context( &mut self, kind: Self::Kind, context: <Self::Source as BumpWithContext>::Context ) -> bool where Self::Source: BumpWithContext { ... } fn eat(&mut self, kind: Self::Kind) -> bool { ... } fn eat_ts(&mut self, kinds: TokenSet<Self::Kind>) -> bool { ... } fn eat_ts_with_context( &mut self, kinds: TokenSet<Self::Kind>, context: <Self::Source as BumpWithContext>::Context ) -> bool where Self::Source: BumpWithContext { ... } fn expect_with_context( &mut self, kind: Self::Kind, context: <Self::Source as BumpWithContext>::Context ) -> bool where Self::Source: BumpWithContext { ... } fn expect(&mut self, kind: Self::Kind) -> bool { ... } fn parse_as_skipped_trivia_tokens<P>(&mut self, parse: P) where P: FnOnce(&mut Self) { ... } fn error(&mut self, err: impl ToDiagnostic<Self>) { ... } fn err_builder( &self, message: impl Display, span: impl AsSpan ) -> ParseDiagnostic { ... } fn err_and_bump( &mut self, err: impl ToDiagnostic<Self>, unknown_syntax_kind: Self::Kind ) { ... } fn last(&self) -> Option<Self::Kind> { ... } fn last_end(&self) -> Option<TextSize> { ... } fn start(&mut self) -> Marker { ... }
}

Required Associated Types§

Required Methods§

source

fn context(&self) -> &ParserContext<Self::Kind>

Returns a reference to the ParserContext

source

fn context_mut(&mut self) -> &mut ParserContext<Self::Kind>

Returns a mutable reference to the ParserContext.

source

fn source(&self) -> &Self::Source

Returns a reference to the `TokenSource``(TokenSource]

source

fn source_mut(&mut self) -> &mut Self::Source

Returns a mutable reference to the TokenSource

Provided Methods§

source

fn is_speculative_parsing(&self) -> bool

Returns true if the parser is trying to parse some syntax but only if it has no errors.

Returning true disables more involved error recovery.

source

fn text(&self, span: TextRange) -> &str

Gets the source text of a range

Panics

If the range is out of bounds

source

fn cur(&self) -> Self::Kind

Gets the current token kind of the parser

source

fn cur_range(&self) -> TextRange

Gets the range of the current token

source

fn has_preceding_line_break(&self) -> bool

Tests if there’s a line break before the current token (between the last and current)

source

fn cur_text(&self) -> &str

Get the source code of the parser’s current token.

source

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

Checks if the parser is currently at a specific token

source

fn at_ts(&self, kinds: TokenSet<Self::Kind>) -> bool

Check if the parser’s current token is contained in a token set

source

fn nth(&mut self, n: usize) -> Self::Kind
where Self::Source: NthToken,

Look ahead at a token and get its kind.

source

fn nth_at(&mut self, n: usize, kind: Self::Kind) -> bool
where Self::Source: NthToken,

Checks if a token lookahead is something

source

fn has_nth_preceding_line_break(&mut self, n: usize) -> bool
where Self::Source: NthToken,

Tests if there’s a line break before the nth token.

source

fn bump(&mut self, kind: Self::Kind)

Consume the current token if kind matches.

source

fn bump_ts(&mut self, kinds: TokenSet<Self::Kind>)

Consume the current token if kind matches.

source

fn bump_remap_with_context( &mut self, kind: Self::Kind, context: <Self::Source as BumpWithContext>::Context )
where Self::Source: BumpWithContext,

Consume any token but cast it as a different kind using the specified `context.

source

fn bump_remap(&mut self, kind: Self::Kind)

Consume any token but cast it as a different kind

source

fn bump_any(&mut self)

Bumps the current token regardless of its kind and advances to the next token.

source

fn bump_with_context( &mut self, kind: Self::Kind, context: <Self::Source as BumpWithContext>::Context )
where Self::Source: BumpWithContext,

Consumes the current token if kind matches and lexes the next token using the specified `context.

source

fn eat_with_context( &mut self, kind: Self::Kind, context: <Self::Source as BumpWithContext>::Context ) -> bool
where Self::Source: BumpWithContext,

Consume the next token if kind matches using the specified `context.

source

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

Consume the next token if kind matches.

source

fn eat_ts(&mut self, kinds: TokenSet<Self::Kind>) -> bool

Consume the next token if token set matches.

source

fn eat_ts_with_context( &mut self, kinds: TokenSet<Self::Kind>, context: <Self::Source as BumpWithContext>::Context ) -> bool
where Self::Source: BumpWithContext,

Consume the next token if token set matches using the specified `context.

source

fn expect_with_context( &mut self, kind: Self::Kind, context: <Self::Source as BumpWithContext>::Context ) -> bool
where Self::Source: BumpWithContext,

Try to eat a specific token kind, if the kind is not there then adds an error to the events stack using the specified `context.

source

fn expect(&mut self, kind: Self::Kind) -> bool

Try to eat a specific token kind, if the kind is not there then adds an error to the events stack.

source

fn parse_as_skipped_trivia_tokens<P>(&mut self, parse: P)
where P: FnOnce(&mut Self),

Allows parsing an unsupported syntax as skipped trivia tokens.

source

fn error(&mut self, err: impl ToDiagnostic<Self>)

Add a diagnostic

source

fn err_builder( &self, message: impl Display, span: impl AsSpan ) -> ParseDiagnostic

Creates a new diagnostic. Pass the message and the range where the error occurred

source

fn err_and_bump( &mut self, err: impl ToDiagnostic<Self>, unknown_syntax_kind: Self::Kind )

Bump and add an error event

source

fn last(&self) -> Option<Self::Kind>

Returns the kind of the last bumped token.

source

fn last_end(&self) -> Option<TextSize>

Returns the end offset of the last bumped token.

source

fn start(&mut self) -> Marker

Starts a new node in the syntax tree. All nodes and tokens consumed between the start and the corresponding Marker::complete belong to the same node.

Object Safety§

This trait is not object safe.

Implementors§