Skip to content
Merged
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
16 changes: 16 additions & 0 deletions crates/oxc_parser/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ pub trait LexerConfig: Default {
/// Byte handlers table type.
type ByteHandlers: Index<usize, Output = ByteHandler<Self>>;

/// `true` if [`tokens`] method returns a static value.
///
/// This const is useful in situations where code can be more efficient
/// when the return value of [`tokens`] method is known at compile time.
///
/// Implementors of this trait MUST only set this const to `true` if [`tokens`] method returns a static value.
///
/// [`tokens`]: LexerConfig::tokens
const TOKENS_METHOD_IS_STATIC: bool;

/// Returns `true` if tokens are enabled.
fn tokens(&self) -> bool;

Expand All @@ -128,6 +138,8 @@ pub struct NoTokensLexerConfig;
impl LexerConfig for NoTokensLexerConfig {
type ByteHandlers = ByteHandlers<Self>;

const TOKENS_METHOD_IS_STATIC: bool = true;

#[inline(always)]
fn tokens(&self) -> bool {
false
Expand All @@ -146,6 +158,8 @@ pub struct TokensLexerConfig;
impl LexerConfig for TokensLexerConfig {
type ByteHandlers = ByteHandlers<Self>;

const TOKENS_METHOD_IS_STATIC: bool = true;

#[inline(always)]
fn tokens(&self) -> bool {
true
Expand Down Expand Up @@ -174,6 +188,8 @@ impl RuntimeLexerConfig {
impl LexerConfig for RuntimeLexerConfig {
type ByteHandlers = ByteHandlers<Self>;

const TOKENS_METHOD_IS_STATIC: bool = false;

#[inline(always)]
fn tokens(&self) -> bool {
self.tokens
Expand Down
Loading