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

format.register({
	name = "DxO Sidecar",
	shortname = "DOP",
	author = "liqube",

	extensions = "dop",
	headers = "^Sidecar = %{", -- '^' anchors the first byte and '%{' matches the literal opening brace
	require_header_match = true,
	require_file_match = true,

	patterns = {
		-- Dates and times
		patterns.rfc3339ish_date_time(nil, "%s*[%a_][%w_]*%s*=%s*", { quoted = true }),

		-- Quoted UUID values
		patterns.guid_value(nil, "%s*[%a_][%w_]*%s*=%s*", { quoted = true }),

		-- Keep quoted values together before checking their contents as other tokens
		-- Matching quote delimiters with backslash escapes between them
		{ pattern = { '"', '"', "\\" }, type = "string", delim_type = "operator" },

		-- Whole numeric values, negative values, and decimals
		patterns.number_token(),

		-- Mark field names only when they introduce a value
		-- An identifier followed by optional spacing and '='
		{ pattern = "[%a_][%w_]*", type = "symbol", followed_by = "%s*=" },

		-- Assignments, containers, and separators as the file structure
		-- One '=', brace, or comma character
		{ pattern = "[={},]", type = "operator" },
	},

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