-- lx format
local format = require("core.format")
local common = require("format.asm.common")
local vocabulary = require("format.asm.vocabulary_gnu_aarch64")

format.register({
	name = "Assembly Source (GNU AArch64)",
	shortname = "ASM GNU AArch64",
	author = "liqube",
	internal = true,
	comment = "//",

	patterns = {
		-- Preprocessor directives before hash comments
		common.preprocessor_patterns,
		common.arm_immediate_patterns,

		-- AArch64 source accepts hash, double-slash, C block comments
		{ pattern = "#.-\n", type = "comment" },
		common.c_comment_patterns,

		-- Shared GNU labels, strings, and numbers
		common.structure_patterns,

		-- AArch64 scalar, SIMD, SVE, and SME register ranges include element suffixes
		{ pattern = "%f[%w][xw][0-9]%f[^%w]", type = "variable" },
		{ pattern = "%f[%w][xw][12][0-9]%f[^%w]", type = "variable" },
		{ pattern = "%f[%w][xw]30%f[^%w]", type = "variable" },
		{ pattern = "%f[%w][xw]zr%f[^%w]", type = "variable" },
		{ pattern = "%f[%w](wsp)%f[^%w]", type = { "variable" } },
		{ pattern = "%f[%w](sp)%f[^%w]", type = { "variable" } },
		{ pattern = "%f[%w][zvqbdsh][0-9][%.%w]*%f[^%w]", type = "variable" },
		{ pattern = "%f[%w][zvqbdsh][12][0-9][%.%w]*%f[^%w]", type = "variable" },
		{ pattern = "%f[%w][zvqbdsh]3[01][%.%w]*%f[^%w]", type = "variable" },
		{ pattern = "%f[%w]p[n]?[0-9][%.%w/]*%f[^%w]", type = "variable" },
		{ pattern = "%f[%w]p[n]?1[0-5][%.%w/]*%f[^%w]", type = "variable" },
		{ pattern = "%f[%w]za%d*[hv]?[%.%w]*%f[^%w]", type = "variable" },
		{ pattern = "%f[%w](zt0)%f[^%w]", type = { "variable" } },
		common.instruction_patterns,
		common.symbol_patterns,

		-- AArch64 operand punctuation and relocation expressions
		{ pattern = "[%+%-=/%*%^%%<>!~|&@%?:,%[%]%(%){}]", type = "operator" },
	},

	block_comment = common.block_comment,
	outline_patterns = common.outline_patterns,
	symbols = common.with_gnu_symbols(vocabulary),
})
