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 documentation and the Q# compiler source as reference. Tested against the 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 Q# 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.

Installation

npm install tree-sitter-qsharp    # Node.js
cargo add tree-sitter-qsharp      # Rust
pip install tree-sitter-qsharp    # Python

Or from source:

git clone https://github.com/bezpechno/tree-sitter-qsharp
cd tree-sitter-qsharp
tree-sitter generate

Development

tree-sitter generate    # regenerate parser
tree-sitter test        # run corpus tests
tree-sitter fuzz        # fuzz test
tree-sitter parse file.qs          # parse a file
tree-sitter highlight file.qs      # preview highlighting

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.0.tar.gz (125.6 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.0-cp310-abi3-win_arm64.whl (47.0 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_qsharp-0.1.0-cp310-abi3-win_amd64.whl (48.6 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_qsharp-0.1.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.1.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.1.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.1.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.1.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.1.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.1.0.tar.gz.

File metadata

  • Download URL: tree_sitter_qsharp-0.1.0.tar.gz
  • Upload date:
  • Size: 125.6 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.0.tar.gz
Algorithm Hash digest
SHA256 31d9d59698af058aa6a9159a12c0c7b572f45f27c2aa6bbe099825f6ff01d454
MD5 46111507fe262ed35d074ffaff227269
BLAKE2b-256 d6cc010081aeab26f0ea01cebca0cbcb4d9314f200b54a3dacae7583a0eaebf3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.1.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 0fb74c3a1ef99a6d47067fe50cdaac9f729b04cfddc05894a313964eb3c0f79e
MD5 10cb3742ccfc288302570caf0ca15d92
BLAKE2b-256 2f6c98fce3b63f2eeb2e31ce000556966b17b57c0af9025d10b1f4e06db9af98

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.1.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 14bb2a649df564d6b8423775d12e9cc6d21ff970fa969686767b789d3c51b4b7
MD5 977fb8e7373aecbdb2286fe702bcdf9c
BLAKE2b-256 565458f25d3def0902d66dcffa5a93712ea26f3c8f51be8dda6cd6635b9ab619

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4e18b13938e29592b0386b744cbc5ec99991ee03c242459d4b61e4839352bfb6
MD5 4c0875152f9ec6b99c848449c542425e
BLAKE2b-256 3a45679ce86f316059fb13529f079c70af4ae27edabc37b34cf2b99610e58375

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.1.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 3617e1e199639969144d35fa57aaea959649c2d9535910ba3c326f6b35adab0a
MD5 dfa0b184bfe7a3744ee057baa0316168
BLAKE2b-256 afe3a6eee80d258ba6bc17aa7b0e6770756db84ec3bab9582ca3a3aa7b296f7f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.1.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b5002850cf55ddaf9de89824896b18891f135e58d12cb613566daee201f3de18
MD5 dce6c43f68393846b779d304ab665d83
BLAKE2b-256 d160e67bc76a901b730c3cceecc764e5e18486f33721d93c6acc8d82805530e7

See more details on using hashes here.

File details

Details for the file tree_sitter_qsharp-0.1.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.1.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 582a8cd637f319548f144df400493caae7a2793c6dd61615dc12ff8345943765
MD5 62ab0da6b25f68e062780abe8a60d9db
BLAKE2b-256 5eb488a1f5187ce6db66ba09a2ecda7d5665e52274ba7cf05e7a72491ae0be92

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c5fcd7bcaf8390afa4c305c8739d80fa44062e13174e06364f59fba351f8c0fb
MD5 c2dd64a634ab64755ffc21d945c4d72e
BLAKE2b-256 c563e6f449e9942afaf8773c42e7af7a11fec95d333a3b8aa0dd7e7defa39524

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.1.0-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 de79276ea7950c3ffd805fd51847ed26a075138fed33ac6d892566db010bd790
MD5 c202be66262d4ca6bbb0269fe5ce9b13
BLAKE2b-256 a38f52915dd9e2452c86070e3991dfdb37efa016e37ae1b07bde52d2d1e0a9e9

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