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)
This commit is contained in:
@@ -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,13 +18,10 @@ syntax.add {
|
||||
{ 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" },
|
||||
{ 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"} },
|
||||
|
||||
@@ -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++",
|
||||
@@ -20,14 +22,11 @@ syntax.add {
|
||||
{ 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" },
|
||||
{ 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"} },
|
||||
|
||||
Reference in New Issue
Block a user