{
	"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
	"name": "Moxie",
	"scopeName": "source.moxie",
	"fileTypes": ["mx"],
	"patterns": [
		{ "include": "#pragmas" },
		{ "include": "#comments" },
		{ "include": "#raw-strings" },
		{ "include": "#strings" },
		{ "include": "#rune-literals" },
		{ "include": "#numbers" },
		{ "include": "#func-declaration" },
		{ "include": "#type-declaration" },
		{ "include": "#keywords" },
		{ "include": "#builtin-types" },
		{ "include": "#builtin-functions" },
		{ "include": "#removed-names" },
		{ "include": "#constants" },
		{ "include": "#operators" },
		{ "include": "#identifiers" }
	],
	"repository": {
		"pragmas": {
			"patterns": [
				{
					"name": "meta.pragma.moxie",
					"match": "^\\s*(//:build|//:generate|//:linkname|//:extern|//:inline|//:noinline|//:wasmexport|//:section|//:align|//export)\\b.*$"
				},
				{
					"name": "meta.pragma.moxie",
					"match": "^\\s*(//go:[a-z]+)\\b.*$"
				}
			]
		},
		"comments": {
			"patterns": [
				{
					"name": "comment.line.double-slash.moxie",
					"match": "//.*$"
				},
				{
					"name": "comment.block.moxie",
					"begin": "/\\*",
					"end": "\\*/"
				}
			]
		},
		"raw-strings": {
			"name": "string.quoted.backtick.moxie",
			"begin": "`",
			"end": "`"
		},
		"strings": {
			"name": "string.quoted.double.moxie",
			"begin": "\"",
			"end": "\"",
			"patterns": [
				{
					"name": "constant.character.escape.moxie",
					"match": "\\\\[abfnrtv\\\\'\"0-7xuU]"
				}
			]
		},
		"rune-literals": {
			"name": "string.quoted.single.moxie",
			"begin": "'",
			"end": "'",
			"patterns": [
				{
					"name": "constant.character.escape.moxie",
					"match": "\\\\."
				}
			]
		},
		"numbers": {
			"patterns": [
				{
					"name": "constant.numeric.imaginary.moxie",
					"match": "\\b[0-9][0-9_]*(\\.[0-9_]*)?([eE][+-]?[0-9_]+)?i\\b"
				},
				{
					"name": "constant.numeric.hex.moxie",
					"match": "\\b0[xX][0-9a-fA-F_]+(\\.[0-9a-fA-F_]*)?([pP][+-]?[0-9_]+)?\\b"
				},
				{
					"name": "constant.numeric.binary.moxie",
					"match": "\\b0[bB][01_]+\\b"
				},
				{
					"name": "constant.numeric.octal.moxie",
					"match": "\\b0[oO][0-7_]+\\b"
				},
				{
					"name": "constant.numeric.float.moxie",
					"match": "\\b[0-9][0-9_]*\\.[0-9_]*([eE][+-]?[0-9_]+)?\\b"
				},
				{
					"name": "constant.numeric.float.moxie",
					"match": "\\b[0-9][0-9_]*[eE][+-]?[0-9_]+\\b"
				},
				{
					"name": "constant.numeric.integer.moxie",
					"match": "\\b[0-9][0-9_]*\\b"
				}
			]
		},
		"func-declaration": {
			"patterns": [
				{
					"name": "meta.function.moxie",
					"begin": "\\b(func)\\s+(\\([^)]*\\)\\s+)?([A-Za-z_][A-Za-z0-9_]*)",
					"beginCaptures": {
						"1": { "name": "storage.type.func.moxie" },
						"2": { "name": "meta.receiver.moxie" },
						"3": { "name": "entity.name.function.moxie" }
					},
					"end": "(?<=\\{)|$",
					"patterns": [
						{ "include": "#parameters" },
						{ "include": "#builtin-types" },
						{ "include": "#identifiers" }
					]
				}
			]
		},
		"parameters": {
			"patterns": [
				{
					"name": "variable.parameter.moxie",
					"match": "\\b[A-Za-z_][A-Za-z0-9_]*(?=\\s+[\\[\\*\\.A-Za-z_])"
				},
				{
					"name": "punctuation.separator.moxie",
					"match": "[,\\(\\)\\*\\[\\]]"
				}
			]
		},
		"type-declaration": {
			"patterns": [
				{
					"name": "meta.type.moxie",
					"match": "\\b(type)\\s+([A-Za-z_][A-Za-z0-9_]*)",
					"captures": {
						"1": { "name": "storage.type.type.moxie" },
						"2": { "name": "entity.name.type.moxie" }
					}
				}
			]
		},
		"keywords": {
			"patterns": [
				{
					"name": "keyword.control.moxie",
					"match": "\\b(break|case|continue|default|defer|else|for|goto|if|range|return|select|switch)\\b"
				},
				{
					"name": "keyword.other.moxie",
					"match": "\\b(chan|const|func|import|interface|map|package|struct|var)\\b"
				},
				{
					"name": "constant.language.moxie",
					"match": "\\b(true|false|nil|iota)\\b"
				}
			]
		},
		"builtin-types": {
			"patterns": [
				{
					"name": "support.type.moxie",
					"match": "\\b(bool|byte|rune|string|error|uintptr|comparable|any|int8|int16|int32|int64|uint8|uint16|uint32|uint64|float32|float64)\\b"
				},
				{
					"name": "support.type.unsafe.moxie",
					"match": "\\bunsafe\\.(Pointer|Sizeof|Offsetof|Alignof|Slice|SliceData|String|StringData|TypeOf)\\b"
				}
			]
		},
		"builtin-functions": {
			"patterns": [
				{
					"name": "support.function.moxie",
					"match": "\\b(push|pop|resize|len|cap|copy|delete|close|clear|min|max|panic|recover|print|println|spawn)\\b(?=\\s*\\()"
				}
			]
		},
		"removed-names": {
			"comment": "Names Go has and Moxie does not: not predeclared, they resolve as undefined (a user may declare their own).",
			"patterns": [
				{
					"name": "invalid.illegal.removed.moxie",
					"match": "\\b(int|uint|complex64|complex128)\\b(?=\\s*[;,)\\]\\}={]|\\s+[A-Za-z_(\\[\\*])"
				},
				{
					"name": "invalid.deprecated.removed.moxie",
					"match": "\\b(make|new|append|complex|real|imag|reflect)\\b(?=\\s*[\\(.;,)\\]])"
				}
			]
		},
		"constants": {
			"patterns": [
				{
					"name": "constant.other.placeholder.moxie",
					"match": "%[+#\\- 0]*[0-9]*(\\.[0-9]+)?[a-zA-Z%]"
				}
			]
		},
		"operators": {
			"patterns": [
				{
					"name": "keyword.operator.moxie",
					"match": "<-|\\.\\.\\.|&&|\\|\\||==|!=|<=|>=|<<|>>|&\\^|\\+=|-=|\\*=|/=|%=|&=|\\|=|\\^=|<<=|>>=|&\\^=|:=|\\+\\+|--"
				},
				{
					"name": "keyword.operator.moxie",
					"match": "[+\\-*/%&|^<>=!:~]"
				},
				{
					"name": "punctuation.moxie",
					"match": "[,;.()\\[\\]{}]"
				}
			]
		},
		"identifiers": {
			"patterns": [
				{
					"name": "entity.name.type.moxie",
					"match": "\\b[A-Z][A-Za-z0-9_]*\\b"
				}
			]
		}
	}
}
