-
This is an example of the preprocessor syntax in the language I want to write syntax highlighting rules for:
I'm totally dumb about Lua patterns (and regular expressions, too). Note: The rule in VSCode syntax highlighting is:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
RegEx is essentially correct, all vscode regex should work on ecode. But this particular one does something I wouldn't do on ecode because it's not needed and does not match how the parser works, but i think it's the only rule won't be equal on ecode: new lines don't need to be evaluated as part of the regex, alsp the RegEx and LuaPattern this time are essentially equal, Lua Patterns support some extra shorthand like
the only thing that changes is that regex use backslash () as escape character and lua pattenrs use The double backslash is because this was inside a string, the actual regex is: I highly recommend learning pattern matching if you're interested in implementing new highlighters. Also to add:
in a ecode definition that would be: { { "^%s*(@[A-Za-z_]%w*)%s*(%:%s*%w+%s*)$" }, { "normal", "keyword", "keyword2" } }, json: {
"pattern": "^%s*(@[A-Za-z_]%w*)%s*(%:%s*%w+%s*)$",
"type": [ "normal", "keyword", "keyword2" ]
} |
Beta Was this translation helpful? Give feedback.
RegEx is essentially correct, all vscode regex should work on ecode. But this particular one does something I wouldn't do on ecode because it's not needed and does not match how the parser works, but i think it's the only rule won't be equal on ecode: new lines don't need to be evaluated as part of the regex, alsp the
(?x)
is a flag and it's not needed for that specific regex, and the last?
is redundant, so in short:^\\s*(@[A-Za-z_]\\w*)\\s*(:\\s*\\w+\\s*)$
would do the job in ecode (removed all the unnecessary stuff), although is a very simple regex that can be represented with lua patterns which are faster:
^%s*(@[%a_]%w*)%s*(%:%s*%w+%s*)$
RegEx and LuaPattern this time are essentiall…