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

Customizable Error Messages

Chevrotain allows users to customize both the parser and lexer error messages. This can be accomplished by implementing the following interfaces:

  • IParserErrorMessageProvider
  • ILexerErrorMessageProvider

See executable examples:

  • Custom Parser Errors.
  • Custom Lexer Errors.

In addition it is also possible to directly provide strings values to be used in errors for specific parsing DSL methods, for example:

$.RULE("myStatement", () => {
  // ...
  $.CONSUME(SemiColon, {
    ERR_MSG: "expecting semiColon at end of myStatement",
  });
});

The ERR_MSG config property is available for the following DSL methods:

  • CONSUME
  • OR
  • AT_LEAST_ONE
  • AT_LEAST_ONE_SEP
Edit this page on GitHub
Last Updated: 1/24/26, 5:39 PM
Contributors: Soel, bd82, Shahar Soel, i060847, I060847, Gaurav
Prev
Multiple Start Rules
Next
Parameterized Rules