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

syntax.add({
	name = "HG Ignore",
	shortname = "hgignore",
	author = "liqube",
	filenames = ".hgignore",
	comment = "#",

	patterns = {
		-- Mercurial syntax selector
		{ pattern = "%s*syntax%s*:%s*glob%f[%s#\n]", type = "meta", line_start = true, caseless = true },
		{ pattern = "%s*syntax%s*:%s*regexp%f[%s#\n]", type = "meta", line_start = true, caseless = true },

		-- Mercurial per-line pattern selectors
		{ pattern = "%s*glob%s*:%s*[^#\n]*", type = "keyword", line_start = true, caseless = true },
		{ pattern = "%s*re%s*:%s*[^#\n]*", type = "literal", line_start = true, caseless = true },
		{ pattern = "%s*path%s*:%s*[^#\n]*", type = "keyword2", line_start = true, caseless = true },
		{ pattern = "%s*relglob%s*:%s*[^#\n]*", type = "keyword2", line_start = true, caseless = true },

		-- Escaped leading marker tokens (\# and \!)
		{ pattern = "%s*\\[#!].-\n", type = "string", line_start = true },
		{ pattern = "%s*#.-\n", type = "comment", line_start = true },

		-- Negation pattern prefix
		{ pattern = "%s*!%f[%S]", type = "operator", line_start = true },

		-- Root-relative patterns
		{ pattern = "%s*/", type = "operator", line_start = true },

		-- Glob pieces
		{ pattern = "%*%*", type = "keyword2" },
		{ pattern = "%[[^%]\n]+%]", type = "keyword2" },
		{ pattern = "[%*%?]", type = "keyword2" },

		-- Path separators
		{ pattern = "\\", type = "operator" },
		{ pattern = ":", type = "operator" },
		{ pattern = "/", type = "operator" },
		{ pattern = "[^%s!#%*%?%[%]\\/\n]+", type = "symbol" },
	},

	outline_patterns = {
		{ pattern = "#", line_start = true, block_start_only = true },
	},
})
