Skip to content
This repository was archived by the owner on Jan 27, 2025. It is now read-only.
This repository was archived by the owner on Jan 27, 2025. It is now read-only.

We should be able to create custom TokenKind that doesn't fall in any category #6

Description

@Gipson62

Proposal: Support Custom Token Kinds in lexer_builder!
Problem:

Currently, when defining language-specific constructs like @extern or #include, the resulting tokens are split into multiple TokenKinds such as [At, Keyword("extern")]. However, some users may prefer a single, unique TokenKind for such constructs that isn't treated as an identifier or keyword.
Proposed Solution:

Introduce a way to define custom token kinds directly in the lexer_builder! macro. For example:

lexer_builder!(
  /*
    Rest of the lexer definition...
  */
  Custom {
    Extern,
    Include
  }
)

With this feature, users could define custom TokenKinds like Extern or Include and create their own systems for processing these tokens.
Example:

A user could implement a function that outputs these custom tokens. For instance:

fn macro_start(state: LexerState) -> Option<TokenKind> {
    // Logic to recognize and return a custom token
}

This approach would give developers more flexibility in building lexers tailored to their language's unique requirements

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions