-- lx syntax
local syntax = require("core.syntax")

syntax.add({
	name = "ColorToy Formats",
	shortname = "CTF",
	author = "liqube",

	filenames = { "ColorToy.formats" },

	line_patterns = {
		-- Format row
		{
			pattern = "%s*[^;%[].*",
			type = "string",
		},
	},

	patterns = {
		-- Comment line
		{ pattern = ";.-\n", type = "comment", line_start = true },
		{ pattern = ";.+", type = "comment", line_start = true },

		-- Section header
		{ pattern = "%[.-%]", type = "keyword", line_start = true },

		-- CSS RGB function
		{ pattern = "rgb%f[(]", type = "function" },

		-- CSS RGBA function
		{ pattern = "rgba%f[(]", type = "function" },

		-- CSS HSL function
		{ pattern = "hsl%f[(]", type = "function" },

		-- CSS HSLA function
		{ pattern = "hsla%f[(]", type = "function" },

		-- WINAPI RGB function
		{ pattern = "RGB%f[(]", type = "function" },

		-- Processing color function
		{ pattern = "color%f[(]", type = "function" },

		-- BCB TColor cast
		{ pattern = "TColor", type = "keyword2" },

		-- Optional space modifier
		{ pattern = "<>", type = "operator" },

		-- Space or comma modifier
		{ pattern = "<,>", type = "operator" },

		-- Space or semicolon modifier
		{ pattern = "<;>", type = "operator" },

		-- Space or slash modifier
		{ pattern = "</>", type = "operator" },

		-- Fixed alpha hex byte
		{ pattern = "<ff>", type = "hex", caseless = true },

		-- Red hex component
		{ pattern = "<r:x>", type = "hex" },

		-- Green hex component
		{ pattern = "<g:x>", type = "hex" },

		-- Blue hex component
		{ pattern = "<b:x>", type = "hex" },

		-- RGB float component
		{ pattern = "<[rgb]:f>", type = "literal" },

		-- RGB integer component
		{ pattern = "<[rgb]:i>", type = "literal" },

		-- RGB percentage component
		{ pattern = "<[rgb]:p>", type = "literal" },

		-- HSL float component
		{ pattern = "<[hsl]:f>", type = "literal" },

		-- HSL integer component
		{ pattern = "<[hsl]:i>", type = "literal" },

		-- HSL percentage component
		{ pattern = "<[hsl]:p>", type = "literal" },

		-- Packed RGB integer
		{ pattern = "<rgb:i>", type = "literal" },

		-- Packed ARGB integer
		{ pattern = "<argb:i>", type = "literal" },

		-- Packed BGR integer
		{ pattern = "<bgr:i>", type = "literal" },

		-- Packed ABGR integer
		{ pattern = "<abgr:i>", type = "literal" },

		-- Unknown macro fallback
		{ pattern = "<[^>\n]+>", type = "error" },
	},

	outline_patterns = {
		-- Section header
		{ pattern = "%s*%[.-%]", line_start = true },
	},
})
