From aff32bd31935d75ef2fadc9057be57dc80953646 Mon Sep 17 00:00:00 2001 From: filipw Date: Wed, 15 Jul 2026 19:54:28 +0200 Subject: [PATCH 1/2] emit schema when doing JSON output --- build.js | 11 +++++++++-- grammars/qsharp.tmLanguage.json | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/build.js b/build.js index d3194ac..6719705 100644 --- a/build.js +++ b/build.js @@ -14,15 +14,22 @@ const plist = require("plist"); const srcFile = path.join(__dirname, "src", "qsharp.tmLanguage.yml"); const grammarsDir = path.join(__dirname, "grammars"); +// JSON Schema for TextMate grammars. Emitted only into the JSON outputs (as the +// first key) +const JSON_SCHEMA = "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json"; + function build() { const text = fs.readFileSync(srcFile, "utf8"); const grammar = jsYaml.load(text); + const jsonGrammar = { $schema: JSON_SCHEMA, ...grammar }; + const jsonText = JSON.stringify(jsonGrammar, null, "\t") + "\n"; + fs.mkdirSync(grammarsDir, { recursive: true }); fs.writeFileSync( path.join(grammarsDir, "qsharp.tmLanguage.json"), - JSON.stringify(grammar, null, "\t") + "\n" + jsonText ); fs.writeFileSync( @@ -38,7 +45,7 @@ function build() { if (fs.existsSync(testExtDir)) { fs.writeFileSync( path.join(testExtDir, "qsharp.tmLanguage.json"), - JSON.stringify(grammar, null, "\t") + "\n" + jsonText ); console.log("Refreshed test-extension/qsharp.tmLanguage.json"); } diff --git a/grammars/qsharp.tmLanguage.json b/grammars/qsharp.tmLanguage.json index 5de613d..2d8bedc 100644 --- a/grammars/qsharp.tmLanguage.json +++ b/grammars/qsharp.tmLanguage.json @@ -1,4 +1,5 @@ { + "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", "name": "qsharp", "scopeName": "source.qsharp", "fileTypes": [ From 5b57dc8feb85ab2659e0b14c8e01f6b49cbfac94 Mon Sep 17 00:00:00 2001 From: filipw Date: Wed, 15 Jul 2026 21:57:58 +0200 Subject: [PATCH 2/2] include prettier default formatting in the build --- build.js | 14 +- grammars/qsharp.tmLanguage.json | 2288 ++++++++++++------------------- package-lock.json | 19 +- package.json | 1 + 4 files changed, 870 insertions(+), 1452 deletions(-) diff --git a/build.js b/build.js index 6719705..65b5766 100644 --- a/build.js +++ b/build.js @@ -10,6 +10,7 @@ const fs = require("fs"); const path = require("path"); const jsYaml = require("js-yaml"); const plist = require("plist"); +const prettier = require("prettier"); const srcFile = path.join(__dirname, "src", "qsharp.tmLanguage.yml"); const grammarsDir = path.join(__dirname, "grammars"); @@ -18,12 +19,16 @@ const grammarsDir = path.join(__dirname, "grammars"); // first key) const JSON_SCHEMA = "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json"; -function build() { +async function build() { const text = fs.readFileSync(srcFile, "utf8"); const grammar = jsYaml.load(text); const jsonGrammar = { $schema: JSON_SCHEMA, ...grammar }; - const jsonText = JSON.stringify(jsonGrammar, null, "\t") + "\n"; + + // format with Prettier's defaults + const jsonText = await prettier.format(JSON.stringify(jsonGrammar), { + parser: "json", + }); fs.mkdirSync(grammarsDir, { recursive: true }); @@ -51,4 +56,7 @@ function build() { } } -build(); +build().catch((err) => { + console.error(err); + process.exit(1); +}); diff --git a/grammars/qsharp.tmLanguage.json b/grammars/qsharp.tmLanguage.json index 2d8bedc..4bd2973 100644 --- a/grammars/qsharp.tmLanguage.json +++ b/grammars/qsharp.tmLanguage.json @@ -1,1449 +1,843 @@ { - "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", - "name": "qsharp", - "scopeName": "source.qsharp", - "fileTypes": [ - "qs" - ], - "patterns": [ - { - "include": "#comments" - }, - { - "include": "#attributes" - }, - { - "include": "#namespace-declaration" - }, - { - "include": "#import-export-directive" - }, - { - "include": "#new-expression" - }, - { - "include": "#struct-declaration" - }, - { - "include": "#member-access" - }, - { - "include": "#tuple-binding" - }, - { - "include": "#keywords" - }, - { - "include": "#library-invocation" - }, - { - "include": "#library" - }, - { - "include": "#operations" - }, - { - "include": "#types" - }, - { - "include": "#literals" - }, - { - "include": "#strings" - }, - { - "include": "#callable-invocation" - }, - { - "include": "#callable-declaration" - }, - { - "include": "#udt-declaration" - }, - { - "include": "#array-creation-expression" - }, - { - "include": "#local-declaration" - }, - { - "include": "#array-assignment" - }, - { - "include": "#local-assignment" - }, - { - "include": "#quantum-declaration" - }, - { - "include": "#if-statement" - }, - { - "include": "#parenthesized-expression" - }, - { - "include": "#expression-operators" - }, - { - "include": "#declaration-keywords" - }, - { - "include": "#identifier" - } - ], - "repository": { - "literals": { - "patterns": [ - { - "include": "#boolean-literal" - }, - { - "include": "#result-literal" - }, - { - "include": "#pauli-literal" - }, - { - "include": "#numeric-literal" - } - ] - }, - "comments": { - "patterns": [ - { - "begin": "(^\\s+)?(?=//)", - "beginCaptures": { - "1": { - "name": "punctuation.whitespace.comment.leading.qsharp" - } - }, - "end": "(?=$)", - "patterns": [ - { - "name": "comment.block.documentation.qsharp", - "begin": "(?\\s*<([^<>]|\\g)+>\\s*)?\\s* # type arguments\n(?=\\() # open parentheses of argument list", - "beginCaptures": { - "1": { - "name": "punctuation.accessor.qsharp" - }, - "2": { - "name": "entity.name.function.qsharp" - }, - "3": { - "patterns": [ - { - "include": "#type-parameter-list" - } - ] - } - }, - "end": "(?<=\\))", - "patterns": [ - { - "include": "#argument-list" - } - ] - }, - "callable-declaration": { - "begin": "(?x)\n\\b(operation|function)\\b\\s+\n([_[:alpha:]][_[:alnum:]]*)\\s* # callable name\n(?\\s*<([^<>]|\\g)+>\\s*)?\\s* # type arguments\n(?=\\() # open parentheses of argument list", - "beginCaptures": { - "1": { - "name": "keyword.other.callable.qsharp" - }, - "2": { - "name": "entity.name.function.qsharp" - }, - "3": { - "patterns": [ - { - "include": "#type-parameter-list" - } - ] - } - }, - "end": "(?<=\\))", - "patterns": [ - { - "include": "#parameter-list" - } - ] - }, - "type-parameter-list": { - "begin": "\\<", - "beginCaptures": { - "0": { - "name": "punctuation.definition.typeparameters.begin.qsharp" - } - }, - "end": "\\>", - "endCaptures": { - "0": { - "name": "punctuation.definition.typeparameters.end.qsharp" - } - }, - "patterns": [ - { - "match": "('[_[:alpha:]][_[:alnum:]]*)\\b", - "captures": { - "1": { - "name": "entity.name.type.type-parameter.qsharp" - } - } - }, - { - "name": "punctuation.separator.colon.qsharp", - "match": ":" - }, - { - "name": "keyword.operator.qsharp", - "match": "\\+" - }, - { - "name": "support.type.constraint.qsharp", - "match": "\\b(Eq|Add|Sub|Mul|Div|Mod|Signed|Ord|Show|Integral|Iterable|Exp)\\b" - }, - { - "name": "punctuation.squarebracket.open.qsharp", - "match": "\\[" - }, - { - "name": "punctuation.squarebracket.close.qsharp", - "match": "\\]" - }, - { - "include": "#punctuation-comma" - } - ] - }, - "argument-list": { - "begin": "\\(", - "beginCaptures": { - "0": { - "name": "punctuation.parenthesis.open.qsharp" - } - }, - "end": "\\)", - "endCaptures": { - "0": { - "name": "punctuation.parenthesis.close.qsharp" - } - }, - "patterns": [ - { - "include": "#argument" - }, - { - "include": "#punctuation-comma" - } - ] - }, - "parameter-list": { - "begin": "(\\()", - "beginCaptures": { - "0": { - "name": "punctuation.parenthesis.open.qsharp" - } - }, - "end": "(\\))", - "endCaptures": { - "0": { - "name": "punctuation.parenthesis.close.qsharp" - } - }, - "patterns": [ - { - "include": "#parameter" - }, - { - "include": "#punctuation-comma" - } - ] - }, - "punctuation-comma": { - "name": "punctuation.separator.comma.qsharp", - "match": "," - }, - "identifier": { - "patterns": [ - { - "name": "variable.other.readwrite.qsharp", - "match": "\\b[_[:alpha:]][_[:alnum:]]*\\b" - } - ] - }, - "argument": { - "patterns": [ - { - "include": "#expression" - } - ] - }, - "parameter": { - "begin": "([_[:alpha:]][_[:alnum:]]*)\\s*(:)", - "beginCaptures": { - "1": { - "name": "entity.name.variable.parameter.qsharp" - }, - "2": { - "name": "punctuation.separator.colon.qsharp" - } - }, - "end": "(?=(,|\\)|\\]))", - "patterns": [ - { - "include": "#literals" - }, - { - "include": "#types" - }, - { - "include": "#library" - }, - { - "include": "#expression-operators" - } - ] - }, - "type-array-suffix": { - "begin": "\\b\\[", - "beginCaptures": { - "0": { - "name": "punctuation.squarebracket.open.qsharp" - } - }, - "end": "\\]", - "endCaptures": { - "0": { - "name": "punctuation.squarebracket.close.qsharp" - } - }, - "patterns": [ - { - "include": "#punctuation-comma" - }, - { - "include": "#expression" - } - ] - }, - "udt-declaration": { - "begin": "(?=\\bnewtype\\b)", - "end": "(?<=\\)|;)", - "patterns": [ - { - "begin": "(?x)\n(newtype)\\b\\s+\n([_[:alpha:]][_[:alnum:]]*)", - "beginCaptures": { - "1": { - "name": "keyword.other.udt.qsharp" - }, - "2": { - "name": "entity.name.type.udt.qsharp" - } - }, - "end": "(?=\\s*=)" - }, - { - "begin": "(?:\\s*=\\s*)(\\()", - "beginCaptures": { - "1": { - "name": "punctuation.parenthesis.open.qsharp" - } - }, - "end": "\\)", - "endCaptures": { - "0": { - "name": "punctuation.parenthesis.close.qsharp" - } - }, - "patterns": [ - { - "include": "#literals" - }, - { - "include": "#punctuation-comma" - }, - { - "include": "#types" - }, - { - "include": "#library" - } - ] - }, - { - "begin": "(?:\\s*=\\s*)", - "end": "(?=;)", - "patterns": [ - { - "include": "#literals" - }, - { - "include": "#punctuation-comma" - }, - { - "include": "#types" - }, - { - "include": "#library" - } - ] - } - ] - }, - "struct-declaration": { - "begin": "(?x)\n\\b(struct)\\b\\s+\n([_[:alpha:]][_[:alnum:]]*)", - "beginCaptures": { - "1": { - "name": "keyword.other.struct.qsharp" - }, - "2": { - "name": "entity.name.type.struct.qsharp" - } - }, - "end": "(?<=\\})", - "patterns": [ - { - "include": "#comments" - }, - { - "begin": "\\{", - "beginCaptures": { - "0": { - "name": "punctuation.curlybrace.open.qsharp" - } - }, - "end": "\\}", - "endCaptures": { - "0": { - "name": "punctuation.curlybrace.close.qsharp" - } - }, - "patterns": [ - { - "include": "#comments" - }, - { - "include": "#struct-field" - }, - { - "include": "#punctuation-comma" - }, - { - "include": "#types" - }, - { - "include": "#library" - } - ] - } - ] - }, - "struct-field": { - "begin": "([_[:alpha:]][_[:alnum:]]*)\\s*(:)", - "beginCaptures": { - "1": { - "name": "variable.other.property.qsharp" - }, - "2": { - "name": "punctuation.separator.colon.qsharp" - } - }, - "end": "(?=(,|\\}))", - "patterns": [ - { - "include": "#type-parameter" - }, - { - "include": "#types" - }, - { - "include": "#library" - } - ] - }, - "new-expression": { - "begin": "(?x)\n\\b(new)\\b\\s+\n([_[:alpha:]][_[:alnum:]]*)\\s*\n(?=\\{)", - "beginCaptures": { - "1": { - "name": "keyword.other.new.qsharp" - }, - "2": { - "name": "entity.name.type.struct.qsharp" - } - }, - "end": "(?<=\\})", - "patterns": [ - { - "begin": "\\{", - "beginCaptures": { - "0": { - "name": "punctuation.curlybrace.open.qsharp" - } - }, - "end": "\\}", - "endCaptures": { - "0": { - "name": "punctuation.curlybrace.close.qsharp" - } - }, - "patterns": [ - { - "include": "#comments" - }, - { - "include": "#spread-operator" - }, - { - "include": "#field-initializer" - }, - { - "include": "#punctuation-comma" - }, - { - "include": "#expression" - } - ] - } - ] - }, - "field-initializer": { - "begin": "([_[:alpha:]][_[:alnum:]]*)\\s*(=)(?![=>])", - "beginCaptures": { - "1": { - "name": "variable.other.property.qsharp" - }, - "2": { - "name": "keyword.operator.assignment.qsharp" - } - }, - "end": "(?=(,|\\}))", - "patterns": [ - { - "include": "#expression" - } - ] - }, - "spread-operator": { - "name": "keyword.operator.spread.qsharp", - "match": "\\.\\.\\." - }, - "statements": { - "patterns": [ - { - "include": "#comments" - }, - { - "include": "#attributes" - }, - { - "include": "#import-export-directive" - }, - { - "include": "#open-directive" - }, - { - "include": "#new-expression" - }, - { - "include": "#struct-declaration" - }, - { - "include": "#member-access" - }, - { - "include": "#tuple-binding" - }, - { - "include": "#keywords" - }, - { - "include": "#library-invocation" - }, - { - "include": "#library" - }, - { - "include": "#operations" - }, - { - "include": "#types" - }, - { - "include": "#literals" - }, - { - "include": "#strings" - }, - { - "include": "#callable-invocation" - }, - { - "include": "#callable-declaration" - }, - { - "include": "#udt-declaration" - }, - { - "include": "#array-creation-expression" - }, - { - "include": "#local-declaration" - }, - { - "include": "#array-assignment" - }, - { - "include": "#local-assignment" - }, - { - "include": "#quantum-declaration" - }, - { - "include": "#if-statement" - }, - { - "include": "#parenthesized-expression" - }, - { - "include": "#expression-operators" - }, - { - "include": "#declaration-keywords" - }, - { - "include": "#identifier" - } - ] - }, - "expression": { - "patterns": [ - { - "include": "#comments" - }, - { - "include": "#if-statement" - }, - { - "include": "#new-expression" - }, - { - "include": "#strings" - }, - { - "include": "#member-access" - }, - { - "include": "#library-invocation" - }, - { - "include": "#callable-invocation" - }, - { - "include": "#library" - }, - { - "include": "#types" - }, - { - "include": "#literals" - }, - { - "include": "#parenthesized-expression" - }, - { - "include": "#array-creation-expression" - }, - { - "include": "#expression-operators" - }, - { - "include": "#identifier" - } - ] - }, - "member-access": { - "match": "(?x)\n(\\.)\\s*\n([_[:alpha:]][_[:alnum:]]*)\\b\n(?!\\s*\\()", - "captures": { - "1": { - "name": "punctuation.accessor.qsharp" - }, - "2": { - "name": "variable.other.property.qsharp" - } - } - }, - "attributes": { - "patterns": [ - { - "begin": "(@)([_[:alpha:]][_[:alnum:]]*)\\s*(?=\\()", - "beginCaptures": { - "1": { - "name": "punctuation.definition.attribute.qsharp" - }, - "2": { - "name": "entity.name.function.attribute.qsharp" - } - }, - "end": "(?<=\\))", - "patterns": [ - { - "include": "#argument-list" - } - ] - }, - { - "match": "(@)([_[:alpha:]][_[:alnum:]]*)", - "captures": { - "1": { - "name": "punctuation.definition.attribute.qsharp" - }, - "2": { - "name": "entity.name.function.attribute.qsharp" - } - } - } - ] - }, - "import-export-directive": { - "begin": "\\b(import|export)\\b", - "beginCaptures": { - "1": { - "name": "keyword.other.import.qsharp" - } - }, - "end": "(?=;)|$", - "patterns": [ - { - "begin": "\\b(as)\\b\\s*", - "beginCaptures": { - "1": { - "name": "keyword.other.qsharp" - } - }, - "end": "(?=(,|;)|$)", - "patterns": [ - { - "name": "entity.name.type.alias.qsharp", - "match": "[_[:alpha:]][_[:alnum:]]*" - } - ] - }, - { - "name": "keyword.operator.wildcard.qsharp", - "match": "\\*" - }, - { - "name": "entity.name.namespace.qsharp", - "match": "[_[:alpha:]][_[:alnum:]]*" - }, - { - "include": "#punctuation-accessor" - }, - { - "include": "#punctuation-comma" - } - ] - }, - "boolean-literal": { - "patterns": [ - { - "name": "constant.language.boolean.true.qsharp", - "match": "(?[_[:alpha:]][_[:alnum:]]*)", - "beginCaptures": { - "1": { - "name": "keyword.other.alias.qsharp" - }, - "2": { - "name": "entity.name.type.alias.qsharp" - } - }, - "end": "(?=;)" - }, - { - "name": "entity.name.type.namespace.qsharp", - "match": "[_[:alpha:]][_[:alnum:]]*" - }, - { - "include": "#punctuation-accessor" - } - ] - } - ] - }, - "numeric-literal": { - "patterns": [ - { - "name": "constant.numeric.hexadecimal.qsharp", - "match": "\\b0[xX][0-9a-fA-F][0-9a-fA-F_]*[lL]?\\b" - }, - { - "name": "constant.numeric.binary.qsharp", - "match": "\\b0[bB][01][01_]*[lL]?\\b" - }, - { - "name": "constant.numeric.octal.qsharp", - "match": "\\b0[oO][0-7][0-7_]*[lL]?\\b" - }, - { - "name": "constant.numeric.decimal.qsharp", - "match": "(?x)\n\\b\\d[\\d_]* \\. \\d[\\d_]* (?:[eE][+-]?\\d+)? # 1.0 3.14 1.0e-3\n| \\b\\d[\\d_]* [eE][+-]?\\d+ # 1e10\n| \\b\\d[\\d_]* [lL]? # 42 42L 1_000" - } - ] - }, - "array-creation-expression": { - "begin": "(?)", - "beginCaptures": { - "1": { - "name": "keyword.operator.assignment.increment.qsharp" - }, - "2": { - "name": "keyword.operator.assignment.decrement.qsharp" - }, - "3": { - "name": "keyword.operator.assignment.qsharp" - } - }, - "end": "(?=[,\\)\\];}])", - "patterns": [ - { - "include": "#expression" - } - ] - }, - "if-statement": { - "begin": "(?|=>)" - }, - { - "name": "keyword.operator.assignment.compound.qsharp", - "match": "(\\+=|-=|\\*=|/=|%=|\\^=|&&&=|\\|\\|\\|=|\\^\\^\\^=|<<<=|>>>=|\\bw/=)" - }, - { - "name": "keyword.operator.copy-update.qsharp", - "match": "(\\bw/|<-)" - }, - { - "name": "keyword.operator.assignment.qsharp", - "match": "(?!+\\-*/%^&|~])=(?![=>])" - }, - { - "name": "keyword.operator.range.qsharp", - "match": "(\\.\\.\\.|\\.\\.)" - }, - { - "name": "keyword.operator.bitwise.qsharp", - "match": "(&&&|\\|\\|\\||\\^\\^\\^|~~~|<<<|>>>)" - }, - { - "name": "keyword.operator.comparison.qsharp", - "match": "(==|!=|<=|>=|<|>)" - }, - { - "name": "keyword.operator.arithmetic.qsharp", - "match": "(\\+|\\-|\\*|/|%|\\^)" - }, - { - "name": "keyword.operator.ternary.qsharp", - "match": "(\\?|\\|)" - } - ] - }, - "quantum-declaration": { - "begin": "(?x)\n(?:\\b(?:(use)|(borrow))\\b\\s*)\n([_[:alpha:]][_[:alnum:]]*)\\b\\s*\n(?=;|=|\\))", - "beginCaptures": { - "1": { - "name": "keyword.other.use.qsharp" - }, - "2": { - "name": "keyword.other.borrow.qsharp" - }, - "3": { - "name": "entity.name.variable.local.qsharp" - } - }, - "end": "(?=;|\\))", - "patterns": [ - { - "include": "#quantum-initializer" - } - ] - }, - "quantum-initializer": { - "begin": "(?)", - "beginCaptures": { - "1": { - "name": "keyword.operator.assignment.qsharp" - } - }, - "end": "(?=[,\\)\\];}])", - "patterns": [ - { - "include": "#expression" - } - ] - } - } + "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", + "name": "qsharp", + "scopeName": "source.qsharp", + "fileTypes": ["qs"], + "patterns": [ + { "include": "#comments" }, + { "include": "#attributes" }, + { "include": "#namespace-declaration" }, + { "include": "#import-export-directive" }, + { "include": "#new-expression" }, + { "include": "#struct-declaration" }, + { "include": "#member-access" }, + { "include": "#tuple-binding" }, + { "include": "#keywords" }, + { "include": "#library-invocation" }, + { "include": "#library" }, + { "include": "#operations" }, + { "include": "#types" }, + { "include": "#literals" }, + { "include": "#strings" }, + { "include": "#callable-invocation" }, + { "include": "#callable-declaration" }, + { "include": "#udt-declaration" }, + { "include": "#array-creation-expression" }, + { "include": "#local-declaration" }, + { "include": "#array-assignment" }, + { "include": "#local-assignment" }, + { "include": "#quantum-declaration" }, + { "include": "#if-statement" }, + { "include": "#parenthesized-expression" }, + { "include": "#expression-operators" }, + { "include": "#declaration-keywords" }, + { "include": "#identifier" } + ], + "repository": { + "literals": { + "patterns": [ + { "include": "#boolean-literal" }, + { "include": "#result-literal" }, + { "include": "#pauli-literal" }, + { "include": "#numeric-literal" } + ] + }, + "comments": { + "patterns": [ + { + "begin": "(^\\s+)?(?=//)", + "beginCaptures": { + "1": { "name": "punctuation.whitespace.comment.leading.qsharp" } + }, + "end": "(?=$)", + "patterns": [ + { + "name": "comment.block.documentation.qsharp", + "begin": "(?\\s*<([^<>]|\\g)+>\\s*)?\\s* # type arguments\n(?=\\() # open parentheses of argument list", + "beginCaptures": { + "1": { "name": "punctuation.accessor.qsharp" }, + "2": { "name": "entity.name.function.qsharp" }, + "3": { "patterns": [{ "include": "#type-parameter-list" }] } + }, + "end": "(?<=\\))", + "patterns": [{ "include": "#argument-list" }] + }, + "callable-declaration": { + "begin": "(?x)\n\\b(operation|function)\\b\\s+\n([_[:alpha:]][_[:alnum:]]*)\\s* # callable name\n(?\\s*<([^<>]|\\g)+>\\s*)?\\s* # type arguments\n(?=\\() # open parentheses of argument list", + "beginCaptures": { + "1": { "name": "keyword.other.callable.qsharp" }, + "2": { "name": "entity.name.function.qsharp" }, + "3": { "patterns": [{ "include": "#type-parameter-list" }] } + }, + "end": "(?<=\\))", + "patterns": [{ "include": "#parameter-list" }] + }, + "type-parameter-list": { + "begin": "\\<", + "beginCaptures": { + "0": { "name": "punctuation.definition.typeparameters.begin.qsharp" } + }, + "end": "\\>", + "endCaptures": { + "0": { "name": "punctuation.definition.typeparameters.end.qsharp" } + }, + "patterns": [ + { + "match": "('[_[:alpha:]][_[:alnum:]]*)\\b", + "captures": { + "1": { "name": "entity.name.type.type-parameter.qsharp" } + } + }, + { "name": "punctuation.separator.colon.qsharp", "match": ":" }, + { "name": "keyword.operator.qsharp", "match": "\\+" }, + { + "name": "support.type.constraint.qsharp", + "match": "\\b(Eq|Add|Sub|Mul|Div|Mod|Signed|Ord|Show|Integral|Iterable|Exp)\\b" + }, + { "name": "punctuation.squarebracket.open.qsharp", "match": "\\[" }, + { "name": "punctuation.squarebracket.close.qsharp", "match": "\\]" }, + { "include": "#punctuation-comma" } + ] + }, + "argument-list": { + "begin": "\\(", + "beginCaptures": { + "0": { "name": "punctuation.parenthesis.open.qsharp" } + }, + "end": "\\)", + "endCaptures": { + "0": { "name": "punctuation.parenthesis.close.qsharp" } + }, + "patterns": [ + { "include": "#argument" }, + { "include": "#punctuation-comma" } + ] + }, + "parameter-list": { + "begin": "(\\()", + "beginCaptures": { + "0": { "name": "punctuation.parenthesis.open.qsharp" } + }, + "end": "(\\))", + "endCaptures": { + "0": { "name": "punctuation.parenthesis.close.qsharp" } + }, + "patterns": [ + { "include": "#parameter" }, + { "include": "#punctuation-comma" } + ] + }, + "punctuation-comma": { + "name": "punctuation.separator.comma.qsharp", + "match": "," + }, + "identifier": { + "patterns": [ + { + "name": "variable.other.readwrite.qsharp", + "match": "\\b[_[:alpha:]][_[:alnum:]]*\\b" + } + ] + }, + "argument": { "patterns": [{ "include": "#expression" }] }, + "parameter": { + "begin": "([_[:alpha:]][_[:alnum:]]*)\\s*(:)", + "beginCaptures": { + "1": { "name": "entity.name.variable.parameter.qsharp" }, + "2": { "name": "punctuation.separator.colon.qsharp" } + }, + "end": "(?=(,|\\)|\\]))", + "patterns": [ + { "include": "#literals" }, + { "include": "#types" }, + { "include": "#library" }, + { "include": "#expression-operators" } + ] + }, + "type-array-suffix": { + "begin": "\\b\\[", + "beginCaptures": { + "0": { "name": "punctuation.squarebracket.open.qsharp" } + }, + "end": "\\]", + "endCaptures": { + "0": { "name": "punctuation.squarebracket.close.qsharp" } + }, + "patterns": [ + { "include": "#punctuation-comma" }, + { "include": "#expression" } + ] + }, + "udt-declaration": { + "begin": "(?=\\bnewtype\\b)", + "end": "(?<=\\)|;)", + "patterns": [ + { + "begin": "(?x)\n(newtype)\\b\\s+\n([_[:alpha:]][_[:alnum:]]*)", + "beginCaptures": { + "1": { "name": "keyword.other.udt.qsharp" }, + "2": { "name": "entity.name.type.udt.qsharp" } + }, + "end": "(?=\\s*=)" + }, + { + "begin": "(?:\\s*=\\s*)(\\()", + "beginCaptures": { + "1": { "name": "punctuation.parenthesis.open.qsharp" } + }, + "end": "\\)", + "endCaptures": { + "0": { "name": "punctuation.parenthesis.close.qsharp" } + }, + "patterns": [ + { "include": "#literals" }, + { "include": "#punctuation-comma" }, + { "include": "#types" }, + { "include": "#library" } + ] + }, + { + "begin": "(?:\\s*=\\s*)", + "end": "(?=;)", + "patterns": [ + { "include": "#literals" }, + { "include": "#punctuation-comma" }, + { "include": "#types" }, + { "include": "#library" } + ] + } + ] + }, + "struct-declaration": { + "begin": "(?x)\n\\b(struct)\\b\\s+\n([_[:alpha:]][_[:alnum:]]*)", + "beginCaptures": { + "1": { "name": "keyword.other.struct.qsharp" }, + "2": { "name": "entity.name.type.struct.qsharp" } + }, + "end": "(?<=\\})", + "patterns": [ + { "include": "#comments" }, + { + "begin": "\\{", + "beginCaptures": { + "0": { "name": "punctuation.curlybrace.open.qsharp" } + }, + "end": "\\}", + "endCaptures": { + "0": { "name": "punctuation.curlybrace.close.qsharp" } + }, + "patterns": [ + { "include": "#comments" }, + { "include": "#struct-field" }, + { "include": "#punctuation-comma" }, + { "include": "#types" }, + { "include": "#library" } + ] + } + ] + }, + "struct-field": { + "begin": "([_[:alpha:]][_[:alnum:]]*)\\s*(:)", + "beginCaptures": { + "1": { "name": "variable.other.property.qsharp" }, + "2": { "name": "punctuation.separator.colon.qsharp" } + }, + "end": "(?=(,|\\}))", + "patterns": [ + { "include": "#type-parameter" }, + { "include": "#types" }, + { "include": "#library" } + ] + }, + "new-expression": { + "begin": "(?x)\n\\b(new)\\b\\s+\n([_[:alpha:]][_[:alnum:]]*)\\s*\n(?=\\{)", + "beginCaptures": { + "1": { "name": "keyword.other.new.qsharp" }, + "2": { "name": "entity.name.type.struct.qsharp" } + }, + "end": "(?<=\\})", + "patterns": [ + { + "begin": "\\{", + "beginCaptures": { + "0": { "name": "punctuation.curlybrace.open.qsharp" } + }, + "end": "\\}", + "endCaptures": { + "0": { "name": "punctuation.curlybrace.close.qsharp" } + }, + "patterns": [ + { "include": "#comments" }, + { "include": "#spread-operator" }, + { "include": "#field-initializer" }, + { "include": "#punctuation-comma" }, + { "include": "#expression" } + ] + } + ] + }, + "field-initializer": { + "begin": "([_[:alpha:]][_[:alnum:]]*)\\s*(=)(?![=>])", + "beginCaptures": { + "1": { "name": "variable.other.property.qsharp" }, + "2": { "name": "keyword.operator.assignment.qsharp" } + }, + "end": "(?=(,|\\}))", + "patterns": [{ "include": "#expression" }] + }, + "spread-operator": { + "name": "keyword.operator.spread.qsharp", + "match": "\\.\\.\\." + }, + "statements": { + "patterns": [ + { "include": "#comments" }, + { "include": "#attributes" }, + { "include": "#import-export-directive" }, + { "include": "#open-directive" }, + { "include": "#new-expression" }, + { "include": "#struct-declaration" }, + { "include": "#member-access" }, + { "include": "#tuple-binding" }, + { "include": "#keywords" }, + { "include": "#library-invocation" }, + { "include": "#library" }, + { "include": "#operations" }, + { "include": "#types" }, + { "include": "#literals" }, + { "include": "#strings" }, + { "include": "#callable-invocation" }, + { "include": "#callable-declaration" }, + { "include": "#udt-declaration" }, + { "include": "#array-creation-expression" }, + { "include": "#local-declaration" }, + { "include": "#array-assignment" }, + { "include": "#local-assignment" }, + { "include": "#quantum-declaration" }, + { "include": "#if-statement" }, + { "include": "#parenthesized-expression" }, + { "include": "#expression-operators" }, + { "include": "#declaration-keywords" }, + { "include": "#identifier" } + ] + }, + "expression": { + "patterns": [ + { "include": "#comments" }, + { "include": "#if-statement" }, + { "include": "#new-expression" }, + { "include": "#strings" }, + { "include": "#member-access" }, + { "include": "#library-invocation" }, + { "include": "#callable-invocation" }, + { "include": "#library" }, + { "include": "#types" }, + { "include": "#literals" }, + { "include": "#parenthesized-expression" }, + { "include": "#array-creation-expression" }, + { "include": "#expression-operators" }, + { "include": "#identifier" } + ] + }, + "member-access": { + "match": "(?x)\n(\\.)\\s*\n([_[:alpha:]][_[:alnum:]]*)\\b\n(?!\\s*\\()", + "captures": { + "1": { "name": "punctuation.accessor.qsharp" }, + "2": { "name": "variable.other.property.qsharp" } + } + }, + "attributes": { + "patterns": [ + { + "begin": "(@)([_[:alpha:]][_[:alnum:]]*)\\s*(?=\\()", + "beginCaptures": { + "1": { "name": "punctuation.definition.attribute.qsharp" }, + "2": { "name": "entity.name.function.attribute.qsharp" } + }, + "end": "(?<=\\))", + "patterns": [{ "include": "#argument-list" }] + }, + { + "match": "(@)([_[:alpha:]][_[:alnum:]]*)", + "captures": { + "1": { "name": "punctuation.definition.attribute.qsharp" }, + "2": { "name": "entity.name.function.attribute.qsharp" } + } + } + ] + }, + "import-export-directive": { + "begin": "\\b(import|export)\\b", + "beginCaptures": { "1": { "name": "keyword.other.import.qsharp" } }, + "end": "(?=;)|$", + "patterns": [ + { + "begin": "\\b(as)\\b\\s*", + "beginCaptures": { "1": { "name": "keyword.other.qsharp" } }, + "end": "(?=(,|;)|$)", + "patterns": [ + { + "name": "entity.name.type.alias.qsharp", + "match": "[_[:alpha:]][_[:alnum:]]*" + } + ] + }, + { "name": "keyword.operator.wildcard.qsharp", "match": "\\*" }, + { + "name": "entity.name.namespace.qsharp", + "match": "[_[:alpha:]][_[:alnum:]]*" + }, + { "include": "#punctuation-accessor" }, + { "include": "#punctuation-comma" } + ] + }, + "boolean-literal": { + "patterns": [ + { + "name": "constant.language.boolean.true.qsharp", + "match": "(?[_[:alpha:]][_[:alnum:]]*)", + "beginCaptures": { + "1": { "name": "keyword.other.alias.qsharp" }, + "2": { "name": "entity.name.type.alias.qsharp" } + }, + "end": "(?=;)" + }, + { + "name": "entity.name.type.namespace.qsharp", + "match": "[_[:alpha:]][_[:alnum:]]*" + }, + { "include": "#punctuation-accessor" } + ] + } + ] + }, + "numeric-literal": { + "patterns": [ + { + "name": "constant.numeric.hexadecimal.qsharp", + "match": "\\b0[xX][0-9a-fA-F][0-9a-fA-F_]*[lL]?\\b" + }, + { + "name": "constant.numeric.binary.qsharp", + "match": "\\b0[bB][01][01_]*[lL]?\\b" + }, + { + "name": "constant.numeric.octal.qsharp", + "match": "\\b0[oO][0-7][0-7_]*[lL]?\\b" + }, + { + "name": "constant.numeric.decimal.qsharp", + "match": "(?x)\n\\b\\d[\\d_]* \\. \\d[\\d_]* (?:[eE][+-]?\\d+)? # 1.0 3.14 1.0e-3\n| \\b\\d[\\d_]* [eE][+-]?\\d+ # 1e10\n| \\b\\d[\\d_]* [lL]? # 42 42L 1_000" + } + ] + }, + "array-creation-expression": { + "begin": "(?)", + "beginCaptures": { + "1": { "name": "keyword.operator.assignment.increment.qsharp" }, + "2": { "name": "keyword.operator.assignment.decrement.qsharp" }, + "3": { "name": "keyword.operator.assignment.qsharp" } + }, + "end": "(?=[,\\)\\];}])", + "patterns": [{ "include": "#expression" }] + }, + "if-statement": { + "begin": "(?|=>)" }, + { + "name": "keyword.operator.assignment.compound.qsharp", + "match": "(\\+=|-=|\\*=|/=|%=|\\^=|&&&=|\\|\\|\\|=|\\^\\^\\^=|<<<=|>>>=|\\bw/=)" + }, + { + "name": "keyword.operator.copy-update.qsharp", + "match": "(\\bw/|<-)" + }, + { + "name": "keyword.operator.assignment.qsharp", + "match": "(?!+\\-*/%^&|~])=(?![=>])" + }, + { + "name": "keyword.operator.range.qsharp", + "match": "(\\.\\.\\.|\\.\\.)" + }, + { + "name": "keyword.operator.bitwise.qsharp", + "match": "(&&&|\\|\\|\\||\\^\\^\\^|~~~|<<<|>>>)" + }, + { + "name": "keyword.operator.comparison.qsharp", + "match": "(==|!=|<=|>=|<|>)" + }, + { + "name": "keyword.operator.arithmetic.qsharp", + "match": "(\\+|\\-|\\*|/|%|\\^)" + }, + { "name": "keyword.operator.ternary.qsharp", "match": "(\\?|\\|)" } + ] + }, + "quantum-declaration": { + "begin": "(?x)\n(?:\\b(?:(use)|(borrow))\\b\\s*)\n([_[:alpha:]][_[:alnum:]]*)\\b\\s*\n(?=;|=|\\))", + "beginCaptures": { + "1": { "name": "keyword.other.use.qsharp" }, + "2": { "name": "keyword.other.borrow.qsharp" }, + "3": { "name": "entity.name.variable.local.qsharp" } + }, + "end": "(?=;|\\))", + "patterns": [{ "include": "#quantum-initializer" }] + }, + "quantum-initializer": { + "begin": "(?)", + "beginCaptures": { + "1": { "name": "keyword.operator.assignment.qsharp" } + }, + "end": "(?=[,\\)\\];}])", + "patterns": [{ "include": "#expression" }] + } + } } diff --git a/package-lock.json b/package-lock.json index 1c5002c..d4b6692 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ "js-yaml": "^4.1.0", "mocha": "^10.8.2", "plist": "^3.1.0", + "prettier": "^3.9.5", "ts-node": "^10.9.2", "typescript": "^5.6.3", "vscode-oniguruma": "^2.0.1", @@ -120,7 +121,6 @@ "integrity": "sha512-EANqOCF9QFyra+4pfxUcX9STKJpCLjMbObVzljIJomAWSnuSIEAvyzEU53GaajbXJEgdh0iEcPL+DGvpUd4k1Q==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "undici-types": "~6.21.0" } @@ -1003,6 +1003,22 @@ "node": ">=10.4.0" } }, + "node_modules/prettier": { + "version": "3.9.5", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.9.5.tgz", + "integrity": "sha512-/FVl766LpUfB5vXgCYOYa0MeV/441Ia99AeICQIQFTY/Nw0roZwULcXpku5i1/m5kt/baz+s4Zogspd839HSMg==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", @@ -1207,7 +1223,6 @@ "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "dev": true, "license": "Apache-2.0", - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/package.json b/package.json index 70c6e63..d7ced18 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "js-yaml": "^4.1.0", "mocha": "^10.8.2", "plist": "^3.1.0", + "prettier": "^3.9.5", "ts-node": "^10.9.2", "typescript": "^5.6.3", "vscode-oniguruma": "^2.0.1",