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§
type Kind: SyntaxKind
type Source: TokenSource<Kind = Self::Kind>
Required Methods§
sourcefn context(&self) -> &ParserContext<Self::Kind>
fn context(&self) -> &ParserContext<Self::Kind>
Returns a reference to the ParserContext
sourcefn context_mut(&mut self) -> &mut ParserContext<Self::Kind>
fn context_mut(&mut self) -> &mut ParserContext<Self::Kind>
Returns a mutable reference to the ParserContext.
sourcefn source(&self) -> &Self::Source
fn source(&self) -> &Self::Source
Returns a reference to the `TokenSource``(TokenSource]
sourcefn source_mut(&mut self) -> &mut Self::Source
fn source_mut(&mut self) -> &mut Self::Source
Returns a mutable reference to the TokenSource
Provided Methods§
sourcefn is_speculative_parsing(&self) -> bool
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.
sourcefn has_preceding_line_break(&self) -> bool
fn has_preceding_line_break(&self) -> bool
Tests if there’s a line break before the current token (between the last and current)
sourcefn at_ts(&self, kinds: TokenSet<Self::Kind>) -> bool
fn at_ts(&self, kinds: TokenSet<Self::Kind>) -> bool
Check if the parser’s current token is contained in a token set
sourcefn nth_at(&mut self, n: usize, kind: Self::Kind) -> bool
fn nth_at(&mut self, n: usize, kind: Self::Kind) -> bool
Checks if a token lookahead is something
sourcefn has_nth_preceding_line_break(&mut self, n: usize) -> bool
fn has_nth_preceding_line_break(&mut self, n: usize) -> bool
Tests if there’s a line break before the nth token.
sourcefn bump_remap_with_context(
&mut self,
kind: Self::Kind,
context: <Self::Source as BumpWithContext>::Context
)where
Self::Source: BumpWithContext,
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.
sourcefn bump_remap(&mut self, kind: Self::Kind)
fn bump_remap(&mut self, kind: Self::Kind)
Consume any token but cast it as a different kind
sourcefn bump_any(&mut self)
fn bump_any(&mut self)
Bumps the current token regardless of its kind and advances to the next token.
sourcefn bump_with_context(
&mut self,
kind: Self::Kind,
context: <Self::Source as BumpWithContext>::Context
)where
Self::Source: BumpWithContext,
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.
sourcefn eat_with_context(
&mut self,
kind: Self::Kind,
context: <Self::Source as BumpWithContext>::Context
) -> boolwhere
Self::Source: BumpWithContext,
fn eat_with_context(
&mut self,
kind: Self::Kind,
context: <Self::Source as BumpWithContext>::Context
) -> boolwhere
Self::Source: BumpWithContext,
Consume the next token if kind matches using the specified `context.
sourcefn eat_ts(&mut self, kinds: TokenSet<Self::Kind>) -> bool
fn eat_ts(&mut self, kinds: TokenSet<Self::Kind>) -> bool
Consume the next token if token set matches.
sourcefn eat_ts_with_context(
&mut self,
kinds: TokenSet<Self::Kind>,
context: <Self::Source as BumpWithContext>::Context
) -> boolwhere
Self::Source: BumpWithContext,
fn eat_ts_with_context(
&mut self,
kinds: TokenSet<Self::Kind>,
context: <Self::Source as BumpWithContext>::Context
) -> boolwhere
Self::Source: BumpWithContext,
Consume the next token if token set matches using the specified `context.
sourcefn expect_with_context(
&mut self,
kind: Self::Kind,
context: <Self::Source as BumpWithContext>::Context
) -> boolwhere
Self::Source: BumpWithContext,
fn expect_with_context(
&mut self,
kind: Self::Kind,
context: <Self::Source as BumpWithContext>::Context
) -> boolwhere
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.
sourcefn expect(&mut self, kind: Self::Kind) -> bool
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.
sourcefn parse_as_skipped_trivia_tokens<P>(&mut self, parse: P)
fn parse_as_skipped_trivia_tokens<P>(&mut self, parse: P)
Allows parsing an unsupported syntax as skipped trivia tokens.
sourcefn error(&mut self, err: impl ToDiagnostic<Self>)
fn error(&mut self, err: impl ToDiagnostic<Self>)
Add a diagnostic
sourcefn err_builder(
&self,
message: impl Display,
span: impl AsSpan
) -> ParseDiagnostic
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
sourcefn err_and_bump(
&mut self,
err: impl ToDiagnostic<Self>,
unknown_syntax_kind: Self::Kind
)
fn err_and_bump( &mut self, err: impl ToDiagnostic<Self>, unknown_syntax_kind: Self::Kind )
Bump and add an error event