From 026d2a4271fc992f61772625c8c1d9786804cd1d Mon Sep 17 00:00:00 2001 From: Takase <20792268+takase1121@users.noreply.github.com> Date: Sat, 15 Mar 2025 23:59:21 +0800 Subject: [PATCH] language_cpp: add back digit separators (#2026) * language_cpp: add back digit separators * language_cpp: rewrite number matching in regex * language_c: port digit separators over from language_cpp (cherry picked from commit 8ea0393800bb59a214e8a6efd5b9fb69282803a9) --- data/plugins/language_c.lua | 29 ++++++++++++++--------------- data/plugins/language_cpp.lua | 35 +++++++++++++++++------------------ 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/data/plugins/language_c.lua b/data/plugins/language_c.lua index 2804fb7..f80cd47 100644 --- a/data/plugins/language_c.lua +++ b/data/plugins/language_c.lua @@ -5,6 +5,8 @@ local syntax = require "core.syntax" local isuf = [[(?:[lL][uU]|ll[uU]|LL[uU]|[uU][lL]\b|[uU]ll|[uU]LL|[uU]|[lL]\b|ll|LL)?]] -- float suffix combinations as a Lua pattern / regex local fsuf = "[fFlL]?" +-- number with digit separator as a regex non-capturing group +local digitsep = [[(?:\d[\d']*)]] syntax.add { name = "C", @@ -12,21 +14,18 @@ syntax.add { comment = "//", block_comment = { "/*", "*/" }, patterns = { - { pattern = "//.*", type = "comment" }, - { pattern = { "/%*", "%*/" }, type = "comment" }, - { pattern = { '"', '"', '\\' }, type = "string" }, - { pattern = { "'", "'", '\\' }, type = "string" }, - { regex = "0x[0-9a-fA-f]+"..isuf, type = "number" }, - { regex = "0()[0-7]+"..isuf, type = { "keyword", "number" } }, - { pattern = "%d+%.%d*[Ee]%d+"..fsuf, type = "number" }, - { pattern = "%d+[Ee]%d+"..fsuf, type = "number" }, - { pattern = "%d+%.%d*"..fsuf, type = "number" }, - { pattern = "%.%d+"..fsuf, type = "number" }, - { regex = "\\d+"..isuf, type = "number" }, - { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, - { pattern = "##", type = "operator" }, - { pattern = "struct%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, - { pattern = "union%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, + { pattern = "//.*", type = "comment" }, + { pattern = { "/%*", "%*/" }, type = "comment" }, + { pattern = { '"', '"', '\\' }, type = "string" }, + { pattern = { "'", "'", '\\' }, type = "string" }, + { regex = "0x[0-9a-fA-F][0-9a-fA-F']*"..isuf, type = "number" }, + { regex = "0()[0-7][0-7']*"..isuf, type = { "keyword", "number" } }, + { regex = digitsep.."\\.?"..digitsep.."?(?:[Ee][-+]?"..digitsep..")?"..fsuf, type = "number" }, + { regex = "\\."..digitsep.."(?:[Ee][-+]?"..digitsep..")?"..fsuf, type = "number" }, + { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, + { pattern = "##", type = "operator" }, + { pattern = "struct%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, + { pattern = "union%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, -- static declarations { pattern = "static()%s+()inline", type = { "keyword", "normal", "keyword" } diff --git a/data/plugins/language_cpp.lua b/data/plugins/language_cpp.lua index 2bbc688..7e60457 100644 --- a/data/plugins/language_cpp.lua +++ b/data/plugins/language_cpp.lua @@ -5,6 +5,8 @@ local syntax = require "core.syntax" local isuf = [[(?:[lL][uU]|ll[uU]|LL[uU]|[uU][lL]\b|[uU]ll|[uU]LL|[uU]|[lL]\b|ll|LL)?]] -- float suffix combinations as a Lua pattern / regex local fsuf = "[fFlL]?" +-- number with digit separator as a regex non-capturing group +local digitsep = [[(?:\d[\d']*)]] syntax.add { name = "C++", @@ -16,24 +18,21 @@ syntax.add { comment = "//", block_comment = { "/*", "*/" }, patterns = { - { pattern = "//.*", type = "comment" }, - { pattern = { "/%*", "%*/" }, type = "comment" }, - { pattern = { '"', '"', '\\' }, type = "string" }, - { pattern = { "'", "'", '\\' }, type = "string" }, - { regex = "0x[0-9a-fA-f]+"..isuf, type = "number" }, - { regex = "0b[01]+"..isuf, type = "number" }, - { regex = "0()[0-7]+"..isuf, type = { "keyword", "number" } }, - { pattern = "%d+%.%d*[Ee]%d+"..fsuf, type = "number" }, - { pattern = "%d+[Ee]%d+"..fsuf, type = "number" }, - { pattern = "%d+%.%d*"..fsuf, type = "number" }, - { pattern = "%.%d+"..fsuf, type = "number" }, - { regex = "\\d+"..isuf, type = "number" }, - { pattern = "[%+%-=/%*%^%%<>!~|:&]", type = "operator" }, - { pattern = "##", type = "operator" }, - { pattern = "struct%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, - { pattern = "class%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, - { pattern = "union%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, - { pattern = "namespace%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, + { pattern = "//.*", type = "comment" }, + { pattern = { "/%*", "%*/" }, type = "comment" }, + { pattern = { '"', '"', '\\' }, type = "string" }, + { pattern = { "'", "'", '\\' }, type = "string" }, + { regex = "0x[0-9a-fA-F][0-9a-fA-F']*"..isuf, type = "number" }, + { regex = "0b[01][01']*"..isuf, type = "number" }, + { regex = "0()[0-7][0-7']*"..isuf, type = { "keyword", "number" } }, + { regex = digitsep.."\\.?"..digitsep.."?(?:[Ee][-+]?"..digitsep..")?"..fsuf, type = "number" }, + { regex = "\\."..digitsep.."(?:[Ee][-+]?"..digitsep..")?"..fsuf, type = "number" }, + { pattern = "[%+%-=/%*%^%%<>!~|:&]", type = "operator" }, + { pattern = "##", type = "operator" }, + { pattern = "struct%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, + { pattern = "class%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, + { pattern = "union%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, + { pattern = "namespace%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, -- static declarations { pattern = "static()%s+()inline", type = { "keyword", "normal", "keyword" }