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

format.register({
	name = "Git Attributes",
	shortname = "gitattr",
	author = "liqube",

	filenames = { ".gitattributes" },
	comment = "#",

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

		-- Quoted path pattern
		{ pattern = { '"', '"', "\\" }, type = "string" },

		-- Attribute macro definition such as [attr]binary
		{
			pattern = "(%[attr%])([^%s\r\n]+)",
			type = { "preprocessor", "variable" },
			line_start = true,
		},

		-- Unquoted path pattern at the beginning of an entry
		{
			pattern = "([^%s#][^%s\r\n]*)(%s+)",
			type = { "string", "normal" },
			line_start = true,
		},

		-- Attribute with an assigned value
		{
			pattern = "([%w_.][%w_.%-]*)(=)([^%s\r\n]+)",
			type = { "keyword", "operator", "string" },
		},

		-- Unset or unspecified attribute
		{
			pattern = "([!%-])([%w_.][%w_.%-]*)",
			type = { "operator", "keyword" },
		},

		-- Set attribute
		{ pattern = "[%w_.][%w_.%-]*", type = "keyword" },
	},

	defaults = {
		word_wrap = false,
	},
})
