Chevrotain
Home
Features
Tutorial
Guide
FAQ
Changes
APIs
Playground
Benchmark
Discussions
GitHub
Home
Features
Tutorial
Guide
FAQ
Changes
APIs
Playground
Benchmark
Discussions
GitHub
  • Features

    • Blazing Fast
    • LL(K) Grammars
    • Separation of Grammar and Semantics
    • Easy Debugging
    • Fault Tolerance
    • Multiple Start Rules
    • Customizable Error Messages
    • Parameterized Rules
    • Gates
    • Syntactic Content Assist
    • Grammar Inheritance
    • Backtracking
    • Syntax Diagrams
    • RegExp Based Lexers
    • Position Tracking
    • Token Alternative Matches
    • Token Skipping
    • Token Categories
    • Token Grouping
    • Custom Token Patterns
    • Lexer Modes

Token Grouping

Chevrotain lexers support grouping Tokens Types separately from the main token vector in the lexing result. This is often useful to collect a specific set of Token Types for later processing, for example to collect comments tokens.

To group a Token Type simply specify the group property in its configuration. For example:

const Comment = createToken({
  name: "Comment",
  pattern: /\/\/.+/,
  group: "comments",
});

See executable example for further details.

Edit this page on GitHub
Last Updated: 1/24/26, 5:39 PM
Contributors: Shahar Soel, Soel, bd82, i060847, I060847, Gaurav
Prev
Token Categories
Next
Custom Token Patterns