Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/oxc_parser/src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ impl<'a> ParserImpl<'a> {
}

/// Get current source text
#[inline]
pub(crate) fn cur_src(&self) -> &'a str {
let range = self.cur_token().span();
// SAFETY:
Expand All @@ -53,11 +54,13 @@ impl<'a> ParserImpl<'a> {
}

/// Get current string
#[inline]
pub(crate) fn cur_string(&self) -> &'a str {
self.lexer.get_string(self.token)
}

/// Get current template string
#[inline]
pub(crate) fn cur_template_string(&self) -> Option<&'a str> {
self.lexer.get_template_string(self.token)
}
Expand Down Expand Up @@ -187,6 +190,7 @@ impl<'a> ParserImpl<'a> {
}

/// # Errors
#[inline]
pub(crate) fn expect_without_advance(&mut self, kind: Kind) {
if !self.at(kind) {
let range = self.cur_token().span();
Expand Down
5 changes: 5 additions & 0 deletions crates/oxc_parser/src/error_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct FatalError {
}

impl<'a> ParserImpl<'a> {
#[cold]
pub(crate) fn set_unexpected(&mut self) {
// The lexer should have reported a more meaningful diagnostic
// when it is a undetermined kind.
Expand All @@ -33,13 +34,15 @@ impl<'a> ParserImpl<'a> {
/// # Panics
///
/// * The lexer did not push a diagnostic when `Kind::Undetermined` is returned
#[cold]
#[must_use]
pub(crate) fn unexpected<T: Dummy<'a>>(&mut self) -> T {
self.set_unexpected();
Dummy::dummy(self.ast.allocator)
}

/// Push a Syntax Error
#[cold]
pub(crate) fn error(&mut self, error: OxcDiagnostic) {
self.errors.push(error);
}
Expand All @@ -50,13 +53,15 @@ impl<'a> ParserImpl<'a> {
}

/// Advance lexer's cursor to end of file.
#[cold]
pub(crate) fn set_fatal_error(&mut self, error: OxcDiagnostic) {
if self.fatal_error.is_none() {
self.lexer.advance_to_end();
self.fatal_error = Some(FatalError { error, errors_len: self.errors.len() });
}
}

#[cold]
pub(crate) fn fatal_error<T: Dummy<'a>>(&mut self, error: OxcDiagnostic) -> T {
self.set_fatal_error(error);
Dummy::dummy(self.ast.allocator)
Expand Down
Loading