local format = require("core.format")

format.register({
	name = "C Source",
	shortname = "C",
	extensions = {
		"c",
--		"h",
--		"inl",
--		"cpp",
--		"hpp",
	},
	comment = "//",

	patterns = {
		{ pattern = "//.-\n", type = "comment" },
		{ pattern = { "/%*", "%*/" }, type = "comment" },
		{ pattern = { "#", "[^\\]\n" }, type = "preprocessor" },
		{ 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" },
		{ pattern = "[%a_][%w_]*%f[(]", type = "function" },
		{ pattern = "[%a_][%w_]*", type = "symbol" },
	},

	block_comment = {
		block_open = "/*",
		block_close = "*/",
		block_line_prefix = " * ",
		close_line_prefix = " ",
		open_on_own_line = false,
		close_on_own_line = true,
		strip_line_prefix = "^%s*%*%s?",
		allow_nested = false,
	},

	guard_comment = {
		guard_open = { "#if 0", "#if false" },
		guard_close = "#endif",
		guard_align_to_indent = false,
		allow_nested = true,
	},

	symbols = {
		["auto"] = "keyword",
		["break"] = "control",
		["case"] = "keyword",
		["const"] = "keyword",
		["continue"] = "control",
		["default"] = "keyword",
		["do"] = "keyword",
		["else"] = "keyword",
		["enum"] = "keyword",
		["extern"] = "keyword",
		["for"] = "keyword",
		["goto"] = "control",
		["if"] = "keyword",
		["inline"] = "keyword",
		["register"] = "keyword",
		["restrict"] = "keyword",
		["return"] = "control",
		["sizeof"] = "keyword",
		["static"] = "keyword",
		["struct"] = "keyword",
		["switch"] = "keyword",
		["typedef"] = "keyword",
		["union"] = "keyword",
		["volatile"] = "keyword",
		["while"] = "keyword",
		["_Alignas"] = "keyword",
		["_Alignof"] = "keyword",
		["_Atomic"] = "keyword",
		["_Generic"] = "keyword",
		["_Noreturn"] = "keyword",
		["_Static_assert"] = "keyword",
		["_Thread_local"] = "keyword",

		["_Bool"] = "keyword2",
		["bool"] = "keyword2",
		["char"] = "keyword2",
		["double"] = "keyword2",
		["float"] = "keyword2",
		["int"] = "keyword2",
		["long"] = "keyword2",
		["ptrdiff_t"] = "keyword2",
		["short"] = "keyword2",
		["signed"] = "keyword2",
		["size_t"] = "keyword2",
		["unsigned"] = "keyword2",
		["void"] = "keyword2",

		["false"] = "literal",
		["true"] = "literal",
		["NULL"] = "literal",
	},
})
