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
Consume token single character pattern case #1141
Comments
Thanks for reporting this @janisdd I am guessing this may be related to some single character optimization not taking into account the existence of the ignore case flag |
Here is a possible fix https://github.com/SAP/chevrotain/blob/master/packages/chevrotain/src/scan/lexer.ts#L127 -regExpSource !== "."
+regExpSource !== "." &&
+ !currPattern.ignoreCase And maybe the following tests below it("can create a token from a single character regex with ignore flag", () => {
let input = "a"
let result = testLexer.tokenize(input)
expect(tokenMatcher(result.tokens[0], SingleCharacterWithIgnoreCaseFlagTok)).to.be.true
expect(result.tokens[0].image).to.equal("a")
expect(result.tokens[0].startOffset).to.equal(0)
input = "A"
result = testLexer.tokenize(input)
expect(tokenMatcher(result.tokens[0], SingleCharacterWithIgnoreCaseFlagTok)).to.be.true
expect(result.tokens[0].image).to.equal("A")
expect(result.tokens[0].startOffset).to.equal(0)
}) I tried adding a check below https://github.com/SAP/chevrotain/blob/master/packages/chevrotain/test/scan/regexp_spec.ts#L81 it("Can compute for single ignore case", () => {
expect(getOptimizedStartCodesIndices(/a/i)).to.deep.equal([
65,
97
])
}) but it seems to work fine there without the fix. So this test is probably not needed. I also noticed some smaller unattractive typings In https://github.com/SAP/chevrotain/blob/master/packages/chevrotain/src/scan/lexer.ts there are many any typed vars e.g. In https://github.com/SAP/chevrotain/blob/master/packages/chevrotain/src/utils/utils.ts#L44 the type is missing. It probably should be -export function map<I, O>(arr: I[], callback: (I, idx?: number) => O): O[] {
+export function map<I, O>(arr: I[], callback: (i:I, idx?: number) => O): O[] { After this changed there are some errors in the https://github.com/SAP/chevrotain/blob/master/packages/chevrotain/src/scan/lexer.ts This led me to some other things in https://github.com/SAP/chevrotain/blob/master/packages/chevrotain/src/utils/utils.ts https://github.com/SAP/chevrotain/blob/master/packages/chevrotain/src/utils/utils.ts#L93 can be (using user defined type guards) export function isString(item: any): item is string {
return typeof item === "string"
} same as the others below But this is somewhat out of scope here... just wanted to write it down ;) |
Thanks @janisdd do you want to create a PR?
I suppose this is a combination of:
|
It looks like a token with a single character e.g.
/a/i
ignores the case insensitive flag.Here is an example to paste in the playground at https://sap.github.io/chevrotain/playground/
When you input
a
it works fine but fails forA
.However, if you change the regex pattern to
/(a)/i
it works for both cases.I know it's just a small issue and can also easily worked around with
/(a|A)/
but just wanted to let you know.It might be connected to issue #817 and/or #708
Or am I missing something?
The text was updated successfully, but these errors were encountered: