-- lx format
local format = require("core.format")
local patterns = require("core.format.patterns")

local symbols = {
	_expansion_flags = "rl",
	["ADD"] = "keyword",
	["ALL"] = "keyword",
	["ALTER"] = "keyword",
	["ANALYZE"] = "keyword",
	["AND"] = "keyword",
	["AS"] = "keyword",
	["ASC"] = "keyword",
	["BEFORE"] = "keyword",
	["BETWEEN"] = "keyword",
	["BOTH"] = "keyword",
	["BY"] = "keyword",
	["CALL"] = "keyword",
	["CASCADE"] = "keyword",
	["CASE"] = "keyword",
	["CHANGE"] = "keyword",
	["CHECK"] = "keyword",
	["COLUMN"] = "keyword",
	["CONDITION"] = "keyword",
	["CONSTRAINT"] = "keyword",
	["CONTINUE"] = "keyword",
	["CONVERT"] = "keyword",
	["CREATE"] = "keyword",
	["CROSS"] = "keyword",
	["CURRENT_DATE"] = "keyword",
	["CURRENT_TIME"] = "keyword",
	["CURRENT_TIMESTAMP"] = "keyword",
	["DATABASE"] = "keyword",
	["DATABASES"] = "keyword",
	["DECLARE"] = "keyword",
	["DEFAULT"] = "keyword",
	["DELETE"] = "keyword",
	["DESC"] = "keyword",
	["DESCRIBE"] = "keyword",
	["DISTINCT"] = "keyword",
	["DROP"] = "keyword",
	["DUAL"] = "keyword",
	["EACH"] = "keyword",
	["ELSE"] = "keyword",
	["ELSEIF"] = "keyword",
	["END"] = "keyword",
	["ESCAPE"] = "keyword",
	["EXCEPT"] = "keyword",
	["EXISTS"] = "keyword",
	["EXPLAIN"] = "keyword",
	["FETCH"] = "keyword",
	["FOR"] = "keyword",
	["FORCE"] = "keyword",
	["FOREIGN"] = "keyword",
	["FROM"] = "keyword",
	["FULLTEXT"] = "keyword",
	["GENERATED"] = "keyword",
	["GRANT"] = "keyword",
	["GROUP"] = "keyword",
	["HAVING"] = "keyword",
	["IF"] = "keyword",
	["IGNORE"] = "keyword",
	["IN"] = "keyword",
	["INDEX"] = "keyword",
	["INNER"] = "keyword",
	["INOUT"] = "keyword",
	["INSERT"] = "keyword",
	["INTERSECT"] = "keyword",
	["INTO"] = "keyword",
	["IS"] = "keyword",
	["ITERATE"] = "keyword",
	["JOIN"] = "keyword",
	["KEY"] = "keyword",
	["KEYS"] = "keyword",
	["LEADING"] = "keyword",
	["LEAVE"] = "keyword",
	["LEFT"] = "keyword",
	["LIKE"] = "keyword",
	["LIMIT"] = "keyword",
	["LOCK"] = "keyword",
	["LOOP"] = "keyword",
	["MATCH"] = "keyword",
	["NATURAL"] = "keyword",
	["NOT"] = "keyword",
	["ON"] = "keyword",
	["OPTIMIZE"] = "keyword",
	["OPTION"] = "keyword",
	["OR"] = "keyword",
	["ORDER"] = "keyword",
	["OUT"] = "keyword",
	["OUTER"] = "keyword",
	["PRIMARY"] = "keyword",
	["PROCEDURE"] = "keyword",
	["RANGE"] = "keyword",
	["READ"] = "keyword",
	["REFERENCES"] = "keyword",
	["REGEXP"] = "keyword",
	["RENAME"] = "keyword",
	["REPEAT"] = "keyword",
	["REPLACE"] = "keyword",
	["RETURN"] = "keyword",
	["REVOKE"] = "keyword",
	["RIGHT"] = "keyword",
	["ROLLBACK"] = "keyword",
	["ROW"] = "keyword",
	["SCHEMA"] = "keyword",
	["SCHEMAS"] = "keyword",
	["SELECT"] = "keyword",
	["SET"] = "keyword",
	["SHOW"] = "keyword",
	["SIGNAL"] = "keyword",
	["SPATIAL"] = "keyword",
	["SQL"] = "keyword",
	["TABLE"] = "keyword",
	["THEN"] = "keyword",
	["TO"] = "keyword",
	["TRAILING"] = "keyword",
	["TRANSACTION"] = "keyword",
	["TRIGGER"] = "keyword",
	["UNION"] = "keyword",
	["UNIQUE"] = "keyword",
	["UPDATE"] = "keyword",
	["USE"] = "keyword",
	["USING"] = "keyword",
	["VALUES"] = "keyword",
	["VIEW"] = "keyword",
	["WHEN"] = "keyword",
	["WHERE"] = "keyword",
	["WHILE"] = "keyword",
	["WITH"] = "keyword",
	["BIGINT"] = "keyword2",
	["BINARY"] = "keyword2",
	["BIT"] = "keyword2",
	["BLOB"] = "keyword2",
	["BOOL"] = "keyword2",
	["BOOLEAN"] = "keyword2",
	["CHAR"] = "keyword2",
	["DATE"] = "keyword2",
	["DATETIME"] = "keyword2",
	["DECIMAL"] = "keyword2",
	["DOUBLE"] = "keyword2",
	["ENUM"] = "keyword2",
	["FLOAT"] = "keyword2",
	["INT"] = "keyword2",
	["INTEGER"] = "keyword2",
	["JSON"] = "keyword2",
	["LONGTEXT"] = "keyword2",
	["LONGBLOB"] = "keyword2",
	["MEDIUMINT"] = "keyword2",
	["MEDIUMTEXT"] = "keyword2",
	["NUMERIC"] = "keyword2",
	["REAL"] = "keyword2",
	["SMALLINT"] = "keyword2",
	["TEXT"] = "keyword2",
	["TIME"] = "keyword2",
	["TIMESTAMP"] = "keyword2",
	["TINYINT"] = "keyword2",
	["TINYTEXT"] = "keyword2",
	["UUID"] = "keyword2",
	["VARBINARY"] = "keyword2",
	["VARCHAR"] = "keyword2",
	["YEAR"] = "keyword2",

	["NULL"] = "literal",
	["TRUE"] = "literal",
	["FALSE"] = "literal",
}

format.register({
	name = "MySQL Script",
	shortname = "MySQL",
	author = "liqube",
	extensions = "mysql.sql",
	comment = "--",

	patterns = {
		{ pattern = "%-%-.-\n", type = "comment" },
		{ pattern = { "/%*", "%*/" }, type = "comment" },
		{ pattern = { "'", "'", "\\" }, type = "string" },
		patterns.hex_token({ caseless = true }),
		patterns.number_token(),
		patterns.float_token(),
		{ pattern = "[%+%-=/%*%%<>!~|&@%?$#]", type = "operator" },
		{ pattern = "[%a_][%w_]*%f[(]", type = "function" },
		{ pattern = "[%a_][%w_]*", type = "symbol" },
	},
	symbols = symbols,
})
