From 9e0eac5e20d2a3c09669244a64d871a6faa3267e Mon Sep 17 00:00:00 2001 From: Nick Winans Date: Fri, 28 Jun 2024 01:16:00 -0700 Subject: [PATCH] feat: add Luau language support (#67) --- packages/tm-grammars/NOTICE | 53 ++ packages/tm-grammars/README.md | 1 + packages/tm-grammars/grammars/luau.json | 772 ++++++++++++++++++++++++ packages/tm-grammars/index.js | 11 + samples/luau.sample | 14 + sources-grammars.ts | 4 + 6 files changed, 855 insertions(+) create mode 100644 packages/tm-grammars/grammars/luau.json create mode 100644 samples/luau.sample diff --git a/packages/tm-grammars/NOTICE b/packages/tm-grammars/NOTICE index 4c2444e..08c5cb6 100644 --- a/packages/tm-grammars/NOTICE +++ b/packages/tm-grammars/NOTICE @@ -4588,6 +4588,59 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +========================================================================================================= +Files: luau.json +License: https://raw.githubusercontent.com/JohnnyMorganz/Luau.tmLanguage/main/LICENSE.md +SPDX: NOASSERTION +--------------------------------------------------------------------------------------------------------- +Copyright (c) JohnnyMorganz +All rights reserved. + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +=== + +Copyright (c) Microsoft Corporation +All rights reserved. + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + ========================================================================================================= Files: markdown-vue.json, vue.json, vue-directives.json, vue-interpolations.json, vue-sfc-style-variable-injection.json License: https://raw.githubusercontent.com/vuejs/language-tools/master/LICENSE diff --git a/packages/tm-grammars/README.md b/packages/tm-grammars/README.md index 4e75db1..dd70845 100644 --- a/packages/tm-grammars/README.md +++ b/packages/tm-grammars/README.md @@ -126,6 +126,7 @@ import { grammars } from 'tm-grammars' | `log` | | [emilast/vscode-logfile-highlighter](https://github.com/emilast/vscode-logfile-highlighter/blob/eb50e785c27b4b4f7dbf6c0e801c58fe91baef5d/syntaxes/log.tmLanguage) | [MIT](https://raw.githubusercontent.com/emilast/vscode-logfile-highlighter/master/LICENSE) | | 2.51 kB | | `logo` | | [textmate/logo.tmbundle](https://github.com/textmate/logo.tmbundle/blob/3205e987ed2a2aa11accdd55a7d094832441f89c/Syntaxes/Logo.tmLanguage) | | | 3.03 kB | | `lua` | | [microsoft/vscode](https://github.com/microsoft/vscode/blob/5c213a1e84928c7a7d11ca5b282ca602d40c1352/extensions/lua/syntaxes/lua.tmLanguage.json) | [MIT](https://raw.githubusercontent.com/microsoft/vscode/main/LICENSE.txt) | `c` | 14.41 kB | +| `luau` | | [JohnnyMorganz/Luau.tmLanguage](https://github.com/JohnnyMorganz/Luau.tmLanguage/blob/5febad569516f7a3a587b59389fc2cdc40bff972/Luau.tmLanguage) | [NOASSERTION](https://raw.githubusercontent.com/JohnnyMorganz/Luau.tmLanguage/main/LICENSE.md) | | 12.01 kB | | `make` | `makefile` | [microsoft/vscode](https://github.com/microsoft/vscode/blob/91db8ea85fee30ebb3c7a5e7939aa2a8d79811c5/extensions/make/syntaxes/make.tmLanguage.json) | [MIT](https://raw.githubusercontent.com/microsoft/vscode/main/LICENSE.txt) | | 8.45 kB | | `markdown` | `md` | [microsoft/vscode](https://github.com/microsoft/vscode/blob/6b0a582e595fab7da09fcd267f4f8248e7ec437e/extensions/markdown-basics/syntaxes/markdown.tmLanguage.json) | [MIT](https://raw.githubusercontent.com/microsoft/vscode/main/LICENSE.txt) | `css` `html` `ini` `java` `lua` `make` `perl` `r` `ruby` `php` `sql` `vb` `xml` `xsl` `yaml` `bat` `clojure` `coffee` `c` `cpp` `diff` `docker` `git-commit` `git-rebase` `go` `groovy` `pug` `javascript` `json` `jsonc` `less` `objective-c` `swift` `scss` `raku` `powershell` `python` `julia` `rust` `scala` `shellscript` `typescript` `tsx` `csharp` `fsharp` `dart` `handlebars` `log` `erlang` `elixir` `latex` `bibtex` `html-derivative` | 52.58 kB | | `marko` | | [marko-js/marko-tmbundle](https://github.com/marko-js/marko-tmbundle/blob/dd3a0c39e656bedd276d3bcbdea92a2d627755c7/Syntaxes/marko.tmLanguage) | [MIT](https://raw.githubusercontent.com/marko-js/marko-tmbundle/master/LICENSE) | `css` `less` `scss` `javascript` | 18.31 kB | diff --git a/packages/tm-grammars/grammars/luau.json b/packages/tm-grammars/grammars/luau.json new file mode 100644 index 0000000..48ae3c0 --- /dev/null +++ b/packages/tm-grammars/grammars/luau.json @@ -0,0 +1,772 @@ +{ + "displayName": "Luau", + "fileTypes": [ + "luau" + ], + "name": "luau", + "patterns": [ + { + "include": "#function-definition" + }, + { + "include": "#number" + }, + { + "include": "#string" + }, + { + "include": "#shebang" + }, + { + "include": "#comment" + }, + { + "include": "#local-declaration" + }, + { + "include": "#for-loop" + }, + { + "include": "#type-alias-declaration" + }, + { + "include": "#keyword" + }, + { + "include": "#language_constant" + }, + { + "include": "#standard_library" + }, + { + "include": "#identifier" + }, + { + "include": "#operator" + }, + { + "include": "#parentheses" + }, + { + "include": "#table" + }, + { + "include": "#type_cast" + }, + { + "include": "#type_annotation" + }, + { + "include": "#attribute" + } + ], + "repository": { + "attribute": { + "patterns": [ + { + "captures": { + "1": { + "name": "keyword.operator.attribute.luau" + }, + "2": { + "name": "storage.type.attribute.luau" + } + }, + "match": "(@)([a-zA-Z_][a-zA-Z0-9_]*)", + "name": "meta.attribute.luau" + } + ] + }, + "comment": { + "patterns": [ + { + "begin": "--\\[(=*)\\[", + "end": "\\]\\1\\]", + "name": "comment.block.luau", + "patterns": [ + { + "begin": "(```lua)\\s+", + "beginCaptures": { + "1": { + "name": "comment.luau" + } + }, + "end": "(```)", + "endCaptures": { + "1": { + "name": "comment.luau" + } + }, + "name": "keyword.operator.other.luau", + "patterns": [ + { + "include": "source.luau" + } + ] + }, + { + "include": "#doc_comment_tags" + } + ] + }, + { + "begin": "---", + "end": "\\n", + "name": "comment.line.double-dash.documentation.luau", + "patterns": [ + { + "include": "#doc_comment_tags" + } + ] + }, + { + "begin": "--", + "end": "\\n", + "name": "comment.line.double-dash.luau" + } + ] + }, + "doc_comment_tags": { + "patterns": [ + { + "match": "@\\w+", + "name": "storage.type.class.luadoc.luau" + }, + { + "captures": { + "1": { + "name": "storage.type.class.luadoc.luau" + }, + "2": { + "name": "variable.parameter.luau" + } + }, + "match": "((?<=[\\s*!\\/])[\\\\@]param)(?:\\s)+(\\b\\w+\\b)" + } + ] + }, + "for-loop": { + "begin": "\\b(for)\\b", + "beginCaptures": { + "1": { + "name": "keyword.control.luau" + } + }, + "end": "\\b(in)\\b|(=)", + "endCaptures": { + "1": { + "name": "keyword.control.luau" + }, + "2": { + "name": "keyword.operator.assignment.luau" + } + }, + "patterns": [ + { + "begin": "(:)", + "beginCaptures": { + "1": { + "name": "keyword.operator.type.luau" + } + }, + "end": "(?=\\s*in\\b|\\s*[=,]|\\s*$)", + "patterns": [ + { + "include": "#type_literal" + } + ] + }, + { + "match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b", + "name": "variable.parameter.luau" + } + ] + }, + "function-definition": { + "begin": "\\b(?:(local)\\s+)?(function)\\b(?![,:])", + "beginCaptures": { + "1": { + "name": "storage.modifier.local.luau" + }, + "2": { + "name": "keyword.control.luau" + } + }, + "end": "(?<=[\\)\\-{}\\[\\]\"'])", + "name": "meta.function.luau", + "patterns": [ + { + "include": "#comment" + }, + { + "include": "#generics-declaration" + }, + { + "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" + } + ] + } + ] + }, + { + "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" + }, + { + "match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b", + "name": "entity.name.function.luau" + } + ] + }, + "generics-declaration": { + "begin": "(<)", + "end": "(>)", + "patterns": [ + { + "match": "[a-zA-Z_][a-zA-Z0-9_]*", + "name": "entity.name.type.luau" + }, + { + "match": "=", + "name": "keyword.operator.assignment.luau" + }, + { + "include": "#type_literal" + } + ] + }, + "identifier": { + "patterns": [ + { + "match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b(?=\\s*(?:[({\"']|\\[\\[))", + "name": "entity.name.function.luau" + }, + { + "match": "(?<=[^.]\\.|:)\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b", + "name": "variable.other.property.luau" + }, + { + "match": "\\b([A-Z_][A-Z0-9_]*)\\b", + "name": "variable.other.constant.luau" + }, + { + "match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b", + "name": "variable.other.readwrite.luau" + } + ] + }, + "interpolated_string_expression": { + "begin": "\\{", + "beginCaptures": { + "0": { + "name": "punctuation.definition.interpolated-string-expression.begin.luau" + } + }, + "contentName": "meta.embedded.line.luau", + "end": "\\}", + "endCaptures": { + "0": { + "name": "punctuation.definition.interpolated-string-expression.end.luau" + } + }, + "name": "meta.template.expression.luau", + "patterns": [ + { + "include": "source.luau" + } + ] + }, + "keyword": { + "patterns": [ + { + "match": "\\b(break|do|else|for|if|elseif|return|then|repeat|while|until|end|in|continue)\\b", + "name": "keyword.control.luau" + }, + { + "match": "\\b(local)\\b", + "name": "storage.modifier.local.luau" + }, + { + "match": "\\b(function)\\b(?![,:])", + "name": "keyword.control.luau" + }, + { + "match": "(?=?", + "name": "keyword.operator.comparison.luau" + }, + { + "match": "\\+=|-=|/=|//=|\\*=|%=|\\^=|\\.\\.=|=", + "name": "keyword.operator.assignment.luau" + }, + { + "match": "\\+|-|%|\\*|\\/\\/|\\/|\\^", + "name": "keyword.operator.arithmetic.luau" + }, + { + "match": "#|(?)|=|;|$|(?=\\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": [ + { + "include": "#comment" + }, + { + "include": "#string" + }, + { + "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" + }, + { + "match": "\\b(nil|string|number|boolean|thread|userdata|symbol|any)\\b", + "name": "support.type.primitive.luau" + }, + { + "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": "source.luau" + } + ] + }, + { + "begin": "(<)", + "beginCaptures": { + "1": { + "name": "keyword.operator.type.luau" + } + }, + "end": "(>)", + "endCaptures": { + "1": { + "name": "keyword.operator.type.luau" + } + }, + "patterns": [ + { + "match": "=", + "name": "keyword.operator.assignment.luau" + }, + { + "include": "#type_literal" + } + ] + }, + { + "match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b", + "name": "entity.name.type.luau" + }, + { + "begin": "\\{", + "end": "\\}", + "patterns": [ + { + "begin": "\\[", + "end": "\\]", + "patterns": [ + { + "include": "#type_literal" + } + ] + }, + { + "captures": { + "1": { + "name": "variable.property.luau" + }, + "2": { + "name": "keyword.operator.type.luau" + } + }, + "match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b(:)" + }, + { + "include": "#type_literal" + }, + { + "match": "[,;]", + "name": "punctuation.separator.fields.type.luau" + } + ] + }, + { + "begin": "\\(", + "end": "\\)", + "patterns": [ + { + "captures": { + "1": { + "name": "variable.parameter.luau" + }, + "2": { + "name": "keyword.operator.type.luau" + } + }, + "match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)\\b(:)", + "name": "variable.parameter.luau" + }, + { + "include": "#type_literal" + } + ] + } + ] + } + }, + "scopeName": "source.luau" +} diff --git a/packages/tm-grammars/index.js b/packages/tm-grammars/index.js index f3fa536..f8a86c0 100644 --- a/packages/tm-grammars/index.js +++ b/packages/tm-grammars/index.js @@ -1677,6 +1677,17 @@ export const grammars = [ sha: '5c213a1e84928c7a7d11ca5b282ca602d40c1352', source: 'https://github.com/microsoft/vscode/blob/5c213a1e84928c7a7d11ca5b282ca602d40c1352/extensions/lua/syntaxes/lua.tmLanguage.json', }, + { + byteSize: 12296, + displayName: 'Luau', + lastUpdate: '2024-06-22T10:31:37Z', + license: 'NOASSERTION', + licenseUrl: 'https://raw.githubusercontent.com/JohnnyMorganz/Luau.tmLanguage/main/LICENSE.md', + name: 'luau', + scopeName: 'source.luau', + sha: '5febad569516f7a3a587b59389fc2cdc40bff972', + source: 'https://github.com/JohnnyMorganz/Luau.tmLanguage/blob/5febad569516f7a3a587b59389fc2cdc40bff972/Luau.tmLanguage', + }, { aliases: [ 'makefile', diff --git a/samples/luau.sample b/samples/luau.sample new file mode 100644 index 0000000..aed3008 --- /dev/null +++ b/samples/luau.sample @@ -0,0 +1,14 @@ +--!strict + +function ispositive(x : number) : string + if x > 0 then + return "yes" + else + return "no" + end +end + +local result : string +result = ispositive(1) + +-- From https://luau-lang.org/getting-started \ No newline at end of file diff --git a/sources-grammars.ts b/sources-grammars.ts index add7506..c8a07a8 100644 --- a/sources-grammars.ts +++ b/sources-grammars.ts @@ -707,6 +707,10 @@ export const sourcesCommunity: GrammarSource[] = [ name: 'logo', source: 'https://github.com/textmate/logo.tmbundle/blob/master/Syntaxes/Logo.tmLanguage', }, + { + name: 'luau', + source: 'https://github.com/JohnnyMorganz/Luau.tmLanguage/blob/main/Luau.tmLanguage', + }, { name: 'marko', source: 'https://github.com/marko-js/marko-tmbundle/blob/master/Syntaxes/marko.tmLanguage',