From cfca01e88ea1a3c49542ab6a6fea44bbb0ce2522 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Wed, 6 Mar 2024 21:06:36 +0100 Subject: [PATCH] Fix `language_js` regex/comment distinction (#1731) --- data/plugins/language_js.lua | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/data/plugins/language_js.lua b/data/plugins/language_js.lua index 2eb38741..6412fdf0 100644 --- a/data/plugins/language_js.lua +++ b/data/plugins/language_js.lua @@ -57,18 +57,19 @@ syntax.add { comment = "//", block_comment = { "/*", "*/" }, patterns = { - { pattern = "//.*", type = "comment" }, - { pattern = { "/%*", "%*/" }, type = "comment" }, - { regex = regex_pattern, syntax = inner_regex_syntax, type = {"string", "string"} }, - { pattern = { '"', '"', '\\' }, type = "string" }, - { pattern = { "'", "'", '\\' }, type = "string" }, - { pattern = { "`", "`", '\\' }, type = "string" }, - { pattern = "-?0[xXbBoO][%da-fA-F_]+n?()%s*()/?", type = {"number", "normal", "operator"} }, - { pattern = "-?%d+[%d%.eE_n]*()%s*()/?", type = {"number", "normal", "operator"} }, - { pattern = "-?%.?%d+()%s*()/?", type = {"number", "normal", "operator"} }, - { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, - { pattern = "[%a_][%w_]*%f[(]", type = "function" }, - { pattern = "[%a_][%w_]*()%s*()/?", type = {"symbol", "normal", "operator"} }, + { pattern = "//.*", type = "comment" }, + { pattern = { "/%*", "%*/" }, type = "comment" }, + { regex = regex_pattern, syntax = inner_regex_syntax, type = {"string", "string"} }, + { pattern = { '"', '"', '\\' }, type = "string" }, + { pattern = { "'", "'", '\\' }, type = "string" }, + { pattern = { "`", "`", '\\' }, type = "string" }, + -- Use (?:\/(?!\/))? to avoid that a regex can start after a number, while also allowing // comments + { regex = [[-?0[xXbBoO][\da-fA-F_]+n?()\s*()(?:\/(?!\/))?]], type = {"number", "normal", "operator"} }, + { regex = [[-?\d+[0-9.eE_n]*()\s*()(?:\/(?!\/))?]], type = {"number", "normal", "operator"} }, + { regex = [[-?\.?\d+()\s*()(?:\/(?!\/))?]], type = {"number", "normal", "operator"} }, + { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, + { pattern = "[%a_][%w_]*%f[(]", type = "function" }, + { regex = [=[[a-zA-Z_]\w*()\s*()(?:\/(?!\/))?]=], type = {"symbol", "normal", "operator"} }, }, symbols = { ["async"] = "keyword",