Replies: 1 comment
|
I don't think I thought of lexer error recovery in combination with token modes. I naively suspect this empty token could theoretically cause problems. In the worst case you can always roll your own lexer which produces Chevrotain like tokens Another (verbose) optionsDuplicate the definitions all the tokens from the "parent" mode const BazTok = createToken({
name: "Baz",
pattern: "baz",
pop_mode: true
})
createToken({
name: "BazInner",
pattern: "baz",
// pop to exit inner mode
pop_mode: true
// category allows BazInner to match in the Parser where `BazTok` would also match
// https://chevrotain.io/docs/features/token_categories.html#token-categories
categories: [BazTok],
})Preprocess: Maybe its not a Chevrotain Lexer problem.This seems like cleanest approach with the most powerful possibilities. If your problem is matching brackets, You could run your own separate mini lexer first which
Note this will cause offsets and line/column position to be invalid |
Uh oh!
There was an error while loading. Please reload this page.
Hi, I have a question about Chevrotain lexer modes.
For string templates like:
"foo {{ bar }} baz"I use a separate mode for the {{ ... }} section. The issue is malformed input like:
"foo {{ bar baz"If }} is missing, the lexer may stay in the inner mode and consume too much input.
I found that this seems to work:
So I am using an empty token as a fallback to pop the mode.
Is this actually supported, or is it accidental / a bug? If I rely on it, what problems could it cause? For example, could it lead to non-advancing lexing, infinite loops, or broken recovery?
Also, what is the recommended way to recover from an unterminated mode like this in Chevrotain?
All reactions