2022-03-24 16:57:26 +01:00
|
|
|
-- mod-version:3 -- lite-xl 2.1
|
2020-03-07 16:53:54 +01:00
|
|
|
local syntax = require "core.syntax"
|
|
|
|
|
|
|
|
syntax.add {
|
2021-11-21 03:46:43 +01:00
|
|
|
name = "C",
|
2022-03-11 22:03:49 +01:00
|
|
|
files = { "%.c$" },
|
2020-03-07 16:53:54 +01:00
|
|
|
comment = "//",
|
2021-12-26 08:05:27 +01:00
|
|
|
block_comment = { "/*", "*/" },
|
2020-03-07 16:53:54 +01:00
|
|
|
patterns = {
|
2021-05-19 22:35:28 +02:00
|
|
|
{ pattern = "//.-\n", type = "comment" },
|
|
|
|
{ pattern = { "/%*", "%*/" }, type = "comment" },
|
|
|
|
{ pattern = { '"', '"', '\\' }, type = "string" },
|
|
|
|
{ pattern = { "'", "'", '\\' }, type = "string" },
|
|
|
|
{ pattern = "0x%x+", type = "number" },
|
|
|
|
{ pattern = "%d+[%d%.eE]*f?", type = "number" },
|
|
|
|
{ pattern = "%.?%d+f?", type = "number" },
|
|
|
|
{ pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" },
|
2022-03-24 05:20:14 +01:00
|
|
|
{ pattern = "##", type = "operator" },
|
2021-05-19 22:35:28 +02:00
|
|
|
{ pattern = "struct%s()[%a_][%w_]*", type = {"keyword", "keyword2"} },
|
|
|
|
{ pattern = "union%s()[%a_][%w_]*", type = {"keyword", "keyword2"} },
|
2022-03-24 05:20:14 +01:00
|
|
|
-- static declarations
|
|
|
|
{ pattern = "static()%s+()inline",
|
|
|
|
type = { "keyword", "normal", "keyword" }
|
|
|
|
},
|
|
|
|
{ pattern = "static()%s+()const",
|
|
|
|
type = { "keyword", "normal", "keyword" }
|
|
|
|
},
|
|
|
|
{ pattern = "static()%s+()[%a_][%w_]*",
|
|
|
|
type = { "keyword", "normal", "literal" }
|
|
|
|
},
|
|
|
|
-- match function type declarations
|
|
|
|
{ pattern = "[%a_][%w_]*()%*+()%s+()[%a_][%w_]*%f[%(]",
|
|
|
|
type = { "literal", "operator", "normal", "function" }
|
|
|
|
},
|
|
|
|
{ pattern = "[%a_][%w_]*()%s+()%*+()[%a_][%w_]*%f[%(]",
|
|
|
|
type = { "literal", "normal", "operator", "function" }
|
|
|
|
},
|
|
|
|
{ pattern = "[%a_][%w_]*()%s+()[%a_][%w_]*%f[%(]",
|
|
|
|
type = { "literal", "normal", "function" }
|
|
|
|
},
|
|
|
|
-- match variable type declarations
|
|
|
|
{ pattern = "[%a_][%w_]*()%*+()%s+()[%a_][%w_]*",
|
|
|
|
type = { "literal", "operator", "normal", "normal" }
|
|
|
|
},
|
|
|
|
{ pattern = "[%a_][%w_]*()%s+()%*+()[%a_][%w_]*",
|
|
|
|
type = { "literal", "normal", "operator", "normal" }
|
|
|
|
},
|
|
|
|
{ pattern = "[%a_][%w_]*()%s+()[%a_][%w_]*()%s*()[;,%[%)]",
|
|
|
|
type = { "literal", "normal", "normal", "normal", "normal" }
|
|
|
|
},
|
|
|
|
{ pattern = "[%a_][%w_]*()%s+()[%a_][%w_]*()%s*()=",
|
|
|
|
type = { "literal", "normal", "normal", "normal", "operator" }
|
|
|
|
},
|
|
|
|
{ pattern = "[%a_][%w_]*()&()%s+()[%a_][%w_]*",
|
|
|
|
type = { "literal", "operator", "normal", "normal" }
|
|
|
|
},
|
|
|
|
{ pattern = "[%a_][%w_]*()%s+()&()[%a_][%w_]*",
|
|
|
|
type = { "literal", "normal", "operator", "normal" }
|
2022-03-11 22:03:49 +01:00
|
|
|
},
|
|
|
|
-- Uppercase constants of at least 2 chars in len
|
2022-03-24 05:20:14 +01:00
|
|
|
{ pattern = "_?%u[%u_][%u%d_]*%f[%s%+%*%-%.%)%]}%?%^%%=/<>~|&;:,!]",
|
|
|
|
type = "number"
|
2022-03-11 22:03:49 +01:00
|
|
|
},
|
|
|
|
-- Magic constants
|
|
|
|
{ pattern = "__[%u%l]+__", type = "number" },
|
2022-03-24 05:20:14 +01:00
|
|
|
-- all other functions
|
2021-05-19 22:35:28 +02:00
|
|
|
{ pattern = "[%a_][%w_]*%f[(]", type = "function" },
|
2022-03-24 05:20:14 +01:00
|
|
|
-- Macros
|
|
|
|
{ pattern = "^%s*#%s*define%s+()[%a_][%a%d_]*",
|
|
|
|
type = { "keyword", "symbol" }
|
|
|
|
},
|
|
|
|
{ pattern = "#%s*include%s()<.->", type = {"keyword", "string"} },
|
|
|
|
{ pattern = "%f[#]#%s*[%a_][%w_]*", type = "keyword" },
|
|
|
|
-- Everything else to make the tokenizer work properly
|
2022-03-11 22:03:49 +01:00
|
|
|
{ pattern = "[%a_][%w_]*", type = "symbol" },
|
2020-03-07 16:53:54 +01:00
|
|
|
},
|
|
|
|
symbols = {
|
|
|
|
["if"] = "keyword",
|
|
|
|
["then"] = "keyword",
|
|
|
|
["else"] = "keyword",
|
|
|
|
["elseif"] = "keyword",
|
|
|
|
["do"] = "keyword",
|
|
|
|
["while"] = "keyword",
|
|
|
|
["for"] = "keyword",
|
|
|
|
["break"] = "keyword",
|
|
|
|
["continue"] = "keyword",
|
|
|
|
["return"] = "keyword",
|
|
|
|
["goto"] = "keyword",
|
|
|
|
["typedef"] = "keyword",
|
|
|
|
["enum"] = "keyword",
|
|
|
|
["extern"] = "keyword",
|
|
|
|
["static"] = "keyword",
|
|
|
|
["volatile"] = "keyword",
|
|
|
|
["const"] = "keyword",
|
|
|
|
["inline"] = "keyword",
|
|
|
|
["switch"] = "keyword",
|
|
|
|
["case"] = "keyword",
|
|
|
|
["default"] = "keyword",
|
|
|
|
["auto"] = "keyword",
|
2022-03-11 22:03:49 +01:00
|
|
|
["struct"] = "keyword",
|
|
|
|
["union"] = "keyword",
|
2021-12-15 18:20:17 +01:00
|
|
|
["void"] = "keyword2",
|
2020-03-07 16:53:54 +01:00
|
|
|
["int"] = "keyword2",
|
|
|
|
["short"] = "keyword2",
|
|
|
|
["long"] = "keyword2",
|
|
|
|
["float"] = "keyword2",
|
|
|
|
["double"] = "keyword2",
|
|
|
|
["char"] = "keyword2",
|
|
|
|
["unsigned"] = "keyword2",
|
|
|
|
["bool"] = "keyword2",
|
|
|
|
["true"] = "literal",
|
|
|
|
["false"] = "literal",
|
|
|
|
["NULL"] = "literal",
|
2021-07-20 20:39:50 +02:00
|
|
|
["#include"] = "keyword",
|
|
|
|
["#if"] = "keyword",
|
|
|
|
["#ifdef"] = "keyword",
|
|
|
|
["#ifndef"] = "keyword",
|
2022-03-11 22:03:49 +01:00
|
|
|
["#elif"] = "keyword",
|
2021-07-20 20:39:50 +02:00
|
|
|
["#else"] = "keyword",
|
|
|
|
["#elseif"] = "keyword",
|
|
|
|
["#endif"] = "keyword",
|
|
|
|
["#define"] = "keyword",
|
|
|
|
["#warning"] = "keyword",
|
|
|
|
["#error"] = "keyword",
|
|
|
|
["#pragma"] = "keyword",
|
2020-03-07 16:53:54 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|