Skip to main content

Q# grammar for tree-sitter

Project description

tree-sitter-qsharp

A tree-sitter grammar for Q#, Microsoft's quantum programming language.

This is a new project, not affiliated with Microsoft or the tree-sitter organization. Feedback, bug reports, and contributions are welcome.

What it does

Parses Q# source files into a concrete syntax tree that editors can use for syntax highlighting, code folding, symbol navigation, and indentation.

Built by reading the Q# language reference and the Q# compiler source. Tested against Q# files in the microsoft/qsharp repository.

Supported constructs

  • Namespaces, imports, exports, open directives
  • Operations and functions with type parameters, functor clauses, specializations
  • Structs, newtypes, all builtin types
  • Full expression grammar with operator precedence per the official specification
  • Quantum-specific syntax: use/borrow, within/apply, repeat/until/fixup, Adjoint/Controlled
  • All literals: int, bigint, float, imaginary, string, interpolated string, bool, Result, Pauli
  • External scanner for float/range disambiguation (1. vs 0..5)

Known limitations

  • Explicit type arguments on calls (Foo<Int>(x)) are not supported due to </> ambiguity with comparison operators. Q# type inference handles this in practice.
  • Open-ended step ranges (...2...) parse but the AST does not perfectly represent all range component positions.
  • This is a v0.x project. There may be edge cases that are not yet covered.

Editor query files

Feature File
Syntax highlighting queries/highlights.scm
Code folding queries/folds.scm
Symbol outline queries/tags.scm
Auto-indentation queries/indents.scm
Scope tracking queries/locals.scm
Text objects queries/textobjects.scm

Capture names follow the nvim-treesitter conventions.

Contributing

If you find Q# code that doesn't parse correctly, please open an issue with the .qs file or a minimal reproducing snippet. Pull requests are welcome.

References

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tree_sitter_qsharp-0.1.2.tar.gz (125.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tree_sitter_qsharp-0.1.2-cp310-abi3-win_arm64.whl (46.8 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_qsharp-0.1.2-cp310-abi3-win_amd64.whl (48.4 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_qsharp-0.1.2-cp310-abi3-musllinux_1_2_x86_64.whl (64.5 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

tree_sitter_qsharp-0.1.2-cp310-abi3-musllinux_1_2_aarch64.whl (68.9 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_qsharp-0.1.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (69.9 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

tree_sitter_qsharp-0.1.2-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (64.6 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

tree_sitter_qsharp-0.1.2-cp310-abi3-macosx_11_0_arm64.whl (48.4 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_qsharp-0.1.2-cp310-abi3-macosx_10_9_x86_64.whl (45.9 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

Details for the file tree_sitter_qsharp-0.1.2.tar.gz.

File metadata

  • Download URL: tree_sitter_qsharp-0.1.2.tar.gz
  • Upload date:
  • Size: 125.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tree_sitter_qsharp-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3ba6c3acab7044c4c0391b800ddf3684c9b1605a31b0f82a14f5f47bb5686eb0
MD5 4c25d94c0a728a5927c0125647206f4a
BLAKE2b-256 5895291e60e4fe711385beacef35921ef5ed4bb70185ee0c1d04ac8ad52efb57

See more details on using hashes here.

File details

Details for the file tree_sitter_qsharp-0.1.2-cp310-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.1.2-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 c7d2daec12d6f39798ca97100806f467d79fb0a7b4ac7c4eb97d29883e04ce9e
MD5 b2788b8e34747da0675644632f27c7f3
BLAKE2b-256 96345f4ec46188ba0529ed41679578fcd11d054c23eaa495aba33e6965c87154

See more details on using hashes here.

File details

Details for the file tree_sitter_qsharp-0.1.2-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.1.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6a77dff4454a574b9e12735cf25efcc832c100b51878c74a1f4feaae4c6518d7
MD5 74c7062ef2e0b9e785e7fdfc85419a4f
BLAKE2b-256 5afa8243af0cacc869905cfb768b95376d0750ce9eb4e888c78ec3d2263350ec

See more details on using hashes here.

File details

Details for the file tree_sitter_qsharp-0.1.2-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.1.2-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e7cf3feb79c867792815deadae0b3b63c7e285d23e0cacc5dc93bdcb941db44d
MD5 78e157d3fdfe5a5db418a67bfe7b822e
BLAKE2b-256 fae0b65536b7ac0d719e928cc9efebb9287b43d46ef0ed7cc3375574b7916b3b

See more details on using hashes here.

File details

Details for the file tree_sitter_qsharp-0.1.2-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.1.2-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 a5f0d30346ecd21180ba7eab210625c22de728c94ecfffc34333642fb832f5e2
MD5 c8fc61b7a938967e4394462f7351f7f6
BLAKE2b-256 266530d86592ec64b40f6cd7a0b27bfb02432d87524e6085135a29f6a755b1a5

See more details on using hashes here.

File details

Details for the file tree_sitter_qsharp-0.1.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.1.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 af624b0fe12f4f6c8daa2d07ac27ef29e59963de8fb89fa6507c4d52570faa1e
MD5 8c7596dc8acd64c92cffc748770566dc
BLAKE2b-256 2fe5c5e94a055d3c976ef078300689bdd51bb4978c5fd135dfe70c1e98e6e251

See more details on using hashes here.

File details

Details for the file tree_sitter_qsharp-0.1.2-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.1.2-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 fcc31c559587c55663d03b57206a3942c29bf5c98e434d44cc7ece30bc612fae
MD5 2be98de34ada2958742b6b22e095d255
BLAKE2b-256 4e6d3b879ae4270211d6375318528e538b345ae6ca91a5479d23aae1a98be43f

See more details on using hashes here.

File details

Details for the file tree_sitter_qsharp-0.1.2-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.1.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4da5c2a5b3a713b8c3eac9e5cfeb0677d7858dfa3d64b2a0b6a24112f227a2e2
MD5 71bc5ff1cb8ece9d603a09a1048ea755
BLAKE2b-256 55a5f3f171886310ca96bd99ece39b4c5cf67800a74bb589c99b60a1c9807892

See more details on using hashes here.

File details

Details for the file tree_sitter_qsharp-0.1.2-cp310-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.1.2-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ba7b57ea299a63c2efdfe940e6daec531fd47cdbe0789abe3271e3971cccf106
MD5 1a3bd9431e0495f89108744407e02208
BLAKE2b-256 7aec32eaf62bd2e372ad2ac24521f503eb8d2e538fdd540cd6bcd3ab9876d5ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page