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

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

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

		-- ARM source uses hash, '@', double-slash, C block comment forms
		{ pattern = "#.-\n", type = "comment" },
		common.arm_comment_patterns,
		common.c_comment_patterns,

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

		-- ARM core and SIMD register ranges
		{ pattern = "%f[%w]r[0-9]%f[^%w]", type = "variable" },
		{ pattern = "%f[%w]r1[0-5]%f[^%w]", type = "variable" },
		{ pattern = "%f[%w][sd][0-9]%f[^%w]", type = "variable" },
		{ pattern = "%f[%w][sd][12][0-9]%f[^%w]", type = "variable" },
		{ pattern = "%f[%w][sd]3[01]%f[^%w]", type = "variable" },
		{ pattern = "%f[%w]q[0-9]%f[^%w]", type = "variable" },
		{ pattern = "%f[%w]q1[0-5]%f[^%w]", type = "variable" },
		{ pattern = "%f[%w](sp)%f[^%w]", type = { "variable" } },
		{ pattern = "%f[%w](lr)%f[^%w]", type = { "variable" } },
		{ pattern = "%f[%w](pc)%f[^%w]", type = { "variable" } },

		-- Match vocabulary base before optional Neon and MVE type suffixes
		{ pattern = "[%a_][%w_]*", type = "symbol" },
		common.instruction_patterns,
		common.symbol_patterns,

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

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