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)): the current Q# compiler parses < only as the comparison operator, so it reads Foo<Int>(x) as a comparison chain rather than a type application — this grammar matches that behavior. The syntax appears in older Q# docs but is not accepted by the current compiler (verified by running it).
  • 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.2.0.tar.gz (125.5 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.2.0-cp310-abi3-win_arm64.whl (47.0 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_qsharp-0.2.0-cp310-abi3-win_amd64.whl (47.7 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_qsharp-0.2.0-cp310-abi3-musllinux_1_2_x86_64.whl (64.7 kB view details)

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

tree_sitter_qsharp-0.2.0-cp310-abi3-musllinux_1_2_aarch64.whl (69.1 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_qsharp-0.2.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (70.0 kB view details)

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

tree_sitter_qsharp-0.2.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (64.7 kB view details)

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

tree_sitter_qsharp-0.2.0-cp310-abi3-macosx_11_0_arm64.whl (48.5 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_qsharp-0.2.0-cp310-abi3-macosx_10_9_x86_64.whl (46.1 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: tree_sitter_qsharp-0.2.0.tar.gz
  • Upload date:
  • Size: 125.5 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.2.0.tar.gz
Algorithm Hash digest
SHA256 a2924612e3f20526110c9d502590d70eff0e0288475aefc7a98af1aca0d28ad5
MD5 f53f8f11a69f3b2d28a0ff823020dfd7
BLAKE2b-256 0c49681e73c69c3d6b80036824b3dde6ed856c4b126f598a2a4f6873997c8b19

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.2.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 e3e36a99ac226905c715952658d83aeae9662bbcd0520903ea5a4ba9ecd2a0b8
MD5 423addd6e8c1e66021073d381ab6ff19
BLAKE2b-256 878bc899b1ecc59d38f67d86838421935a39bbdbd8dac27da1e6fb655a9f556b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.2.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b3212314a0aed1d84d168067ca59b3e910319ce8c692df812ff790ba160b52f9
MD5 9630143af82c60e513fc4fc1fecfbb2c
BLAKE2b-256 1e613bee90f64f05f2104541d97671f76864b966e4f040f5e1a3c01ee2008572

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.2.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 eeb8110730c1f315c9c2eefb7540ad6c6e7fa211ee36db9758dac12b5c25e664
MD5 3abe282bff9c8b90caadc776612cc305
BLAKE2b-256 bfa8a0d2d976d3f21a9f0e17f2d973fd098ce77dae78c950292fe8bb40aa0211

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.2.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 2397544be7b28dd33b0420d562f7da726a02e397bb9fa6a916b8f7363a5df35b
MD5 025e53b18e195af6cbe72c3ec609f0d6
BLAKE2b-256 99ec96bd794d443ec1ab308321e969f545dcc115e91419aae169c66043c2a078

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.2.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 15ecbc4991b969b128b83b25e536c7e1b77d75585969f2d6a9fa4953e2a5d0f3
MD5 16a65ecedf0b5da7c68f42cbe53ba473
BLAKE2b-256 ed170ce9d6379938c890b8d86163c98e695a54a550ddeaad36cf703e0be3a280

See more details on using hashes here.

File details

Details for the file tree_sitter_qsharp-0.2.0-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.2.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 3a95738b9f51472f4dab6cea5f3d043b229da7edd2ae77961baaf8dfa3f6e920
MD5 8b1107c961a6d0da4b254615aa88c9c9
BLAKE2b-256 db652d9798325b4b3ab2af5a9d9bb79b70f3d69ddd23fbc8047b1919347d156e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ee6e87d008f8eda32b3ddb032ae32791d10e33865f41f0cd40e0fae848e84576
MD5 80c4b72c7684f6ab3d7278f103396634
BLAKE2b-256 c0f607e9bf05b2416c29e0b8bbae232b5116b6be2ef163f08079f1180dfe6ca3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.2.0-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7f0d6c0bfdce05ec563a47dcbd9645a6f3c5d5e7a3614ea43dad4d79eda8f0ae
MD5 32e993ddc5e7c499e1ac2db1bbb0c348
BLAKE2b-256 482377851b549894e249965fe405e27d487b3aeb5893c9998871b5f3e7435446

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