Skip to content

Commit 04aedaa

Browse files
committed
modernize the infra and updated the syntax to the latest Q# 1.x
1 parent 857eefd commit 04aedaa

29 files changed

Lines changed: 3502 additions & 10468 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,6 @@ dist
103103
# TernJS port file
104104
.tern-port
105105
out/
106+
107+
# macOS
108+
.DS_Store

.mocharc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require": "ts-node/register",
3+
"spec": "test/**/*.tests.ts",
4+
"timeout": 10000
5+
}

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,32 @@ This repository contains the TextMate grammar for Q#. The grammar provides token
44

55
[![CoC](https://img.shields.io/badge/code%20of%20conduct-contributor%20covenant-yellow)](CODE_OF_CONDUCT.md)
66

7+
## Language coverage
8+
9+
The grammar tracks modern Q# (QDK 1.x) and covers, among other things:
10+
11+
* File-scoped namespaces, `import` / `export` directives (with `*` wildcards and `as` aliases), and the legacy `namespace { }` / `open` forms
12+
* `struct` declarations, `new` struct instantiation, copy-and-update (`...spread`) and member access (`point.X`)
13+
* Attributes (`@EntryPoint()`, `@Test()`, `@Config(...)`, ...)
14+
* Operation/function declarations with type parameters and class constraints (`<'T : Eq + Add>`, `Exp['T]`), plus the functors `is Adj + Ctl`
15+
* Lambdas (`->`, `=>`), partial application, ternary (`cond ? a | b`), and the full operator set (arithmetic, comparison, logical, bitwise `&&& ||| ^^^ ~~~ <<< >>>`, ranges `..`/`...`, copy-update `w/ ... <-`)
16+
* Numeric literals in decimal, hex (`0xFF`), binary (`0b1010`), octal (`0o52`), `BigInt` (`42L`), exponent (`1.0e-3`) and digit-separator (`1_000`) forms
17+
* Interpolated strings (`$"...{expr}..."`) with tokenized expression holes
18+
* Intrinsic quantum operations highlighted as quantum operations while still tokenizing their arguments
19+
20+
The behaviour is pinned by an extensive unit-test suite; the tests can additionally be run against a checkout of the official [`microsoft/qdk`](https://github.com/microsoft/qdk) samples by pointing the `QDK_SAMPLES` environment variable at its `samples/` directory.
21+
722
## Build and Development
823

924
To contribute, clone the repo and run (requires Node.js and `npm` to be installed on the dev machine)
1025

1126
* `npm install` to install all dependencies
12-
* Run `npm run compile` to build and run tests
13-
* Run `npm run test` to run only tests
27+
* Run `npm run build` to regenerate the grammar outputs from the YAML source
28+
* Run `npm test` to build the grammar and run the unit tests
1429

1530
The source grammar is located at `src/qsharp.tmLanguage.yml` and is the core file to be maintained.
31+
The build (`build.js`) converts it into the two output files below; the tests tokenize
32+
Q# snippets with `vscode-textmate` and assert on the resulting scopes.
1633

1734
## Output
1835

build.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Builds the Q# TextMate grammar outputs from the YAML source.
2+
//
3+
// src/qsharp.tmLanguage.yml -> grammars/qsharp.tmLanguage (plist)
4+
// -> grammars/qsharp.tmLanguage.json (JSON)
5+
//
6+
// The YAML file is the single source of truth and the only file that should be
7+
// edited by hand. Run with `npm run build`.
8+
9+
const fs = require("fs");
10+
const path = require("path");
11+
const jsYaml = require("js-yaml");
12+
const plist = require("plist");
13+
14+
const srcFile = path.join(__dirname, "src", "qsharp.tmLanguage.yml");
15+
const grammarsDir = path.join(__dirname, "grammars");
16+
17+
function build() {
18+
const text = fs.readFileSync(srcFile, "utf8");
19+
const grammar = jsYaml.load(text);
20+
21+
fs.mkdirSync(grammarsDir, { recursive: true });
22+
23+
fs.writeFileSync(
24+
path.join(grammarsDir, "qsharp.tmLanguage.json"),
25+
JSON.stringify(grammar, null, "\t") + "\n"
26+
);
27+
28+
fs.writeFileSync(
29+
path.join(grammarsDir, "qsharp.tmLanguage"),
30+
plist.build(grammar)
31+
);
32+
33+
console.log("Built grammars/qsharp.tmLanguage and grammars/qsharp.tmLanguage.json");
34+
}
35+
36+
build();

0 commit comments

Comments
 (0)