From 659da4737794c1eb4d4bbd54d8f8f772a4f709ce Mon Sep 17 00:00:00 2001 From: JohnnyMorganz Date: Mon, 1 Apr 2024 13:56:59 +0000 Subject: [PATCH] Update grammar syntax Grammar was rewritten upstream --- editors/code/syntaxes/Luau.tmLanguage.json | 715 ++++++++++++--------- 1 file changed, 398 insertions(+), 317 deletions(-) diff --git a/editors/code/syntaxes/Luau.tmLanguage.json b/editors/code/syntaxes/Luau.tmLanguage.json index fb68679f..bbc9c3cf 100644 --- a/editors/code/syntaxes/Luau.tmLanguage.json +++ b/editors/code/syntaxes/Luau.tmLanguage.json @@ -7,15 +7,23 @@ "name": "Luau", "scopeName": "source.luau", "fileTypes": [ - "luau", - "lua" + "luau" ], "patterns": [ + { + "include": "#function-definition" + }, + { + "include": "#number" + }, + { + "include": "#string" + }, { "include": "#shebang" }, { - "include": "#function-declaration" + "include": "#comment" }, { "include": "#local-declaration" @@ -27,96 +35,111 @@ "include": "#type-alias-declaration" }, { - "include": "#expression" + "include": "#keyword" + }, + { + "include": "#language_constant" + }, + { + "include": "#standard_library" + }, + { + "include": "#identifier" + }, + { + "include": "#operator" }, { - "include": "#comments" + "include": "#parentheses" + }, + { + "include": "#table" + }, + { + "include": "#type_cast" + }, + { + "include": "#type_annotation" } ], "repository": { - "shebang": { - "name": "comment.line.shebang.luau", - "match": "\\A(#!).*(?=$)", - "captures": { - "1": { - "name": "punctuation.definition.comment.luau" - } - } - }, - "function-declaration": { - "name": "meta.function.luau", - "contentName": "meta.parameters.luau", - "begin": "\\b(?:(local)\\s*)?(function)\\s*([a-zA-Z_]\\w*(?:[.:]([a-zA-Z_]\\w*))*)?\\s*(\\<[\\w\\s\\,\\.]*\\>)?\\s*\\(", - "end": "\\)(?:\\s*(:)\\s*(.+?)(?=\\s*\\b(?:([^\\w.,<])|\\)>)\\s*\\w|\\s*)$)?", + "function-definition": { + "begin": "\\b(?:(local)\\s+)?(function)\\b(?![,:])", "beginCaptures": { "1": { "name": "storage.modifier.local.luau" }, "2": { "name": "keyword.control.luau" - }, - "3": { - "name": "entity.name.function.luau", - "patterns": [ - { - "name": "variable.language.metamethod.luau", - "match": "\\b(__add|__call|__concat|__div|__eq|__index|__le|__len|__lt|__metatable|__mod|__mode|__mul|__newindex|__pow|__sub|__tostring|__unm)\\b" - } - ] - }, - "5": { - "patterns": [ - { - "name": "entity.name.type.luau", - "match": "\\b([a-zA-Z]\\w*)\\b" - } - ] - } - }, - "endCaptures": { - "1": { - "name": "keyword.operator.type.luau" - }, - "2": { - "patterns": [ - { - "include": "#type_literal" - } - ] - }, - "3": { - "patterns": [ - { - "name": "keyword.operator.type.luau", - "match": ">" - } - ] } }, + "end": "(?<=[\\)\\-{}\\[\\]\"'])", + "name": "meta.function.luau", "patterns": [ { - "name": "keyword.operator.type.luau", - "match": ":" + "include": "#comment" }, { - "name": "variable.parameter.luau", - "match": "(?.]\\s*)\\b_\\b" + "include": "#generics-declaration" }, { - "name": "variable.other.constant.luau", - "match": "(?.]\\s*)\\b([A-Z_][A-Z0-9_]*)\\b" + "begin": "(\\()", + "beginCaptures": { + "1": { + "name": "punctuation.definition.parameters.begin.luau" + } + }, + "end": "(\\))", + "endCaptures": { + "1": { + "name": "punctuation.definition.parameters.end.luau" + } + }, + "name": "meta.parameter.luau", + "patterns": [ + { + "include": "#comment" + }, + { + "match": "\\.\\.\\.", + "name": "variable.parameter.function.varargs.luau" + }, + { + "match": "[a-zA-Z_][a-zA-Z0-9_]*", + "name": "variable.parameter.function.luau" + }, + { + "match": ",", + "name": "punctuation.separator.arguments.luau" + }, + { + "begin": ":", + "beginCaptures": { + "0": { + "name": "keyword.operator.type.luau" + } + }, + "end": "(?=[\\),])", + "patterns": [ + { + "include": "#type_literal" + } + ] + } + ] }, { - "name": "variable.parameter.luau", - "match": "(?.]\\s*)\\b([a-zA-Z_]\\w*)\\b" + "match": "\\b(__add|__call|__concat|__div|__eq|__index|__le|__len|__lt|__metatable|__mod|__mode|__mul|__newindex|__pow|__sub|__tostring|__unm|__iter|__idiv)\\b", + "name": "variable.language.metamethod.luau" }, { - "include": "#type_literal" + "match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b", + "name": "entity.name.function.luau" } ] }, "local-declaration": { - "begin": "\\b(?:(local)\\s+\\b)", + "begin": "\\b(local)\\b", "end": "(?=\\s*do\\b|\\s*[=;]|\\s*$)", "beginCaptures": { "1": { @@ -125,185 +148,103 @@ }, "patterns": [ { - "name": "keyword.operator.type.luau", - "match": ":" + "include": "#comment" }, { - "include": "#keywords" - }, - { - "name": "variable.parameter.luau", - "match": "(?.]\\s*)\\b_\\b" + "begin": "(:)", + "beginCaptures": { + "1": { + "name": "keyword.operator.type.luau" + } + }, + "end": "(?=\\s*do\\b|\\s*[=;,]|\\s*$)", + "patterns": [ + { + "include": "#type_literal" + } + ] }, { "name": "variable.other.constant.luau", - "match": "(?.]\\s*)\\b([A-Z_][A-Z0-9_]*)\\b" - }, - { - "name": "variable.other.luau", - "match": "(?.]\\s*)\\b([a-zA-Z_]\\w*)\\b" + "match": "\\b([A-Z_][A-Z0-9_]*)\\b" }, { - "include": "#type_literal" + "name": "variable.other.readwrite.luau", + "match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b" } ] }, "for-loop": { - "match": "\\b(for)\\s+(.+?)(\\bin\\b|(=))", - "captures": { + "begin": "\\b(for)\\b", + "beginCaptures": { "1": { "name": "keyword.control.luau" - }, - "2": { - "patterns": [ - { - "name": "keyword.operator.type.luau", - "match": ":" - }, - { - "name": "variable.parameter.luau", - "match": "(?.]\\s*)\\b_\\b" - }, - { - "name": "variable.other.constant.luau", - "match": "(?.]\\s*)\\b([A-Z_][A-Z0-9_]*)\\b" - }, - { - "name": "variable.parameter.luau", - "match": "(?.]\\s*)\\b([a-zA-Z_]\\w*)\\b" - }, - { - "include": "#type_literal" - } - ] - }, - "3": { - "name": "keyword.control.luau" - }, - "4": { - "name": "keyword.operator.assignment.luau" } - } - }, - "type-alias-declaration": { - "begin": "\\b(?:(export)\\s+)?(type)\\s+([^=]+)\\s*(=)", - "end": "(?=\\s*$)|(?=\\s*;)", - "beginCaptures": { + }, + "end": "\\b(in)\\b|(=)", + "endCaptures": { "1": { - "name": "storage.modifier.visibility.luau" + "name": "keyword.control.luau" }, "2": { - "name": "storage.type.luau" - }, - "3": { - "patterns": [ - { - "name": "keyword.operator.type.luau", - "match": "[<>]" - }, - { - "name": "entity.name.type.alias.luau", - "match": "\\b[a-zA-Z_]\\w*\\b" - } - ] - }, - "4": { "name": "keyword.operator.assignment.luau" } }, "patterns": [ { - "include": "#type_literal" - } - ] - }, - "keywords": { - "patterns": [ - { - "name": "storage.modifier.local.luau", - "match": "\\blocal\\b" - }, - { - "name": "keyword.control.luau", - "match": "\\b(break|do|else|for|if|elseif|return|then|repeat|while|until|end|function|in|continue)\\b" - }, - { - "name": "variable.language.metamethod.luau", - "match": "\\b(__add|__call|__concat|__div|__eq|__index|__le|__len|__lt|__metatable|__mod|__mode|__mul|__newindex|__pow|__sub|__tostring|__unm)\\b" + "begin": "(:)", + "beginCaptures": { + "1": { + "name": "keyword.operator.type.luau" + } + }, + "end": "(?=\\s*in\\b|\\s*[=,]|\\s*$)", + "patterns": [ + { + "include": "#type_literal" + } + ] }, { - "name": "keyword.other.unit.luau", - "match": "(\\.\\.\\.)" + "name": "variable.parameter.luau", + "match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b" } ] }, - "standard_library": { - "patterns": [ - { - "name": "support.function.luau", - "match": "\\b(assert|collectgarbage|error|getfenv|getmetatable|ipairs|loadstring|newproxy|next|pairs|pcall|print|rawequal|rawset|select|setfenv|setmetatable|tonumber|tostring|type|unpack|xpcall|require|typeof)\\b" - }, - { - "name": "constant.language.luau", - "match": "\\b(_G|_VERSION)\\b" - }, - { - "name": "support.function.luau", - "match": "\\b(bit32\\.(?:arshift|band|bnot|bor|btest|bxor|extract|lrotate|lshift|replace|rrotate|rshift)|coroutine\\.(?:create|isyieldable|resume|running|status|wrap|yield)|debug\\.(?:loadmodule|profilebegin|profileend|traceback)|math\\.(?:abs|acos|asin|atan|atan2|ceil|clamp|cos|cosh|deg|exp|floor|fmod|frexp|ldexp|log|log10|max|min|modf|noise|pow|rad|random|randomseed|round|sign|sin|sinh|sqrt|tan|tanh)|os\\.(?:clock|date|difftime|time)|string\\.(?:byte|char|find|format|gmatch|gsub|len|lower|match|pack|packsize|rep|reverse|split|sub|unpack|upper)|table\\.(?:concat|create|find|foreach|foreachi|getn|insert|maxn|move|pack|remove|sort|unpack|clear)|task\\.(?:spawn|synchronize|desynchronize|wait|defer|delay)|utf8\\.(?:char|codepoint|codes|graphemes|len|nfcnormalize|nfdnormalize|offset))\\b" - }, - { - "name": "support.constant.luau", - "match": "\\b(bit32|coroutine|debug|math(\\.(huge|pi))?|os|string|table|task|utf8(\\.charpattern)?)\\b" - }, - { - "name": "support.function.luau", - "match": "\\b(delay|DebuggerManager|elapsedTime|PluginManager|printidentity|settings|spawn|stats|tick|time|UserSettings|version|wait|warn)\\b" - }, - { - "name": "constant.language.luau", - "match": "\\b(game|plugin|shared|script|workspace|Enum(?:\\.\\w+){0,2})\\b" + "shebang": { + "captures": { + "1": { + "name": "punctuation.definition.comment.luau" } - ] + }, + "match": "\\A(#!).*$\\n?", + "name": "comment.line.shebang.luau" }, - "operators": { + "string_escape": { "patterns": [ { - "name": "keyword.operator.arithmetic.luau", - "match": "(\\+|-(?!-)|/|\\*|%|\\^)" - }, - { - "name": "keyword.operator.logical.luau keyword.operator.wordlike.luau", - "match": "\\b(and|or|not)\\b" + "name": "constant.character.escape.luau", + "match": "\\\\[abfnrtvz'\"`{\\\\]" }, { - "name": "keyword.operator.assignment.luau", - "match": "(\\+=|-=|/=|\\*=|%=|\\^=|\\.\\.=|=)" + "name": "constant.character.escape.luau", + "match": "\\\\\\d{1,3}" }, { - "name": "keyword.operator.other.luau", - "match": "(\\.\\.|\\#)" + "name": "constant.character.escape.luau", + "match": "\\\\x[0-9a-fA-F]{2}" }, { - "name": "keyword.operator.comparison.luau", - "match": "(==|~=|>=|>|<=|<)" + "name": "constant.character.escape.luau", + "match": "\\\\u\\{[0-9a-fA-F]*\\}" }, { - "begin": "(::)\\s+", - "beginCaptures": { - "1": { - "name": "keyword.operator.typeassertion.luau" - } - }, - "end": "(?=^|[;),}\\]:?\\-\\+\\>]|\\|\\||\\&\\&|\\!\\=\\=|$|(::\\s+)|(\\s+\\<))", - "patterns": [ - { - "include": "#type_literal" - } - ] + "name": "constant.character.escape.luau", + "match": "\\\\$" } ] }, - "numbers": { + "number": { "patterns": [ { "name": "constant.numeric.hex.luau", @@ -319,23 +260,7 @@ } ] }, - "language_constants": { - "patterns": [ - { - "name": "constant.language.boolean.true.luau", - "match": "\\btrue\\b" - }, - { - "name": "constant.language.boolean.false.luau", - "match": "\\bfalse\\b" - }, - { - "name": "constant.language.nil.luau", - "match": "\\bnil\\b" - } - ] - }, - "strings": { + "string": { "patterns": [ { "name": "string.quoted.double.luau", @@ -368,7 +293,7 @@ "end": "`", "patterns": [ { - "include": "#interpolated-string-expression" + "include": "#interpolated_string_expression" }, { "include": "#string_escape" @@ -377,27 +302,7 @@ } ] }, - "string_escape": { - "patterns": [ - { - "name": "constant.character.escape.luau", - "match": "\\\\[abfnrtvz'\"`{\\\\]" - }, - { - "name": "constant.character.escape.luau", - "match": "\\\\\\d{1,3}" - }, - { - "name": "constant.character.escape.luau", - "match": "\\\\x[0-9a-fA-F]{2}" - }, - { - "name": "constant.character.escape.luau", - "match": "\\\\u\\{[0-9a-fA-F]*\\}" - } - ] - }, - "interpolated-string-expression": { + "interpolated_string_expression": { "name": "meta.template.expression.luau", "contentName": "meta.embedded.line.luau", "begin": "\\{", @@ -414,71 +319,173 @@ }, "patterns": [ { - "include": "#expression" + "include": "source.luau" } ] }, - "expression": { + "standard_library": { "patterns": [ { - "include": "#keywords" + "name": "support.function.luau", + "match": "(?=?", + "name": "keyword.operator.comparison.luau" }, { - "name": "variable.other.readwrite.luau", - "match": "\\b([a-zA-Z_]\\w*)\\b" + "match": "\\+=|-=|/=|//=|\\*=|%=|\\^=|\\.\\.=|=", + "name": "keyword.operator.assignment.luau" }, { - "match": "\\b(Axes|BrickColor|CFrame|Color3|ColorSequence|ColorSequenceKeypoint|DateTime|DockWidgetPluginGuiInfo|Faces|Instance|NumberRange|NumberSequence|NumberSequenceKeypoint|OverlapParams|PathWaypoint|PhysicalProperties|Random|Ray|RaycastParams|Rect|Region3|Region3int16|TweenInfo|UDim|UDim2|Vector2|Vector2int16|Vector3|Vector3int16)\\b\\.?(\\b[a-zA-Z_]\\w*(?=\\())?", - "captures": { - "1": { - "name": "support.class.luau" - }, - "2": { - "name": "support.function.luau" - } - } + "match": "\\+|-|%|\\*|\\/\\/|\\/|\\^", + "name": "keyword.operator.arithmetic.luau" + }, + { + "match": "#|(?)", + "patterns": [ + { + "match": "[a-zA-Z_][a-zA-Z0-9_]*", + "name": "entity.name.type.luau" + }, + { + "match": "=", + "name": "keyword.operator.assignment.luau" + }, + { + "include": "#type_literal" + } + ] + }, + "type-alias-declaration": { + "begin": "^\\b(?:(export)\\s+)?(type)\\b", + "end": "(?=\\s*$)|(?=\\s*;)", + "beginCaptures": { + "1": { + "name": "storage.modifier.visibility.luau" + }, + "2": { + "name": "storage.type.luau" + } + }, + "patterns": [ + { + "include": "#type_literal" + }, + { + "match": "=", + "name": "keyword.operator.assignment.luau" + } + ] + }, + "type_annotation": { + "begin": ":(?!\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b(?=\\s*(?:[({\"']|\\[\\[)))", + "end": "(?<=\\))(?!\\s*->)|=|;|$|(?=\\breturn\\b)|(?=\\bend\\b)", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#type_literal" + } + ] + }, + "type_cast": { + "begin": "(::)", + "beginCaptures": { + "1": { + "name": "keyword.operator.typecast.luau" + } + }, + "end": "(?=^|[;),}\\]:?\\-\\+\\>](?!\\s*[&\\|])|$|\\b(break|do|else|for|if|elseif|return|then|repeat|while|until|end|in|continue)\\b)", + "patterns": [ + { + "include": "#type_literal" + } + ] + }, "type_literal": { "patterns": [ { - "name": "keyword.operator.type.luau", - "match": "([\\?|\\||\\&])" + "include": "#comment" }, { - "name": "keyword.operator.type.luau", - "match": "(->)" + "include": "#string" }, { - "begin": "\\b(typeof)\\b\\s*\\(", - "end": "\\)(?![.:\\)])", + "match": "\\?|\\&|\\|", + "name": "keyword.operator.type.luau" + }, + { + "match": "->", + "name": "keyword.operator.type.luau" + }, + { + "match": "\\b(false)\\b", + "name": "constant.language.boolean.false.luau" + }, + { + "match": "\\b(true)\\b", + "name": "constant.language.boolean.true.luau" + }, + { + "name": "support.type.primitive.luau", + "match": "\\b(nil|string|number|boolean|thread|userdata|symbol|any)\\b" + }, + { + "begin": "\\b(typeof)\\b(\\()", "beginCaptures": { "1": { "name": "support.function.luau" + }, + "2": { + "name": "punctuation.arguments.begin.typeof.luau" + } + }, + "end": "(\\))", + "endCaptures": { + "1": { + "name": "punctuation.arguments.end.typeof.luau" } }, "patterns": [ { - "include": "#expression" + "include": "source.luau" } ] }, { - "name": "support.type.primitive.luau", - "match": "\\b(nil|string|number|boolean|thread|userdata|symbol|any)\\b" - }, - { - "include": "#language_constants" - }, - { - "begin": "\\b([a-zA-Z]\\w*)\\b(<)", + "begin": "(<)", "end": "(>)", "beginCaptures": { "1": { - "name": "entity.name.type.luau" - }, - "2": { "name": "keyword.operator.type.luau" } }, @@ -594,24 +681,23 @@ } }, "patterns": [ + { + "match": "=", + "name": "keyword.operator.assignment.luau" + }, { "include": "#type_literal" } - ], - "contentName": "meta.parameter.type.variable.luau" + ] }, { - "name": "entity.name.type.luau", - "match": "\\b([a-zA-Z]\\w*)\\b" + "match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b", + "name": "entity.name.type.luau" }, { "begin": "\\{", "end": "\\}", "patterns": [ - { - "name": "keyword.operator.type.luau", - "match": ":" - }, { "begin": "\\[", "end": "\\]", @@ -622,31 +708,32 @@ ] }, { - "name": "variable.property.luau", - "match": "(?\\s*)\\b([a-zA-Z_]\\w*)\\b(?=:)" + "match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b(:)", + "captures": { + "1": { + "name": "variable.property.luau" + }, + "2": { + "name": "keyword.operator.type.luau" + } + } }, { "include": "#type_literal" + }, + { + "match": "[,;]", + "name": "punctuation.separator.fields.type.luau" } ] }, { - "begin": "(\\s*\\<[\\w\\s\\,]*\\>\\s*)?\\(", + "begin": "\\(", "end": "\\)", - "beginCaptures": { - "1": { - "patterns": [ - { - "name": "entity.name.type.luau", - "match": "\\b([a-zA-Z]\\w*)\\b" - } - ] - } - }, "patterns": [ { "name": "variable.parameter.luau", - "match": "([a-zA-Z_]\\w*)\\s*(:)", + "match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b(:)", "captures": { "1": { "name": "variable.parameter.luau" @@ -660,12 +747,6 @@ "include": "#type_literal" } ] - }, - { - "include": "#strings" - }, - { - "include": "#comments" } ] }