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

local symbols = {
	_expansion_flags = "rl",
	["ABORT"] = "keyword",
	["ACTION"] = "keyword",
	["ADD"] = "keyword",
	["AFTER"] = "keyword",
	["ALL"] = "keyword",
	["ALTER"] = "keyword",
	["ANALYZE"] = "keyword",
	["AND"] = "keyword",
	["AS"] = "keyword",
	["ASC"] = "keyword",
	["ATTACH"] = "keyword",
	["AUTOINCREMENT"] = "keyword",
	["BEFORE"] = "keyword",
	["BEGIN"] = "keyword",
	["BETWEEN"] = "keyword",
	["BY"] = "keyword",
	["CASCADE"] = "keyword",
	["CASE"] = "keyword",
	["CAST"] = "keyword",
	["CHECK"] = "keyword",
	["COLLATE"] = "keyword",
	["COLUMN"] = "keyword",
	["COMMIT"] = "keyword",
	["CONFLICT"] = "keyword",
	["CONSTRAINT"] = "keyword",
	["CREATE"] = "keyword",
	["CROSS"] = "keyword",
	["CURRENT_DATE"] = "keyword",
	["CURRENT_TIME"] = "keyword",
	["CURRENT_TIMESTAMP"] = "keyword",
	["DATABASE"] = "keyword",
	["DEFAULT"] = "keyword",
	["DEFERRABLE"] = "keyword",
	["DEFERRED"] = "keyword",
	["DELETE"] = "keyword",
	["DESC"] = "keyword",
	["DETACH"] = "keyword",
	["DISTINCT"] = "keyword",
	["DROP"] = "keyword",
	["EACH"] = "keyword",
	["ELSE"] = "keyword",
	["END"] = "keyword",
	["ESCAPE"] = "keyword",
	["EXCEPT"] = "keyword",
	["EXCLUSIVE"] = "keyword",
	["EXISTS"] = "keyword",
	["EXPLAIN"] = "keyword",
	["FAIL"] = "keyword",
	["FOR"] = "keyword",
	["FOREIGN"] = "keyword",
	["FROM"] = "keyword",
	["FULL"] = "keyword",
	["GLOB"] = "keyword",
	["GROUP"] = "keyword",
	["HAVING"] = "keyword",
	["IF"] = "keyword",
	["IGNORE"] = "keyword",
	["IMMEDIATE"] = "keyword",
	["IN"] = "keyword",
	["INDEX"] = "keyword",
	["INDEXED"] = "keyword",
	["INITIALLY"] = "keyword",
	["INNER"] = "keyword",
	["INSERT"] = "keyword",
	["INSTEAD"] = "keyword",
	["INTERSECT"] = "keyword",
	["INTO"] = "keyword",
	["IS"] = "keyword",
	["ISNULL"] = "keyword",
	["JOIN"] = "keyword",
	["KEY"] = "keyword",
	["LEFT"] = "keyword",
	["LIKE"] = "keyword",
	["LIMIT"] = "keyword",
	["MATCH"] = "keyword",
	["NATURAL"] = "keyword",
	["NO"] = "keyword",
	["NOT"] = "keyword",
	["NOTNULL"] = "keyword",
	["OF"] = "keyword",
	["OFFSET"] = "keyword",
	["ON"] = "keyword",
	["OR"] = "keyword",
	["ORDER"] = "keyword",
	["OUTER"] = "keyword",
	["PLAN"] = "keyword",
	["PRAGMA"] = "keyword",
	["PRIMARY"] = "keyword",
	["QUERY"] = "keyword",
	["RAISE"] = "keyword",
	["RECURSIVE"] = "keyword",
	["REFERENCES"] = "keyword",
	["REGEXP"] = "keyword",
	["REINDEX"] = "keyword",
	["RELEASE"] = "keyword",
	["RENAME"] = "keyword",
	["REPLACE"] = "keyword",
	["RESTRICT"] = "keyword",
	["RIGHT"] = "keyword",
	["ROLLBACK"] = "keyword",
	["ROW"] = "keyword",
	["SAVEPOINT"] = "keyword",
	["SELECT"] = "keyword",
	["SET"] = "keyword",
	["TABLE"] = "keyword",
	["TEMP"] = "keyword",
	["TEMPORARY"] = "keyword",
	["THEN"] = "keyword",
	["TO"] = "keyword",
	["TRANSACTION"] = "keyword",
	["TRIGGER"] = "keyword",
	["UNION"] = "keyword",
	["UNIQUE"] = "keyword",
	["UPDATE"] = "keyword",
	["USING"] = "keyword",
	["VACUUM"] = "keyword",
	["VALUES"] = "keyword",
	["VIEW"] = "keyword",
	["VIRTUAL"] = "keyword",
	["WHEN"] = "keyword",
	["WHERE"] = "keyword",
	["WITH"] = "keyword",
	["WITHOUT"] = "keyword",

	["BLOB"] = "keyword2",
	["INTEGER"] = "keyword2",
	["INT"] = "keyword2",
	["REAL"] = "keyword2",
	["TEXT"] = "keyword2",
	["NUMERIC"] = "keyword2",

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

format.register({
	name = "SQLite Script",
	shortname = "SQLite",
	author = "liqube",
	extensions = "sqlite.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,
})
