improve number highlighting for c (#1752)

* improve number highlighting for c

* add unsigned suffix

* add long suffixes

* reorder octal literals and add suffix for hex numbers

* fix integer and float suffixes
too many characters, send help
This commit is contained in:
ThaCuber 2024-06-19 22:02:12 -04:00 committed by GitHub
parent 062f8dd1ff
commit 4df2871a46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 3 deletions

View File

@ -1,6 +1,11 @@
-- mod-version:3 -- mod-version:3
local syntax = require "core.syntax" 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 { syntax.add {
name = "C", name = "C",
files = { "%.c$" }, files = { "%.c$" },
@ -11,9 +16,13 @@ syntax.add {
{ pattern = { "/%*", "%*/" }, type = "comment" }, { pattern = { "/%*", "%*/" }, type = "comment" },
{ pattern = { '"', '"', '\\' }, type = "string" }, { pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "'", "'", '\\' }, type = "string" }, { pattern = { "'", "'", '\\' }, type = "string" },
{ pattern = "0x%x+", type = "number" }, { regex = "0x[0-9a-fA-f]+"..isuf, type = "number" },
{ pattern = "%d+[%d%.eE]*f?", type = "number" }, { regex = "0()[0-7]+"..isuf, type = { "keyword", "number" } },
{ pattern = "%.?%d+f?", type = "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 = "##", type = "operator" }, { pattern = "##", type = "operator" },
{ pattern = "struct%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, { pattern = "struct%s()[%a_][%w_]*", type = {"keyword", "keyword2"} },