Regex for entity.function.name.lambda.kusto
triggers an Oniguruma bug
#209
Labels
entity.function.name.lambda.kusto
triggers an Oniguruma bug
#209
The regex on this line (
"(?<=let ).+(?=\\W*=)"
) triggers an Oniguruma bug that prevents it from ever matching.Specifically, a lookbehind immediately followed by a greedily-quantified
.
or\N
(which are handled the same when not using Oniguruma'sm
flag) prevent the regex from matching. So, for example, if we test it against the string"let dt = datetime(2017-01-29 09:00:05);"
(from the Kusto sample used by Shiki), it does not match, although it should. This prevents thedt
in this example string from being highlighted correctly.Additionally, since Shiki's JS engine doesn't reproduce this Oniguruma bug, it leads to Shiki listing Kusto as mismatched (unsupported) in its JS engine, since the JS engine doesn't match Oniguruma's results (even though the JS engine is in fact highlighting it correctly).
More details about the bug
We can create a reduced test case for the bug with
(?<=.).+
or(?<=.)\N+
. These do not find a match withinaa
. This bug is very specific to a greedily-quantified.
or\N
following a lookbehind. If we replace the reduced regex with any of the following, the bug is not triggered and the regex finds a match:(?<=.)[^\n]+
-- A dot excludes only\n
in Oniguruma.\n
:(?<=.)[\0-\x{10FFFF}]+
(?<=.)\O+
-- Uppercase letter O (not zero).(?<=.)(?m:.+)
(?<=.).+?
(?<=.).
Fix
I'd recommend changing the regex to
"(?<=let )[^\\n]+(?=\\W*=)"
or"(?<=let )\\O+(?=\\W*=)"
. Either of these will fix it.I'd be happy to submit a PR if that would help.
Context
Apart from when using Shiki's JS engine (which emulates Oniguruma), regexes in TextMate grammars are run in the Oniguruma regex engine. VS Code, Shiki, etc. use
vscode-oniguruma
for this.vscode-oniguruma
v1.7.0 up to the latest version are running Oniguruma 6.9.8.CC @antfu
The text was updated successfully, but these errors were encountered: