PowerShell grammar for tree-sitter
Project description
tree-sitter-pwsh
PowerShell grammar for tree-sitter.
Parses .ps1 and .psm1 files into a concrete syntax tree for syntax highlighting, code navigation, and analysis.
Features
- Pipelines and commands — pipes
|, chain operators&&||, redirections>>>2>&1, invocation&., splatting@params - Directives —
using namespace,using module(including hashtable specs),using assembly,using static, and top-of-file#Requires - Strings and interpolation — expandable strings
"$var $(expr)", verbatim strings, here-strings@"/@', and PowerShell-style escaping - Functions and named blocks —
function,filter,workflowwithparam()blocks, attributes, validation, andbegin/process/end/clean - Control flow —
if/elseif/else,switch(-Regex,-Wildcard,-Exact,-CaseSensitive),foreach,for,while,do/while/until - Error handling —
try/catch/finallywith typed catch clauses,trap,throw,break,continue,return,exit - Expressions — ternary
? :, null-coalescing??/??=, comparison/string/type/containment operators,-fformat, range.. - Types — common .NET type forms including generics
[Dictionary[string, int]], arrays[int[]], nested typesArray+Enumerator, and backtick arityDictionary`2 - Variables —
$var,$scope:var,${braced}with backtick escapes,@splatted, and special vars$$$^$?$_ - Classes and enums — properties, methods, constructors with
: base()/: this()chaining,hidden/staticattributes, and inheritance clauses - Numbers — decimal, hex
0x, scientific1.5e10, numeric suffixes (u,ul,s,us,y,uy,n,l,d), and size multipliers (kb/mb/gb/tb/pb) - Case-insensitive keywords and operators — parses PowerShell casing variations without normalization
Example
using namespace System.IO
function Get-FileSize {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]$Path
)
begin { $total = 0 }
process {
$size = (Get-Item $Path).Length
$total += $size
}
end { $total }
clean { Remove-Variable total }
}
$result = Get-FileSize -Path ".\README.md"
$message = $result -gt 1kb ? "Large file" : "Small file"
Write-Host $message
Parsed tree:
(program
(using_directive_list
(using_statement (type_name (type_name (type_identifier)) (type_identifier))))
(statement_list
(function_statement
(function_name)
(script_block
(param_block
(attribute_list
(attribute (attribute_name (type_spec (type_name (type_identifier))))))
(parameter_list
(script_parameter
(attribute_list
(attribute (attribute_name (type_spec (type_name (type_identifier))))))
(variable))))
(script_block_body
(named_block_list
(named_block (block_name) (statement_block ...))
(named_block (block_name) (statement_block ...))
(named_block (block_name) (statement_block ...))
(named_block (block_name) (statement_block ...))))))
(pipeline
(assignment_expression ...))
(pipeline
(assignment_expression ...))
(pipeline
(pipeline_chain
(command (command_name) (command_elements ...))))))
Installation
npm
npm install tree-sitter-pwsh
Cargo
cargo add tree-sitter-pwsh
PyPI
pip install tree-sitter-pwsh
Go
import tree_sitter_powershell "github.com/wharflab/tree-sitter-powershell/bindings/go"
The root package also exports the bundled queries/highlights.scm via go:embed:
import powershell "github.com/wharflab/tree-sitter-powershell"
lang := powershell.GetLanguage()
query, _ := powershell.GetHighlightsQuery()
Usage
Node.js
import Parser from "tree-sitter";
import PowerShell from "tree-sitter-pwsh";
const parser = new Parser();
parser.setLanguage(PowerShell);
const tree = parser.parse(`Get-Process | Where-Object { $_.CPU -gt 10 }\n`);
console.log(tree.rootNode.toString());
Rust
let mut parser = tree_sitter::Parser::new();
let language = tree_sitter_pwsh::LANGUAGE;
parser.set_language(&language.into()).unwrap();
let tree = parser.parse("Get-Process | Sort-Object CPU\n", None).unwrap();
println!("{}", tree.root_node().to_sexp());
Python
from tree_sitter import Language, Parser
import tree_sitter_pwsh
parser = Parser(Language(tree_sitter_pwsh.language()))
tree = parser.parse(b"Get-Process | Sort-Object CPU\n")
print(tree.root_node.sexp())
Syntax Highlighting
The grammar ships with a queries/highlights.scm file for use in editors that support tree-sitter highlighting (Neovim, Helix, Zed, etc.).
References
- PowerShell Language Specification
- PowerShell/EditorSyntax — used as a real-world parsing benchmark
- PowerShell/tree-sitter-PowerShell — archived PowerShell grammar repo; provided a significant part of the corpus coverage and the
TheBigTestFile.ps1benchmark target - Originally forked from airbus-cert/tree-sitter-powershell
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tree_sitter_pwsh-0.29.1.tar.gz.
File metadata
- Download URL: tree_sitter_pwsh-0.29.1.tar.gz
- Upload date:
- Size: 310.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44de4e5a25cffea0f656e85aa75c1f898bec19f9a1468852215fca1855415536
|
|
| MD5 |
170b7cfd623cf0aba0f02b539312d6d3
|
|
| BLAKE2b-256 |
abe1b6f73b976c08e127b3299741dc334e4167e5a3eadf691feb8b5814e67cae
|
Provenance
The following attestation bundles were made for tree_sitter_pwsh-0.29.1.tar.gz:
Publisher:
publish_pypi.yml on wharflab/tree-sitter-powershell
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_sitter_pwsh-0.29.1.tar.gz -
Subject digest:
44de4e5a25cffea0f656e85aa75c1f898bec19f9a1468852215fca1855415536 - Sigstore transparency entry: 1340307932
- Sigstore integration time:
-
Permalink:
wharflab/tree-sitter-powershell@e5af78e74b2361802d295687acd1321f43a5cd3e -
Branch / Tag:
refs/tags/v0.29.1 - Owner: https://github.com/wharflab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@e5af78e74b2361802d295687acd1321f43a5cd3e -
Trigger Event:
push
-
Statement type:
File details
Details for the file tree_sitter_pwsh-0.29.1-cp310-abi3-win_arm64.whl.
File metadata
- Download URL: tree_sitter_pwsh-0.29.1-cp310-abi3-win_arm64.whl
- Upload date:
- Size: 137.7 kB
- Tags: CPython 3.10+, Windows ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
925471a008116b22fd68b095e1929c0b5838ee10c1edc3bd800022803aacb93d
|
|
| MD5 |
f0893c9609cdc00c391cf22746cd6291
|
|
| BLAKE2b-256 |
8833a05c4866a9215bc9e2c62c2a8bbbad71a7417b88b4082dc8a6dbcd6cc479
|
Provenance
The following attestation bundles were made for tree_sitter_pwsh-0.29.1-cp310-abi3-win_arm64.whl:
Publisher:
publish_pypi.yml on wharflab/tree-sitter-powershell
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_sitter_pwsh-0.29.1-cp310-abi3-win_arm64.whl -
Subject digest:
925471a008116b22fd68b095e1929c0b5838ee10c1edc3bd800022803aacb93d - Sigstore transparency entry: 1340307971
- Sigstore integration time:
-
Permalink:
wharflab/tree-sitter-powershell@e5af78e74b2361802d295687acd1321f43a5cd3e -
Branch / Tag:
refs/tags/v0.29.1 - Owner: https://github.com/wharflab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@e5af78e74b2361802d295687acd1321f43a5cd3e -
Trigger Event:
push
-
Statement type:
File details
Details for the file tree_sitter_pwsh-0.29.1-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: tree_sitter_pwsh-0.29.1-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 143.0 kB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d199568e877626467c80da06c2dc735719f207c5d003b1269f07cd1328d81378
|
|
| MD5 |
0a1cb74def56c0f795ef0f8c57afa432
|
|
| BLAKE2b-256 |
7690be6c8644dbfdb6f4be34c49a3a7c2008f4e0e3239a3eb675e4885ba47415
|
Provenance
The following attestation bundles were made for tree_sitter_pwsh-0.29.1-cp310-abi3-win_amd64.whl:
Publisher:
publish_pypi.yml on wharflab/tree-sitter-powershell
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_sitter_pwsh-0.29.1-cp310-abi3-win_amd64.whl -
Subject digest:
d199568e877626467c80da06c2dc735719f207c5d003b1269f07cd1328d81378 - Sigstore transparency entry: 1340307951
- Sigstore integration time:
-
Permalink:
wharflab/tree-sitter-powershell@e5af78e74b2361802d295687acd1321f43a5cd3e -
Branch / Tag:
refs/tags/v0.29.1 - Owner: https://github.com/wharflab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@e5af78e74b2361802d295687acd1321f43a5cd3e -
Trigger Event:
push
-
Statement type:
File details
Details for the file tree_sitter_pwsh-0.29.1-cp310-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: tree_sitter_pwsh-0.29.1-cp310-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 159.5 kB
- Tags: CPython 3.10+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6808ab3d81a1e7690aef6ee21985c5e3fa12ff7b18f39f9234ce7456a6b2564d
|
|
| MD5 |
b5b9f8eede8bd9eafb339ddb2a9d9cb3
|
|
| BLAKE2b-256 |
e67e8fcd9b0395858c6e86976fc0d9eb4556a99369e167f03be001e920a33af8
|
Provenance
The following attestation bundles were made for tree_sitter_pwsh-0.29.1-cp310-abi3-musllinux_1_2_x86_64.whl:
Publisher:
publish_pypi.yml on wharflab/tree-sitter-powershell
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_sitter_pwsh-0.29.1-cp310-abi3-musllinux_1_2_x86_64.whl -
Subject digest:
6808ab3d81a1e7690aef6ee21985c5e3fa12ff7b18f39f9234ce7456a6b2564d - Sigstore transparency entry: 1340307935
- Sigstore integration time:
-
Permalink:
wharflab/tree-sitter-powershell@e5af78e74b2361802d295687acd1321f43a5cd3e -
Branch / Tag:
refs/tags/v0.29.1 - Owner: https://github.com/wharflab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@e5af78e74b2361802d295687acd1321f43a5cd3e -
Trigger Event:
push
-
Statement type:
File details
Details for the file tree_sitter_pwsh-0.29.1-cp310-abi3-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: tree_sitter_pwsh-0.29.1-cp310-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 156.5 kB
- Tags: CPython 3.10+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
febbf547d997f795019229afa6f637c381a76d4be01b7c4eb6ed258baae3d5a4
|
|
| MD5 |
a29a93d45b3958f61e48f99a5c75a234
|
|
| BLAKE2b-256 |
7b33ba458cc810a03f084af3dda3af3b605ab92f3ceefed05c2412a1604c91b0
|
Provenance
The following attestation bundles were made for tree_sitter_pwsh-0.29.1-cp310-abi3-musllinux_1_2_aarch64.whl:
Publisher:
publish_pypi.yml on wharflab/tree-sitter-powershell
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_sitter_pwsh-0.29.1-cp310-abi3-musllinux_1_2_aarch64.whl -
Subject digest:
febbf547d997f795019229afa6f637c381a76d4be01b7c4eb6ed258baae3d5a4 - Sigstore transparency entry: 1340307955
- Sigstore integration time:
-
Permalink:
wharflab/tree-sitter-powershell@e5af78e74b2361802d295687acd1321f43a5cd3e -
Branch / Tag:
refs/tags/v0.29.1 - Owner: https://github.com/wharflab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@e5af78e74b2361802d295687acd1321f43a5cd3e -
Trigger Event:
push
-
Statement type:
File details
Details for the file tree_sitter_pwsh-0.29.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.
File metadata
- Download URL: tree_sitter_pwsh-0.29.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 157.0 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ ARM64, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fea6555bd3471f81115dd2ce12468229ef01147ba3f457c9390a724b30641d3f
|
|
| MD5 |
4e8cecc832439d47c42ca44dad9bc060
|
|
| BLAKE2b-256 |
d2e815386fdb368601ffbd139cff67b6ebd0226aae256fd509ca071919f7fdb9
|
Provenance
The following attestation bundles were made for tree_sitter_pwsh-0.29.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl:
Publisher:
publish_pypi.yml on wharflab/tree-sitter-powershell
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_sitter_pwsh-0.29.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl -
Subject digest:
fea6555bd3471f81115dd2ce12468229ef01147ba3f457c9390a724b30641d3f - Sigstore transparency entry: 1340307979
- Sigstore integration time:
-
Permalink:
wharflab/tree-sitter-powershell@e5af78e74b2361802d295687acd1321f43a5cd3e -
Branch / Tag:
refs/tags/v0.29.1 - Owner: https://github.com/wharflab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@e5af78e74b2361802d295687acd1321f43a5cd3e -
Trigger Event:
push
-
Statement type:
File details
Details for the file tree_sitter_pwsh-0.29.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.
File metadata
- Download URL: tree_sitter_pwsh-0.29.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
- Upload date:
- Size: 161.1 kB
- Tags: CPython 3.10+, manylinux: glibc 2.28+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
121ab6ad7319387a8bc6f2c29f823021a3a20e7a4b1ed2bab007c379c5c7f855
|
|
| MD5 |
7f9555b1b2f89500e692ebc840c77f83
|
|
| BLAKE2b-256 |
1ff757c49ba449751afd0105262aa39a86e6a5c1a427ae213ecdcc3575efd44b
|
Provenance
The following attestation bundles were made for tree_sitter_pwsh-0.29.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:
Publisher:
publish_pypi.yml on wharflab/tree-sitter-powershell
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_sitter_pwsh-0.29.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl -
Subject digest:
121ab6ad7319387a8bc6f2c29f823021a3a20e7a4b1ed2bab007c379c5c7f855 - Sigstore transparency entry: 1340307945
- Sigstore integration time:
-
Permalink:
wharflab/tree-sitter-powershell@e5af78e74b2361802d295687acd1321f43a5cd3e -
Branch / Tag:
refs/tags/v0.29.1 - Owner: https://github.com/wharflab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@e5af78e74b2361802d295687acd1321f43a5cd3e -
Trigger Event:
push
-
Statement type:
File details
Details for the file tree_sitter_pwsh-0.29.1-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: tree_sitter_pwsh-0.29.1-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 148.8 kB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fa6813dec216a97044c977bd272c2c83bbdc7b02d211ad50498390cc86f531d
|
|
| MD5 |
a6b536ec08deb14dc2e62991bc203d9a
|
|
| BLAKE2b-256 |
b9c962a9290275481c7abbf8280914ebb3d8617973c9655210df0cc680d72be4
|
Provenance
The following attestation bundles were made for tree_sitter_pwsh-0.29.1-cp310-abi3-macosx_11_0_arm64.whl:
Publisher:
publish_pypi.yml on wharflab/tree-sitter-powershell
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_sitter_pwsh-0.29.1-cp310-abi3-macosx_11_0_arm64.whl -
Subject digest:
7fa6813dec216a97044c977bd272c2c83bbdc7b02d211ad50498390cc86f531d - Sigstore transparency entry: 1340307988
- Sigstore integration time:
-
Permalink:
wharflab/tree-sitter-powershell@e5af78e74b2361802d295687acd1321f43a5cd3e -
Branch / Tag:
refs/tags/v0.29.1 - Owner: https://github.com/wharflab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@e5af78e74b2361802d295687acd1321f43a5cd3e -
Trigger Event:
push
-
Statement type:
File details
Details for the file tree_sitter_pwsh-0.29.1-cp310-abi3-macosx_10_9_x86_64.whl.
File metadata
- Download URL: tree_sitter_pwsh-0.29.1-cp310-abi3-macosx_10_9_x86_64.whl
- Upload date:
- Size: 137.7 kB
- Tags: CPython 3.10+, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f712fc89d4608c3c2f1a83d97c0d176c5f534a4f06c2a0f547dd1dda5ecad363
|
|
| MD5 |
4db9b4b472f2c8ac2e20b3992d81a747
|
|
| BLAKE2b-256 |
b2db7f15e26b97ddf0de85e8fb24d5fa7f25ccd1ddf9835b3b9b1848175a10d9
|
Provenance
The following attestation bundles were made for tree_sitter_pwsh-0.29.1-cp310-abi3-macosx_10_9_x86_64.whl:
Publisher:
publish_pypi.yml on wharflab/tree-sitter-powershell
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tree_sitter_pwsh-0.29.1-cp310-abi3-macosx_10_9_x86_64.whl -
Subject digest:
f712fc89d4608c3c2f1a83d97c0d176c5f534a4f06c2a0f547dd1dda5ecad363 - Sigstore transparency entry: 1340307941
- Sigstore integration time:
-
Permalink:
wharflab/tree-sitter-powershell@e5af78e74b2361802d295687acd1321f43a5cd3e -
Branch / Tag:
refs/tags/v0.29.1 - Owner: https://github.com/wharflab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@e5af78e74b2361802d295687acd1321f43a5cd3e -
Trigger Event:
push
-
Statement type: