Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected character error does not show correct column #1969

Closed
baodart opened this issue Jul 24, 2023 · 2 comments
Closed

Unexpected character error does not show correct column #1969

baodart opened this issue Jul 24, 2023 · 2 comments

Comments

@baodart
Copy link

baodart commented Jul 24, 2023

Here's a reproduction example:

import { createToken, Lexer } from 'chevrotain'

const WHITESPACE = createToken({ name: 'WHITESPACE', pattern: /\s+/, group: Lexer.SKIPPED })
const NUMBER = createToken({ name: 'NUMBER', pattern: /(0|[1-9]\d*)(\.\d+)?/ })

const lexer = new Lexer([WHITESPACE, NUMBER], { ensureOptimizations: true })

const { tokens, errors } = lexer.tokenize('-"5"')

console.log('tokens', tokens)
console.log('errors', errors)

which logs
image

As the lexer can only understand whitespace and number literal, only 5 is captured as tokens here. There are 2 'unexpected character' errors:

  • The - with offset 0 and column 1 (correct)
  • The (second) " with offset 3 but column 2 (incorrect as 2 is the column of the first ") instead of 4
@bd82
Copy link
Member

bd82 commented Aug 14, 2023

Thanks for reporting this @baodart and providing a minimal reproduction 👍

There is another issue here, the valid token "5" column is reported as 1 instead of 3
I suspect that the logic to keep track of column numbers in case of lexer error recovery.

@bd82 bd82 closed this as completed in d50420d Aug 14, 2023
@bd82
Copy link
Member

bd82 commented Aug 14, 2023

fix was released in 11.0.3 version available on npm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants