-- lx format
local format = require("core.format")
local go_references = require("format.go.references")

format.register({
	name = "Go Source",
	shortname = "Go",
	extensions = "go",
	comment = "//",
	file_references = go_references.new(),

	patterns = {
		{ pattern = "//.-\n", type = "comment" },
		{ pattern = { "/%*", "%*/" }, type = "comment" },
		{ pattern = { '"', '"', "\\" }, type = "string" },
		{ pattern = { "`", "`", "\\" }, type = "string" },
		{ pattern = "0[oO_][0-7]+", type = "number" },
		{ pattern = "-?0x[%x_]+", type = "number" },
		{ pattern = "-?%d+_%d", type = "number" },
		{ pattern = "-?%d+[%d%.eE]*f?", type = "number" },
		{ pattern = "-?%.?%d+f?", type = "number" },
		{ pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" },
		{ pattern = ":=", type = "operator" },
		{ pattern = "[%a_][%w_]*%f[(]", type = "function" },
		{ pattern = "[%a_][%w_]*", type = "symbol" },
	},

	block_comment = {
		block_open = "/*",
		block_close = "*/",
		block_line_prefix = " * ",
		close_line_prefix = " ",
		open_on_own_line = false,
		close_on_own_line = true,
		strip_line_prefix = "^%s*%*%s?",
		allow_nested = false,
	},

	guard_comment = {
		guard_open = "if false {",
		guard_close = "}",
		guard_body_prefix = "auto",
		guard_align_to_indent = true,
		allow_nested = true,
	},

	symbols = {
		["break"] = "keyword",
		["case"] = "keyword",
		["chan"] = "keyword",
		["const"] = "keyword",
		["continue"] = "keyword",
		["default"] = "keyword",
		["defer"] = "keyword",
		["else"] = "keyword",
		["fallthrough"] = "keyword",
		["for"] = "keyword",
		["func"] = "keyword",
		["go"] = "keyword",
		["goto"] = "keyword",
		["if"] = "keyword",
		["import"] = "keyword",
		["interface"] = "keyword",
		["package"] = "keyword",
		["range"] = "keyword",
		["return"] = "keyword",
		["select"] = "keyword",
		["struct"] = "keyword",
		["switch"] = "keyword",
		["type"] = "keyword",
		["var"] = "keyword",

		["any"] = "keyword2",
		["bool"] = "keyword2",
		["byte"] = "keyword2",
		["comparable"] = "keyword2",
		["complex64"] = "keyword2",
		["complex128"] = "keyword2",
		["error"] = "keyword2",
		["float32"] = "keyword2",
		["float64"] = "keyword2",
		["int"] = "keyword2",
		["int8"] = "keyword2",
		["int16"] = "keyword2",
		["int32"] = "keyword2",
		["int64"] = "keyword2",
		["map"] = "keyword2",
		["rune"] = "keyword2",
		["string"] = "keyword2",
		["uint"] = "keyword2",
		["uint8"] = "keyword2",
		["uint16"] = "keyword2",
		["uint32"] = "keyword2",
		["uint64"] = "keyword2",
		["uintptr"] = "keyword2",

		["false"] = "literal",
		["iota"] = "literal",
		["nil"] = "literal",
		["true"] = "literal",
	},
})
