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.

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.1.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.1-cp310-abi3-win_arm64.whl (47.0 kB view details)

Uploaded CPython 3.10+Windows ARM64

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

Uploaded CPython 3.10+Windows x86-64

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

File metadata

  • Download URL: tree_sitter_qsharp-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 fa44715150a4608b84b80ba5db7122a3d652e1667acd35fc955f07397da7b604
MD5 7a62343ac6fc9c94757ba8a8a6a63403
BLAKE2b-256 4ef84021e9101a7f370e67cf843055895d1c00a9fe3bf4f207dc4503d5553df2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.1.1-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 0db7ddc666183471c7f2784126ed144744a37a8020b26e9240389c72a6ee6b5c
MD5 cea4130ffab3c0b777f3ad643b0fc6a1
BLAKE2b-256 76beed59381f71cb764e89adad81907ff136bce266b29040fbc177c1ddbba3fd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.1.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c54df8b346cff44fa7be2a2bd4e5ad0554c54c71f2f9e3181e54ca6110bb8bec
MD5 f190509a875dd051f060a419beaaf08c
BLAKE2b-256 b07daedb5dfbaf7ad036cbed8ab4f1923097e7841885ac1b151b6d92cb6f8f9d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.1.1-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fd401828521f9251770a51d8b84d7fe213081b8b9e6fa0f8de766e01c811e497
MD5 bcd7f008e135c9dae6c0a7c3b1d7b819
BLAKE2b-256 d007fd20263e73aa070022cef15bfca0bf33833101c791d2f55cb4747a797f93

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.1.1-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 5e7b93baa9f7bda48e697f98f3f4d2a0a89f23622b288a5fcc0351a1662231ef
MD5 373680ea971ca6574fc896b734eb4162
BLAKE2b-256 f30d6dc49218f988e6f56692b4703e3b91d04ea837d58290eccf8599d2cbcca3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.1.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f0912b7e3c1b5ffd1d98250b4a89e6c014b7397c70144f59cc922e5e9907ce34
MD5 90fd952652b7a61b06226ce5a3f8bcab
BLAKE2b-256 ba73be42d61a1c16a7f62b2724df1890decf2c65bd1d7d8d231747153cd831c4

See more details on using hashes here.

File details

Details for the file tree_sitter_qsharp-0.1.1-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.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 2930be5b4f67df41f4691fc3655a45331224b89fc73eefb9f8769f553ff8b439
MD5 cf4f3e0328d80b6fd43100f9f571fede
BLAKE2b-256 d04af339838f8361ce294c66772feaba307c72233f8e63f501996d7af534e919

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.1.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 33b2ca69d64393cd845997f88dc84fc5b5a15b1ca66aff64935f89e30a835e06
MD5 62104287b87bcb3a0c61016aeb329cf0
BLAKE2b-256 8c47da8f411389432ec1543be904f36d8ee669bd4d3be7fb4daa24c404340b8c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_qsharp-0.1.1-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 92aac844af46295950bacda3d933c0b0048b16d9aae53c2a7f30bbaa20c0d2f5
MD5 7cc1c9fa866bad8bf83102104aa899fc
BLAKE2b-256 d9007f30ee138314070b4ba6e142931779d4181b5a5c3070aba76dcfbb568354

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