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

syntax.add({
	name = "INI Config File",
	shortname = "INI",
	author = "liqube",

	extensions = {
		"ini",
		"cfg",
		"cnf",
		"conf",
		"inf",
		"url",
		"dsk",
		"xiph",
		"repo",
	},

	filenames = {
		".gitconfig",
		".hgrc",
		".pypirc",
		".editorconfig",
		".theme",
		".dockitem",
		".desktop",
		".npmrc",
	},
	headers = "^%[.-%]",

	line_patterns = {
		-- full-line comment
		{ pattern = "%s*[;#].*", type = "comment", consume_line = true },
		-- full-line [section] header
		{ pattern = "%s*%[[^%]]+%]%s*$", type = "function", consume_line = true },
	},

	patterns = {
		-- GUID/UUID hex value after '='
		patterns.guid_value(),
		-- hex number token
		patterns.hex_token(),
		-- integer/float/exponent token
		patterns.number_token(),
		-- fallback numeric token
		patterns.float_token(),
		-- double-quoted string
		patterns.double_quoted_string(),
		-- single-quoted string
		patterns.single_quoted_string(),
		-- key token before '='
		{ pattern = "[^%s=;\n%[%]#\"'][^=;\n%[%]#\"']*", type = "symbol", line_prefix = "%s*", followed_by = "%s*=" },
		{ pattern = "[=]", type = "operator" }, -- key/value delimiter
	},

	-- INI sections are outline jump points
	outline_patterns = {
		{ pattern = "%s*%[[^%]]+%]%s*", line_start = true },
	},

	symbols = {
		["true"] = "literal",
		["false"] = "literal",
	},
})
