From 0fc179a4b517ee1cc0895806168fdd10ce5b2677 Mon Sep 17 00:00:00 2001 From: Takase <20792268+takase1121@users.noreply.github.com> Date: Thu, 20 Jun 2024 10:16:39 +0800 Subject: [PATCH] language_cpp: backport number highlighting from c (#1818) --- data/plugins/language_cpp.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/data/plugins/language_cpp.lua b/data/plugins/language_cpp.lua index 4efd50ed..d2486736 100644 --- a/data/plugins/language_cpp.lua +++ b/data/plugins/language_cpp.lua @@ -1,6 +1,11 @@ -- mod-version:3 local syntax = require "core.syntax" +-- integer suffix combinations as a regex +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]?" + syntax.add { name = "C++", files = { @@ -15,9 +20,13 @@ syntax.add { { pattern = { "/%*", "%*/" }, type = "comment" }, { pattern = { '"', '"', '\\' }, type = "string" }, { pattern = { "'", "'", '\\' }, type = "string" }, - { pattern = "0x%x+[%x']*", type = "number" }, - { pattern = "%d+[%d%.'eE]*f?", type = "number" }, - { pattern = "%.?%d+[%d']*f?", type = "number" }, + { 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"} },