Parser

Trait Parser 

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

Show 35 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<'l, Lex>(&mut self, n: usize) -> Self::Kind where Lex: LexerWithCheckpoint<'l, Kind = Self::Kind>, Self::Source: NthToken<Lex> + TokenSourceWithBufferedLexer<Lex> { ... } fn nth_at<'l, Lex>(&mut self, n: usize, kind: Self::Kind) -> bool where Lex: LexerWithCheckpoint<'l, Kind = Self::Kind>, Self::Source: NthToken<Lex> + TokenSourceWithBufferedLexer<Lex> { ... } fn nth_at_ts<'l, Lex>( &mut self, n: usize, kinds: TokenSet<Self::Kind>, ) -> bool where Lex: LexerWithCheckpoint<'l, Kind = Self::Kind>, Self::Source: NthToken<Lex> + TokenSourceWithBufferedLexer<Lex> { ... } fn has_nth_preceding_line_break<'l, Lex>(&mut self, n: usize) -> bool where Lex: LexerWithCheckpoint<'l, Kind = Self::Kind>, Self::Source: NthToken<Lex> + TokenSourceWithBufferedLexer<Lex> { ... } 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<'l, Lex>(&mut self, n: usize) -> Self::Kind
where Lex: LexerWithCheckpoint<'l, Kind = Self::Kind>, Self::Source: NthToken<Lex> + TokenSourceWithBufferedLexer<Lex>,

Look ahead at a token and get its kind.

Source

fn nth_at<'l, Lex>(&mut self, n: usize, kind: Self::Kind) -> bool
where Lex: LexerWithCheckpoint<'l, Kind = Self::Kind>, Self::Source: NthToken<Lex> + TokenSourceWithBufferedLexer<Lex>,

Checks if a token lookahead is something

Source

fn nth_at_ts<'l, Lex>(&mut self, n: usize, kinds: TokenSet<Self::Kind>) -> bool
where Lex: LexerWithCheckpoint<'l, Kind = Self::Kind>, Self::Source: NthToken<Lex> + TokenSourceWithBufferedLexer<Lex>,

Checks if a token set lookahead is something

Source

fn has_nth_preceding_line_break<'l, Lex>(&mut self, n: usize) -> bool
where Lex: LexerWithCheckpoint<'l, Kind = Self::Kind>, Self::Source: NthToken<Lex> + TokenSourceWithBufferedLexer<Lex>,

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 token set 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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§