Repository navigation
Conversation
Each tokenizer state is compiled to one regexp, so caseInsensitive on any rule made every rule of the state case-insensitive, and an explicit caseInsensitive: false had no effect. When a state mixes caseInsensitive rules with caseInsensitive: false rules, compile it without the i flag and rewrite the other rules so their letters match either case. States without a caseInsensitive: false rule are compiled as before.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available: #4887
Description of changes:
Each tokenizer state is compiled to one regexp, so
caseInsensitive: trueon any rule turns on theiflag for the whole state. A rule with an explicitcaseInsensitive: falseis matched case-insensitively too, as in the example from the issue:On master
foo FOO bar BARgives four keyword tokens. With this changefoois plain text, andFOO,barandBARare keywords.How it works: when a state has a
caseInsensitiverule and also a rule withcaseInsensitive: false, the state is compiled without theiflag. The other rules are rewritten by the newTokenizer#caseInsensitiveRegexso that their letters match either case, as suggested in the issue thread:[aA];[a-f0-9]becomes[A-Fa-f0-9]. The letters go at the start of the class, or at the end when the class starts with-. When it starts and ends with-, they go in a separate class next to it ((?:[-a-]|[A])), or in a negative lookahead for a negated class;\w,\x41,A,\u{61},\p{Lu}withunicode,\cJ,\k<name>, backreferences) and group syntax ((?:,(?=,(?<=,(?<name>) are left alone.The rewrite is used for the state regexp and for the splitter regexp of rules with token arrays.
Compatibility: a state that has no
caseInsensitive: falserule is compiled exactly as before, socaseInsensitiveon one rule still applies to the rules that don't set it (a test covers this). Across the 200 bundled modes, no state has both acaseInsensitiverule and acaseInsensitive: falserule. The only mode that usescaseInsensitive: false(logtalk) has nocaseInsensitive: truerules, so no bundled mode tokenizes differently.Limits of the rewrite: backreferences still match case-sensitively, and ranges only get the other case for ASCII letters, plus single non-ASCII letters whose other case is one character.
types/ace-modules.d.tswas regenerated withnpm run update-typesfor the new method.ace.d.ts,ace-modules.d.tsandace-extensions.d.tsdid not change.Tests: three tests in
src/tokenizer_test.js:caseInsensitive: falserule;caseInsensitiveRegex.What was run:
npx mocha src/tokenizer_test.js: 8 passing. Withsrc/tokenizer.jsreset to master, the issue-example test fails on its token assertion (foocomes out as a keyword) and the helper test fails because the method doesn't exist yet.npm test: 1498 passing, 3 pending, 2 failing. The same 2 tests fail on master in the same environment (1495 passing):mouse_handler_test.js"multiselect" andvim_test.js"copy".npx eslint src/tokenizer.js src/tokenizer_test.js,npm run update-types(only thetypes/ace-modules.d.tsaddition above),npm run typecheck, and the stricttsc ... ace.d.tscheck from CI.tool/test-npm-package.shand coverage upload.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Pull Request Checklist:
ace.d.ts) and its references:Open kitchen-sink @ a3f779626bcb366f9f7591d6af48dda253f174b2