pub trait Parser: Sized {
type Kind: SyntaxKind;
type Source: TokenSource<Kind = Self::Kind>;
Show 28 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_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(&mut self, kind: Self::Kind) -> bool { ... }
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(&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 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)where
P: FnOnce(&mut Self),
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.
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
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.