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
- Control flow —
if/elseif/else,switch(-Regex, -Wildcard, -Exact, -CaseSensitive),foreach,for,while,do/while/until - Functions —
function,filter,workflowwithparam()blocks, attributes, validation, named blocks (begin/process/end/clean) - Classes & enums — properties, methods, constructors with
: base()/: this()chaining,hidden/staticattributes, inheritance - Error handling —
try/catch/finallywith typed catch clauses,trap,throw,break,continue,return,exit - Pipelines — pipes
|, chain operators&&||, redirections>>>2>&1, invocation&., splatting@params - Expressions — ternary
? :, null-coalescing??/??=, comparison/string/type/containment operators,-fformat, range.. - Types — full .NET type system: generics
[Dictionary[string, int]], arrays[int[]], nested typesArray+Enumerator, backtick-arityDictionary`2 - Strings — expandable
"$var $(expr)", verbatim'literal', here-strings@"/@', escape sequences - Numbers — decimal, hex
0x, scientific1.5e10, all suffixes (u,ul,s,us,y,uy,n,l,d), multipliers (kb/mb/gb/tb/pb) usingdirectives —using namespace,using module(with hashtable specs),using assembly,using static- Variables —
$var,$scope:var,${braced}(with backtick escapes),@splatted, special vars$$$^$?$_ - Case-insensitive — all keywords and operators match regardless of casing
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
- 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.28.0.tar.gz.
File metadata
- Download URL: tree_sitter_pwsh-0.28.0.tar.gz
- Upload date:
- Size: 249.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ea9580dbfb471daa64789cf5ea7c92510dd784e7d63308dac6c82dd035ffa6d
|
|
| MD5 |
2c037c75c15d68c3931d388ce665ad49
|
|
| BLAKE2b-256 |
8effcdcc80c46338f6b9bd140babdbfa9cdd2b6d6e06215f7a98a9626d4e3fac
|
Provenance
The following attestation bundles were made for tree_sitter_pwsh-0.28.0.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.28.0.tar.gz -
Subject digest:
8ea9580dbfb471daa64789cf5ea7c92510dd784e7d63308dac6c82dd035ffa6d - Sigstore transparency entry: 1317237129
- Sigstore integration time:
-
Permalink:
wharflab/tree-sitter-powershell@f42510473ee48892186e81cda208107ab87173c5 -
Branch / Tag:
refs/tags/v0.28.0 - Owner: https://github.com/wharflab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@f42510473ee48892186e81cda208107ab87173c5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tree_sitter_pwsh-0.28.0-cp310-abi3-win_arm64.whl.
File metadata
- Download URL: tree_sitter_pwsh-0.28.0-cp310-abi3-win_arm64.whl
- Upload date:
- Size: 121.8 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 |
6018c75e0a463e34ef482c2d122282c95630380c52d08e80ad696854b0a45d0d
|
|
| MD5 |
3a1fc565210ef2de5965128729a9b966
|
|
| BLAKE2b-256 |
552bf437705b8dc72143e08ac7254a84047e1928f450c84beef29daad9522e47
|
Provenance
The following attestation bundles were made for tree_sitter_pwsh-0.28.0-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.28.0-cp310-abi3-win_arm64.whl -
Subject digest:
6018c75e0a463e34ef482c2d122282c95630380c52d08e80ad696854b0a45d0d - Sigstore transparency entry: 1317237215
- Sigstore integration time:
-
Permalink:
wharflab/tree-sitter-powershell@f42510473ee48892186e81cda208107ab87173c5 -
Branch / Tag:
refs/tags/v0.28.0 - Owner: https://github.com/wharflab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@f42510473ee48892186e81cda208107ab87173c5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tree_sitter_pwsh-0.28.0-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: tree_sitter_pwsh-0.28.0-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 127.7 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 |
2e54fd148e8c08706c80f2df03fd305e106990a90f7671df0afc01a5049457ab
|
|
| MD5 |
a1f3274d9a6ad3e0812189598b5d164d
|
|
| BLAKE2b-256 |
fc141977fb8541f99362c6200f29ec7be3832b8fe741531a655c4ba89f005047
|
Provenance
The following attestation bundles were made for tree_sitter_pwsh-0.28.0-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.28.0-cp310-abi3-win_amd64.whl -
Subject digest:
2e54fd148e8c08706c80f2df03fd305e106990a90f7671df0afc01a5049457ab - Sigstore transparency entry: 1317237249
- Sigstore integration time:
-
Permalink:
wharflab/tree-sitter-powershell@f42510473ee48892186e81cda208107ab87173c5 -
Branch / Tag:
refs/tags/v0.28.0 - Owner: https://github.com/wharflab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@f42510473ee48892186e81cda208107ab87173c5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tree_sitter_pwsh-0.28.0-cp310-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: tree_sitter_pwsh-0.28.0-cp310-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 143.4 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 |
c5057a3bae903b7133c2f1fa29507f124ff04cb518f75e877a97b74d893560ad
|
|
| MD5 |
8cbfd5ceb6bdc8e7c026f741bff9bb8d
|
|
| BLAKE2b-256 |
675805a74bdd7b7932ee37090156ebeeb5978fbc5d575be4af2049a2f5e49feb
|
Provenance
The following attestation bundles were made for tree_sitter_pwsh-0.28.0-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.28.0-cp310-abi3-musllinux_1_2_x86_64.whl -
Subject digest:
c5057a3bae903b7133c2f1fa29507f124ff04cb518f75e877a97b74d893560ad - Sigstore transparency entry: 1317237304
- Sigstore integration time:
-
Permalink:
wharflab/tree-sitter-powershell@f42510473ee48892186e81cda208107ab87173c5 -
Branch / Tag:
refs/tags/v0.28.0 - Owner: https://github.com/wharflab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@f42510473ee48892186e81cda208107ab87173c5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tree_sitter_pwsh-0.28.0-cp310-abi3-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: tree_sitter_pwsh-0.28.0-cp310-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 139.9 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 |
2eb542b64424286a7d8aaaa2026ddb20625912ff05a7bd692efce595ac92e44a
|
|
| MD5 |
05473bff27b14e3417e596095f9b96e3
|
|
| BLAKE2b-256 |
bee0faf8d2376b4cfac2c7fffd6be8916944778cd3596aefca0d0cac74488e61
|
Provenance
The following attestation bundles were made for tree_sitter_pwsh-0.28.0-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.28.0-cp310-abi3-musllinux_1_2_aarch64.whl -
Subject digest:
2eb542b64424286a7d8aaaa2026ddb20625912ff05a7bd692efce595ac92e44a - Sigstore transparency entry: 1317237373
- Sigstore integration time:
-
Permalink:
wharflab/tree-sitter-powershell@f42510473ee48892186e81cda208107ab87173c5 -
Branch / Tag:
refs/tags/v0.28.0 - Owner: https://github.com/wharflab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@f42510473ee48892186e81cda208107ab87173c5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tree_sitter_pwsh-0.28.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.
File metadata
- Download URL: tree_sitter_pwsh-0.28.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 140.7 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 |
b5c4adcb5a0df4b9d918abe4f386bcc3a80b099bb992c16709001d7a4465ef7a
|
|
| MD5 |
0e8a4933f2804dece9b7c246f7c75e0c
|
|
| BLAKE2b-256 |
e1f6859caf7f3a8b01c69bc4f07bd4844c69ee66b630834d5b4f36b909bfc20c
|
Provenance
The following attestation bundles were made for tree_sitter_pwsh-0.28.0-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.28.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl -
Subject digest:
b5c4adcb5a0df4b9d918abe4f386bcc3a80b099bb992c16709001d7a4465ef7a - Sigstore transparency entry: 1317237156
- Sigstore integration time:
-
Permalink:
wharflab/tree-sitter-powershell@f42510473ee48892186e81cda208107ab87173c5 -
Branch / Tag:
refs/tags/v0.28.0 - Owner: https://github.com/wharflab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@f42510473ee48892186e81cda208107ab87173c5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tree_sitter_pwsh-0.28.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.
File metadata
- Download URL: tree_sitter_pwsh-0.28.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
- Upload date:
- Size: 144.6 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 |
592f69cdd5f666ca3483a33911ff585698a4eb6861d720dd674581db5cb17443
|
|
| MD5 |
cc6a26af239d5dc3f6e23313331b12b7
|
|
| BLAKE2b-256 |
0669fc20c46ef581a2d7b10e5bb61cbd7095f446f18d2d94af0967dca73bbdfe
|
Provenance
The following attestation bundles were made for tree_sitter_pwsh-0.28.0-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.28.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl -
Subject digest:
592f69cdd5f666ca3483a33911ff585698a4eb6861d720dd674581db5cb17443 - Sigstore transparency entry: 1317237272
- Sigstore integration time:
-
Permalink:
wharflab/tree-sitter-powershell@f42510473ee48892186e81cda208107ab87173c5 -
Branch / Tag:
refs/tags/v0.28.0 - Owner: https://github.com/wharflab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@f42510473ee48892186e81cda208107ab87173c5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tree_sitter_pwsh-0.28.0-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: tree_sitter_pwsh-0.28.0-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 130.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 |
c84bb4f211a7b0efaaf12c8a33c27c3c9f2b1d13262dbd797a27cd1ec07e441f
|
|
| MD5 |
63c28d07ecc92b5128228f145d464cc5
|
|
| BLAKE2b-256 |
667f24ccbd15bd187a90cfac75d81b4fa64b82505ad344e4d6b574017d3f8efa
|
Provenance
The following attestation bundles were made for tree_sitter_pwsh-0.28.0-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.28.0-cp310-abi3-macosx_11_0_arm64.whl -
Subject digest:
c84bb4f211a7b0efaaf12c8a33c27c3c9f2b1d13262dbd797a27cd1ec07e441f - Sigstore transparency entry: 1317237179
- Sigstore integration time:
-
Permalink:
wharflab/tree-sitter-powershell@f42510473ee48892186e81cda208107ab87173c5 -
Branch / Tag:
refs/tags/v0.28.0 - Owner: https://github.com/wharflab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@f42510473ee48892186e81cda208107ab87173c5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tree_sitter_pwsh-0.28.0-cp310-abi3-macosx_10_9_x86_64.whl.
File metadata
- Download URL: tree_sitter_pwsh-0.28.0-cp310-abi3-macosx_10_9_x86_64.whl
- Upload date:
- Size: 122.2 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 |
6cf0fa334e97582a4cc9c20cca4087cda848bc8b66178a60dbf535d902b2ef1c
|
|
| MD5 |
c9ca17954bf5cce50c018f074ff97401
|
|
| BLAKE2b-256 |
6ac2a68d5c7a0ab8348ce72dcf65981c38336ec5b5e64a0fd6a3ca4d06c5bdb0
|
Provenance
The following attestation bundles were made for tree_sitter_pwsh-0.28.0-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.28.0-cp310-abi3-macosx_10_9_x86_64.whl -
Subject digest:
6cf0fa334e97582a4cc9c20cca4087cda848bc8b66178a60dbf535d902b2ef1c - Sigstore transparency entry: 1317237346
- Sigstore integration time:
-
Permalink:
wharflab/tree-sitter-powershell@f42510473ee48892186e81cda208107ab87173c5 -
Branch / Tag:
refs/tags/v0.28.0 - Owner: https://github.com/wharflab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_pypi.yml@f42510473ee48892186e81cda208107ab87173c5 -
Trigger Event:
push
-
Statement type: