Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
chore: code review
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Nov 16, 2021
1 parent 95c6c60 commit f30abf2
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions crates/rslint_parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,20 @@ impl<'t> Parser<'t> {
}

/// Recover from an error with a recovery set or by using a `{` or `}`.
///
/// # Arguments
///
/// * `error` - the [Diagnostic] to emit
/// * `recovery` - it recovers the parser position is inside a set [tokens](TokenSet)
/// * `include_braces` - it recovers the parser if the current token is a curly brace
/// * `unknown_node` - The kind of the unknown node the parser inserts if it isn't able to recover because
/// the current token is neither in the recovery set nor any of `{` or `}`.
pub fn err_recover(
&mut self,
error: impl Into<ParserError>,
recovery: TokenSet,
include_braces: bool,
// The kind of unknown token the parser wanted to try to guess at that position
unknown_syntax_kind: SyntaxKind,
unknown_node: SyntaxKind,
) -> Option<()> {
if self.state.no_recovery {
return None;
Expand All @@ -208,16 +215,23 @@ impl<'t> Parser<'t> {
let m = self.start();
self.error(error);
self.bump_any();
m.complete(self, unknown_syntax_kind);
m.complete(self, unknown_node);
Some(())
}

/// Recover from an error but don't add an error to the events
///
/// # Arguments
///
/// * `recovery` - it recovers the parser position is inside a set [tokens](TokenSet)
/// * `include_braces` - it recovers the parser if the current token is a curly brace
/// * `unknown_node` - The kind of the unknown node the parser inserts if it isn't able to recover because
/// the current token is neither in the recovery set nor any of `{` or `}`.
pub fn err_recover_no_err(
&mut self,
recovery: TokenSet,
include_braces: bool,
unknown_syntax_kind: SyntaxKind,
unknown_node: SyntaxKind,
) {
match self.cur() {
T!['{'] | T!['}'] if include_braces => {
Expand All @@ -232,7 +246,7 @@ impl<'t> Parser<'t> {

let m = self.start();
self.bump_any();
m.complete(self, unknown_syntax_kind);
m.complete(self, unknown_node);
}

/// Starts a new node in the syntax tree. All nodes and tokens
Expand Down

0 comments on commit f30abf2

Please sign in to comment.