From b880aa42f9c60d8d9d9adba9f4e28df5ab3ef3ca Mon Sep 17 00:00:00 2001 From: jgmdev Date: Fri, 11 Mar 2022 17:03:49 -0400 Subject: [PATCH] language_c: fixes and improvements * Do not compete with language_cpp.lua over the .h and .inl files, these files can contain both cpp and c so we choose the former which supports both syntaxes. * Added support for magic and uppercase constants. --- data/plugins/language_c.lua | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/data/plugins/language_c.lua b/data/plugins/language_c.lua index c4d3b07b..9ba639a0 100644 --- a/data/plugins/language_c.lua +++ b/data/plugins/language_c.lua @@ -3,7 +3,7 @@ local syntax = require "core.syntax" syntax.add { name = "C", - files = { "%.c$", "%.h$", "%.inl$" }, + files = { "%.c$" }, comment = "//", block_comment = { "/*", "*/" }, patterns = { @@ -17,10 +17,21 @@ syntax.add { { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, { pattern = "struct%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, { pattern = "union%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, + { + pattern = "^%s*#define%s+()[%a_][%a%d_]*", + type = { "keyword", "symbol" } + }, + -- Uppercase constants of at least 2 chars in len + { + pattern = "_?%u[%u_][%u%d_]*%f[%s%+%*%-%.%(%)%?%^%%=/<>~|&;:,!]", + type = "number" + }, + -- Magic constants + { pattern = "__[%u%l]+__", type = "number" }, { pattern = "[%a_][%w_]*%f[(]", type = "function" }, - { pattern = "[%a_][%w_]*", type = "symbol" }, { pattern = "#include%s()<.->", type = {"keyword", "string"} }, { pattern = "#[%a_][%w_]*", type = "keyword" }, + { pattern = "[%a_][%w_]*", type = "symbol" }, }, symbols = { ["if"] = "keyword", @@ -45,6 +56,8 @@ syntax.add { ["case"] = "keyword", ["default"] = "keyword", ["auto"] = "keyword", + ["struct"] = "keyword", + ["union"] = "keyword", ["void"] = "keyword2", ["int"] = "keyword2", ["short"] = "keyword2", @@ -61,6 +74,7 @@ syntax.add { ["#if"] = "keyword", ["#ifdef"] = "keyword", ["#ifndef"] = "keyword", + ["#elif"] = "keyword", ["#else"] = "keyword", ["#elseif"] = "keyword", ["#endif"] = "keyword",