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

format.register({
	name = "AngelScript Source",
	shortname = "AngelScript",
	author = "liqube",
	extensions = "as",
	comment = "//",

	patterns = {
		-- Comments before slash operators
		{ pattern = "//.-\n", type = "comment" },
		{ pattern = { "/%*", "%*/" }, type = "comment" },

		-- Strings use C-style backslash escapes
		{ pattern = { '"', '"', "\\" }, type = "string" },
		{ pattern = { "'", "'", "\\" }, type = "string" },

		-- Int and float literals
		{ pattern = "0[xX][%da-fA-F]+", type = "number" },
		{ pattern = "0[bB][01]+", type = "number" },
		{ pattern = "%d+%.?%d*[eE][%+%-]?%d+[fF]?", type = "number" },
		{ pattern = "%d+%.%d*[fF]?", type = "number" },
		{ pattern = "%d+", type = "number" },

		-- Calls, handles, scopes, ordinary punctuation
		{ pattern = "[%a_][%w_]*%f[(]", type = "function" },
		{ pattern = "[%+%-=/%*%^%%<>!~|&@%?%:%.,;%(%)%[%]{}]", type = "operator" },
		{ pattern = "[%a_][%w_]*", type = "symbol" },
	},

	-- AngelScript uses C-style block comment shape
	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,
	},

	symbols = {
		-- Control flow
		["break"] = "control",
		["case"] = "keyword",
		["catch"] = "keyword",
		["continue"] = "control",
		["default"] = "keyword",
		["do"] = "keyword",
		["else"] = "keyword",
		["for"] = "keyword",
		["if"] = "keyword",
		["return"] = "control",
		["switch"] = "keyword",
		["try"] = "keyword",
		["while"] = "keyword",

		-- Declarations and qualifiers
		["abstract"] = "keyword",
		["auto"] = "keyword",
		["class"] = "keyword",
		["const"] = "keyword",
		["enum"] = "keyword",
		["external"] = "keyword",
		["final"] = "keyword",
		["from"] = "keyword",
		["funcdef"] = "keyword",
		["import"] = "keyword",
		["in"] = "keyword",
		["inout"] = "keyword",
		["interface"] = "keyword",
		["mixin"] = "keyword",
		["namespace"] = "keyword",
		["out"] = "keyword",
		["override"] = "keyword",
		["private"] = "keyword",
		["protected"] = "keyword",
		["shared"] = "keyword",
		["typedef"] = "keyword",

		-- Object and operator words
		["cast"] = "keyword",
		["is"] = "keyword",
		["not"] = "keyword",
		["and"] = "keyword",
		["or"] = "keyword",
		["xor"] = "keyword",
		["super"] = "keyword2",
		["this"] = "keyword2",

		-- Primitive types
		["bool"] = "keyword2",
		["double"] = "keyword2",
		["float"] = "keyword2",
		["int"] = "keyword2",
		["int8"] = "keyword2",
		["int16"] = "keyword2",
		["int32"] = "keyword2",
		["int64"] = "keyword2",
		["uint"] = "keyword2",
		["uint8"] = "keyword2",
		["uint16"] = "keyword2",
		["uint32"] = "keyword2",
		["uint64"] = "keyword2",
		["void"] = "keyword2",

		-- Literals
		["false"] = "literal",
		["null"] = "literal",
		["true"] = "literal",
	},
})
