From 905bc3c8bb8b0da8d33c4731d8adf3949fb637a4 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Wed, 31 Jan 2024 18:47:15 -0800 Subject: [PATCH] need json --- grammars/typespec.json | 1271 ++++++++++++++++++++ packages/compiler/src/server/tmlanguage.ts | 5 + 2 files changed, 1276 insertions(+) create mode 100644 grammars/typespec.json diff --git a/grammars/typespec.json b/grammars/typespec.json new file mode 100644 index 0000000000..a7472e4cbf --- /dev/null +++ b/grammars/typespec.json @@ -0,0 +1,1271 @@ +{ + "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", + "name": "TypeSpec", + "scopeName": "source.tsp", + "fileTypes": [ + ".tsp" + ], + "patterns": [ + { + "include": "#statement" + } + ], + "repository": { + "alias-statement": { + "name": "meta.alias-statement.typespec", + "begin": "\\b(alias)\\b", + "beginCaptures": { + "1": { + "name": "keyword.other.tsp" + } + }, + "end": "(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)", + "patterns": [ + { + "include": "#type-parameters" + }, + { + "include": "#operator-assignment" + }, + { + "include": "#expression" + } + ] + }, + "augment-decorator-statement": { + "name": "meta.augment-decorator-statement.typespec", + "begin": "((@@)\\b[_$[:alpha:]]([_$[:alnum:]]|\\.[_$[:alpha:]])*\\b)", + "beginCaptures": { + "1": { + "name": "entity.name.tag.tsp" + }, + "2": { + "name": "entity.name.tag.tsp" + } + }, + "end": "(?=[_$[:alpha:]])|(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)", + "patterns": [ + { + "include": "#token" + }, + { + "include": "#parenthesized-expression" + } + ] + }, + "block-comment": { + "name": "comment.block.tsp", + "begin": "/\\*", + "end": "\\*/" + }, + "boolean-literal": { + "name": "constant.language.tsp", + "match": "\\b(true|false)\\b" + }, + "decorator": { + "name": "meta.decorator.typespec", + "begin": "((@)\\b[_$[:alpha:]]([_$[:alnum:]]|\\.[_$[:alpha:]])*\\b)", + "beginCaptures": { + "1": { + "name": "entity.name.tag.tsp" + }, + "2": { + "name": "entity.name.tag.tsp" + } + }, + "end": "(?=[_$[:alpha:]])|(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)", + "patterns": [ + { + "include": "#token" + }, + { + "include": "#parenthesized-expression" + } + ] + }, + "decorator-declaration-statement": { + "name": "meta.decorator-declaration-statement.typespec", + "begin": "(?:(extern)\\s+)?\\b(dec)\\b\\s+(\\b[_$[:alpha:]][_$[:alnum:]]*\\b)", + "beginCaptures": { + "1": { + "name": "keyword.other.tsp" + }, + "2": { + "name": "keyword.other.tsp" + }, + "3": { + "name": "entity.name.function.tsp" + } + }, + "end": "(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)", + "patterns": [ + { + "include": "#token" + }, + { + "include": "#operation-parameters" + } + ] + }, + "directive": { + "name": "meta.directive.typespec", + "begin": "\\s*(#\\b[_$[:alpha:]][_$[:alnum:]]*\\b)", + "beginCaptures": { + "1": { + "name": "keyword.directive.name.tsp" + } + }, + "end": "$|(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)", + "patterns": [ + { + "include": "#string-literal" + }, + { + "include": "#identifier-expression" + } + ] + }, + "doc-comment": { + "name": "comment.block.tsp", + "begin": "/\\*\\*", + "beginCaptures": { + "0": { + "name": "comment.block.tsp" + } + }, + "end": "\\*/", + "endCaptures": { + "0": { + "name": "comment.block.tsp" + } + }, + "patterns": [ + { + "include": "#doc-comment-block" + } + ] + }, + "doc-comment-block": { + "patterns": [ + { + "include": "#doc-comment-param" + }, + { + "include": "#doc-comment-return-tag" + }, + { + "include": "#doc-comment-unknown-tag" + } + ] + }, + "doc-comment-param": { + "name": "comment.block.tsp", + "match": "(?x)((@)(?:param|template))\\s+(\\b[_$[:alpha:]][_$[:alnum:]]*\\b)\\b", + "captures": { + "1": { + "name": "keyword.tag.tspdoc" + }, + "2": { + "name": "keyword.tag.tspdoc" + }, + "3": { + "name": "variable.name.tsp" + } + } + }, + "doc-comment-return-tag": { + "name": "comment.block.tsp", + "match": "(?x)((@)(?:returns))\\b", + "captures": { + "1": { + "name": "keyword.tag.tspdoc" + }, + "2": { + "name": "keyword.tag.tspdoc" + } + } + }, + "doc-comment-unknown-tag": { + "name": "comment.block.tsp", + "match": "(?x)((@)(?:\\b[_$[:alpha:]][_$[:alnum:]]*\\b))\\b", + "captures": { + "1": { + "name": "entity.name.tag.tsp" + }, + "2": { + "name": "entity.name.tag.tsp" + } + } + }, + "else-expression": { + "name": "meta.else-expression.typespec", + "begin": "\\b(else)\\b", + "beginCaptures": { + "1": { + "name": "keyword.other.tsp" + } + }, + "end": "((?<=\\})|(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b))", + "patterns": [ + { + "include": "#projection-expression" + }, + { + "include": "#projection-body" + } + ] + }, + "else-if-expression": { + "name": "meta.else-if-expression.typespec", + "begin": "\\b(else)\\s+(if)\\b", + "beginCaptures": { + "1": { + "name": "keyword.other.tsp" + }, + "2": { + "name": "keyword.other.tsp" + } + }, + "end": "((?<=\\})|(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b))", + "patterns": [ + { + "include": "#projection-expression" + }, + { + "include": "#projection-body" + } + ] + }, + "enum-statement": { + "name": "meta.enum-statement.typespec", + "begin": "\\b(enum)\\b", + "beginCaptures": { + "1": { + "name": "keyword.other.tsp" + } + }, + "end": "(?<=\\})|(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)", + "patterns": [ + { + "include": "#token" + }, + { + "include": "#expression" + } + ] + }, + "escape-character": { + "name": "constant.character.escape.tsp", + "match": "\\\\." + }, + "expression": { + "patterns": [ + { + "include": "#token" + }, + { + "include": "#directive" + }, + { + "include": "#parenthesized-expression" + }, + { + "include": "#valueof" + }, + { + "include": "#type-arguments" + }, + { + "include": "#tuple-expression" + }, + { + "include": "#model-expression" + }, + { + "include": "#identifier-expression" + } + ] + }, + "function-call": { + "name": "meta.function-call.typespec", + "begin": "(\\b[_$[:alpha:]][_$[:alnum:]]*\\b)\\s*(\\()", + "beginCaptures": { + "1": { + "name": "entity.name.function.tsp" + }, + "2": { + "name": "punctuation.parenthesis.open.tsp" + } + }, + "end": "\\)", + "endCaptures": { + "0": { + "name": "punctuation.parenthesis.close.tsp" + } + }, + "patterns": [ + { + "include": "#expression" + } + ] + }, + "function-declaration-statement": { + "name": "meta.function-declaration-statement.typespec", + "begin": "(?:(extern)\\s+)?\\b(fn)\\b\\s+(\\b[_$[:alpha:]][_$[:alnum:]]*\\b)", + "beginCaptures": { + "1": { + "name": "keyword.other.tsp" + }, + "2": { + "name": "keyword.other.tsp" + }, + "3": { + "name": "entity.name.function.tsp" + } + }, + "end": "(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)", + "patterns": [ + { + "include": "#token" + }, + { + "include": "#operation-parameters" + }, + { + "include": "#type-annotation" + } + ] + }, + "identifier-expression": { + "name": "entity.name.type.tsp", + "match": "\\b[_$[:alpha:]][_$[:alnum:]]*\\b" + }, + "if-expression": { + "name": "meta.if-expression.typespec", + "begin": "\\b(if)\\b", + "beginCaptures": { + "1": { + "name": "keyword.other.tsp" + } + }, + "end": "((?<=\\})|(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b))", + "patterns": [ + { + "include": "#projection-expression" + }, + { + "include": "#projection-body" + } + ] + }, + "import-statement": { + "name": "meta.import-statement.typespec", + "begin": "\\b(import)\\b", + "beginCaptures": { + "1": { + "name": "keyword.other.tsp" + } + }, + "end": "(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)", + "patterns": [ + { + "include": "#token" + } + ] + }, + "interface-body": { + "name": "meta.interface-body.typespec", + "begin": "\\{", + "beginCaptures": { + "0": { + "name": "punctuation.curlybrace.open.tsp" + } + }, + "end": "\\}", + "endCaptures": { + "0": { + "name": "punctuation.curlybrace.close.tsp" + } + }, + "patterns": [ + { + "include": "#token" + }, + { + "include": "#directive" + }, + { + "include": "#decorator" + }, + { + "include": "#interface-member" + }, + { + "include": "#punctuation-semicolon" + } + ] + }, + "interface-heritage": { + "name": "meta.interface-heritage.typespec", + "begin": "\\b(extends)\\b", + "beginCaptures": { + "1": { + "name": "keyword.other.tsp" + } + }, + "end": "((?=\\{)|(?=;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b))", + "patterns": [ + { + "include": "#expression" + }, + { + "include": "#punctuation-comma" + } + ] + }, + "interface-member": { + "name": "meta.interface-member.typespec", + "begin": "(?:\\b(op)\\b\\s+)?(\\b[_$[:alpha:]][_$[:alnum:]]*\\b)", + "beginCaptures": { + "1": { + "name": "keyword.other.tsp" + }, + "2": { + "name": "entity.name.function.tsp" + } + }, + "end": "(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)", + "patterns": [ + { + "include": "#token" + }, + { + "include": "#operation-signature" + } + ] + }, + "interface-statement": { + "name": "meta.interface-statement.typespec", + "begin": "\\b(interface)\\b", + "beginCaptures": { + "1": { + "name": "keyword.other.tsp" + } + }, + "end": "(?<=\\})|(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)", + "patterns": [ + { + "include": "#token" + }, + { + "include": "#interface-heritage" + }, + { + "include": "#interface-body" + }, + { + "include": "#expression" + } + ] + }, + "line-comment": { + "name": "comment.line.double-slash.tsp", + "match": "//.*$" + }, + "model-expression": { + "name": "meta.model-expression.typespec", + "begin": "\\{", + "beginCaptures": { + "0": { + "name": "punctuation.curlybrace.open.tsp" + } + }, + "end": "\\}", + "endCaptures": { + "0": { + "name": "punctuation.curlybrace.close.tsp" + } + }, + "patterns": [ + { + "include": "#model-property" + }, + { + "include": "#token" + }, + { + "include": "#directive" + }, + { + "include": "#decorator" + }, + { + "include": "#model-spread-property" + }, + { + "include": "#punctuation-semicolon" + } + ] + }, + "model-heritage": { + "name": "meta.model-heritage.typespec", + "begin": "\\b(extends|is)\\b", + "beginCaptures": { + "1": { + "name": "keyword.other.tsp" + } + }, + "end": "((?=\\{)|(?=;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b))", + "patterns": [ + { + "include": "#expression" + }, + { + "include": "#punctuation-comma" + } + ] + }, + "model-property": { + "name": "meta.model-property.typespec", + "begin": "(?:(\\b[_$[:alpha:]][_$[:alnum:]]*\\b)|(\\\"(?:[^\\\"\\\\]|\\\\.)*\\\"))", + "beginCaptures": { + "1": { + "name": "variable.name.tsp" + }, + "2": { + "name": "string.quoted.double.tsp" + } + }, + "end": "(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)", + "patterns": [ + { + "include": "#token" + }, + { + "include": "#type-annotation" + }, + { + "include": "#operator-assignment" + }, + { + "include": "#expression" + } + ] + }, + "model-spread-property": { + "name": "meta.model-spread-property.typespec", + "begin": "\\.\\.\\.", + "beginCaptures": { + "0": { + "name": "keyword.operator.spread.tsp" + } + }, + "end": "(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)", + "patterns": [ + { + "include": "#expression" + } + ] + }, + "model-statement": { + "name": "meta.model-statement.typespec", + "begin": "\\b(model)\\b", + "beginCaptures": { + "1": { + "name": "keyword.other.tsp" + } + }, + "end": "(?<=\\})|(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)", + "patterns": [ + { + "include": "#token" + }, + { + "include": "#type-parameters" + }, + { + "include": "#model-heritage" + }, + { + "include": "#expression" + } + ] + }, + "namespace-body": { + "name": "meta.namespace-body.typespec", + "begin": "\\{", + "beginCaptures": { + "0": { + "name": "punctuation.curlybrace.open.tsp" + } + }, + "end": "\\}", + "endCaptures": { + "0": { + "name": "punctuation.curlybrace.close.tsp" + } + }, + "patterns": [ + { + "include": "#statement" + } + ] + }, + "namespace-name": { + "name": "meta.namespace-name.typespec", + "begin": "(?=[_$[:alpha:]])", + "end": "((?=\\{)|(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b))", + "patterns": [ + { + "include": "#identifier-expression" + }, + { + "include": "#punctuation-accessor" + } + ] + }, + "namespace-statement": { + "name": "meta.namespace-statement.typespec", + "begin": "\\b(namespace)\\b", + "beginCaptures": { + "1": { + "name": "keyword.other.tsp" + } + }, + "end": "((?<=\\})|(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b))", + "patterns": [ + { + "include": "#token" + }, + { + "include": "#namespace-name" + }, + { + "include": "#namespace-body" + } + ] + }, + "numeric-literal": { + "name": "constant.numeric.tsp", + "match": "(?:\\b(?", + "endCaptures": { + "0": { + "name": "punctuation.definition.typeparameters.end.tsp" + } + }, + "patterns": [ + { + "include": "#identifier-expression" + }, + { + "include": "#operator-assignment" + }, + { + "include": "#expression" + }, + { + "include": "#punctuation-comma" + } + ] + }, + "type-parameter": { + "name": "meta.type-parameter.typespec", + "begin": "(\\b[_$[:alpha:]][_$[:alnum:]]*\\b)", + "beginCaptures": { + "1": { + "name": "entity.name.type.tsp" + } + }, + "end": "(?=>)|(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)", + "patterns": [ + { + "include": "#type-parameter-constraint" + }, + { + "include": "#type-parameter-default" + } + ] + }, + "type-parameter-constraint": { + "name": "meta.type-parameter-constraint.typespec", + "begin": "extends", + "beginCaptures": { + "0": { + "name": "keyword.other.tsp" + } + }, + "end": "(?=>)|(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)", + "patterns": [ + { + "include": "#expression" + } + ] + }, + "type-parameter-default": { + "name": "meta.type-parameter-default.typespec", + "begin": "=", + "beginCaptures": { + "0": { + "name": "keyword.operator.assignment.tsp" + } + }, + "end": "(?=>)|(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)", + "patterns": [ + { + "include": "#expression" + } + ] + }, + "type-parameters": { + "name": "meta.type-parameters.typespec", + "begin": "<", + "beginCaptures": { + "0": { + "name": "punctuation.definition.typeparameters.begin.tsp" + } + }, + "end": ">", + "endCaptures": { + "0": { + "name": "punctuation.definition.typeparameters.end.tsp" + } + }, + "patterns": [ + { + "include": "#type-parameter" + }, + { + "include": "#punctuation-comma" + } + ] + }, + "union-statement": { + "name": "meta.union-statement.typespec", + "begin": "\\b(union)\\b", + "beginCaptures": { + "1": { + "name": "keyword.other.tsp" + } + }, + "end": "(?<=\\})|(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)", + "patterns": [ + { + "include": "#token" + }, + { + "include": "#expression" + } + ] + }, + "using-statement": { + "name": "meta.using-statement.typespec", + "begin": "\\b(using)\\b", + "beginCaptures": { + "1": { + "name": "keyword.other.tsp" + } + }, + "end": "(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)", + "patterns": [ + { + "include": "#token" + }, + { + "include": "#identifier-expression" + } + ] + }, + "valueof": { + "name": "meta.valueof.typespec", + "begin": "\\b(valueof)", + "beginCaptures": { + "1": { + "name": "keyword.other.tsp" + } + }, + "end": "(?=>)|(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)", + "patterns": [ + { + "include": "#expression" + } + ] + } + } +} \ No newline at end of file diff --git a/packages/compiler/src/server/tmlanguage.ts b/packages/compiler/src/server/tmlanguage.ts index ee9b38427a..55edcad147 100644 --- a/packages/compiler/src/server/tmlanguage.ts +++ b/packages/compiler/src/server/tmlanguage.ts @@ -903,6 +903,11 @@ export async function main() { const plist = await tm.emitPList(grammar, { errorSourceFilePath: resolve("./src/tmlanguage.ts"), }); + const json = await tm.emitJSON(grammar, { + errorSourceFilePath: resolve("./src/tmlanguage.ts"), + }); await mkdir("./dist", { recursive: true }); await writeFile("./dist/typespec.tmLanguage", plist); + await mkdir("../../grammars", { recursive: true }); + await writeFile("../../grammars/typespec.json", json); }