Cannot match characters when using the pattern [\S]+
#1536
Answered
by
bd82
BlackGlory
asked this question in
Q&A
-
This is very strange, aren’t code: import { createToken, Lexer } from 'chevrotain'
test('pass', () => {
const Text = createToken({
name: 'Text'
, pattern: /\S+/
})
const MyLexer = new Lexer([Text])
const result = MyLexer.tokenize('test')
expect(result.errors.length).toBe(0) // ok
})
test('error', () => {
const Text = createToken({
name: 'Text'
, pattern: /[\S]+/
})
const MyLexer = new Lexer([Text])
const result = MyLexer.tokenize('test')
expect(result.errors.length).toBe(0) // oops
})
test('RE', () => {
expect(/^\S+$/.test('test')).toBe(true) // ok
expect(/^[\S]+$/.test('test')).toBe(true) // ok
}) errors:
|
Beta Was this translation helpful? Give feedback.
Answered by
bd82
Jun 9, 2021
Replies: 1 comment 5 replies
-
Seems like a bug in RegExp to AST. A whole characterSet can be marked as a complement, but the complement info of "negative" character escapes ( |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
BlackGlory
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems like a bug in RegExp to AST.
A whole characterSet can be marked as a complement, but the complement info of "negative" character escapes (
\S
,\D
...) are ignored.