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

md-math-block uses non-Oniguruma regex #181662

Closed
jensli opened this issue May 5, 2023 · 4 comments
Closed

md-math-block uses non-Oniguruma regex #181662

jensli opened this issue May 5, 2023 · 4 comments
Assignees
Labels
debt Code quality issues help wanted Issues identified as good community contribution opportunities

Comments

@jensli
Copy link

jensli commented May 5, 2023

Does this issue occur when all extensions are disabled?: No. This is an issue in the Markdown Math extension.

  • VS Code Version: master branch commit 60fe2d5
  • OS Version: NA

The following regex in md-math-block.tmLanguage.json is not a valid TextMate regex:

"begin": "(?<=^\\s*)(\\${2})(?![^$]*\\${2})",

TextMate grammars should use the Oniguruma regex dialect. This is the regex engine used by Ruby. The given regex give the following result when tried in Ruby:

(?<=^\\s*)(\\${2})(?![^$]*\\${2})
=> jdoodle.rb:1: invalid pattern in look-behind: /(?<=^\\s*)(\\${2})(?![^$]*\\${2})/

Tested at jdoodle.com using Ruby 3.0.2.

Either the regex should be updated, or the regex implementation should be fixed to be compliant with Oniguruma.

About TextMate regexes:
https://macromates.com/manual/en/regular_expressions
https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide#textmate-grammars

This issue was first observed here: eclipse-tm4e/tm4e#525

@jensli jensli changed the title md-math-block uses non-Onigurumaregex md-math-block uses non-Oniguruma regex May 5, 2023
@vscodenpa
Copy link

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.78.0. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

@mjbvz mjbvz added the help wanted Issues identified as good community contribution opportunities label May 9, 2023
@dcourv
Copy link
Contributor

dcourv commented May 10, 2023

The issue appears to be that the first portion of the regex, (?<=^\\s*), is a lookbehind on a variable-length subexpression. Onigurama only supports lookbehind on a fixed-length subexpression.

@mjbvz mjbvz added the debt Code quality issues label May 25, 2023
@RedCMD
Copy link
Contributor

RedCMD commented May 27, 2023

vscodes TextMate engine uses the Oniguruma dialect
which does support variable length lookbehinds
https://github.com/kkos/oniguruma/blob/master/doc/SYNTAX.md#6-onig_syn_different_len_alt_look_behind-allow-abc

Oniguruma can handle either form, but not all regex engines can, so for compatibility, Oniguruma allows you to cause regexes for other regex engines to fail if they might depend on this rule.

look-behind length is however limited to 65536 characters

I personally use variable length look-behinds all the time in vscode (including negative-look-behinds)

@mjbvz
Copy link
Collaborator

mjbvz commented Dec 5, 2023

Closing as this doesn't seem like an issue for how we're using the grammar. PRs welcome if you want to provide a reasonable fix for other users

@mjbvz mjbvz closed this as completed Dec 5, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jan 20, 2024
@aiday-mar aiday-mar added this to the December / January 2024 milestone Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debt Code quality issues help wanted Issues identified as good community contribution opportunities
Projects
None yet
Development

No branches or pull requests

6 participants