Search code examples
javascriptprogramming-languagessyntax-highlightingace-editor

Ace Editor - Add regex flag to custom highliting rule


In the Ace editor, is there a way to add regex flags to the regex used to parse the highlighting rules? I want to be able to highlight rules using unicode category classes, is there a way to add the /u flag to the flags fed to Ace?

When I add the unicode flag to the regex inside the json where I define them, they fail. The rules in my json look like this:

{
    "regex": "/(^ *)([\\p{Lu}\\p{Ll}\\p{Lt}\\p{Lm}\\p{Lo}\\p{Nl}_]+|[\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}·]+)( +)(__is__)( *)(__ask__)/gu",
    "token": [
        "text",
        "text",
        "text",
        "keyword",
        "text",
        "keyword"
    ],
    "next": "valueExpr"
}

Solution

  • You can add unicode: true to the rule to add the flag to the regexp created for the all rules in the state. https://github.com/ajaxorg/ace/blob/28103d4690eac107cfd50c315da37a4ec10c18bb/src/tokenizer.js#L36