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

format.register({
	name = "Delphi Form",
	shortname = "DFM",
	author = "liqube",
	extensions = "dfm",
	headers = "^object .-: ",

	patterns = {
		-- lua doesn't support limiting quantifiers %x{64}
		{
			pattern = "%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x",
			type = "operator",
		},
		-- dim data
		{ pattern = "%s+%x+}", type = "operator" }, -- end of dim data
		{ pattern = "#?-?%.?%d+f?", type = "number" }, -- numbers, entities in strings
		{ pattern = "[%a_][%w_]*", type = "function", line_prefix = "%s*On%u[%w_]*%s*=%s*" },
		{ pattern = "[%[%]%=<>:,(){}%.+]", type = "operator" }, -- operators
		{ pattern = { "'", "'" }, type = "string" }, -- strings
		{ pattern = "[%a_][%w_]*%f[:]", type = "function" }, -- object/control name before ':'
		{ pattern = "[%a_][%w_]*", type = "normal" },
	},

	outline_patterns = {
		{ pattern = "%s*object%s+[%a_][%w_]*%s*:%s*", line_start = true },
	},

	symbols = {
		["object"] = "keyword",
		["item"] = "keyword",
		["end"] = "keyword",
		["True"] = "literal",
		["False"] = "literal",
		["Nil"] = "literal",
	},
})
