Skip to main content

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 && ||, PowerShell 7 line-initial pipe continuation (\n| Cmd), redirections > >> 2>&1, invocation & ., splatting @params, barewords (including expandable $var.suffix forms), verbatim arguments --%
  • Directives — using namespace, using module (type names, relative bareword paths like .\Foo.psm1, and hashtable specs), using assembly, using static, and top-of-file #Requires
  • Strings and interpolation — expandable strings "$var $(expr)", escaped quotes "", # in interpolated strings, verbatim strings, here-strings @" / @', sub-expressions $(...), array sub-expressions @(...), hashtable literals @{}, and PowerShell-style escaping
  • Functions and named blocks — function, filter, workflow with param() blocks, attributes, validation, and begin/process/end/clean
  • Control flow — if/elseif/else, switch (-Regex, -Wildcard, -Exact, -CaseSensitive), foreach, for, while, do/while/until
  • Error handling — try/catch/finally with typed catch clauses, trap, throw, break, continue, return, exit
  • Workflow and data blocks — data sections, inlinescript, parallel, and sequence statement blocks
  • Expressions — ternary ? :, null-coalescing ??/??=, logical (-and/-or/-xor), bitwise (-band/-bor/-bxor), comparison/string/type/containment operators, -f format, range ..
  • Types — common .NET type forms including generics [Dictionary[string, int]], arrays [int[]], nested types Array+Enumerator, and double-backtick arity List1 ``
  • Variables — $var, $scope:var, ${braced} with backtick escapes, @splatted, and special vars $$ $^ $? $_
  • Unicode-aware source — Unicode identifiers, variables, parameters, type/class/enum names, and decimal digits
  • Classes and enums — attribute-decorated declarations ([Flags()] enum, [Attr()] class), properties, methods, constructors with : base()/: this() chaining, hidden/static modifiers, and inheritance clauses with generic bases (: IComparer[Object])
  • Numbers — decimal, hex 0x, scientific 1.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

License

MIT

Metadata

Release files for tree-sitter-pwsh 0.38.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tree-sitter-pwsh 0.38.1
File Size Uploaded
tree_sitter_pwsh-0.38.1.tar.gz 467.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for tree-sitter-pwsh 0.38.1
File
tree_sitter_pwsh-0.38.1-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details
tree_sitter_pwsh-0.38.1-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
tree_sitter_pwsh-0.38.1-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
tree_sitter_pwsh-0.38.1-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details
tree_sitter_pwsh-0.38.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.28+ ARM64, Linux glibc 2.17+ ARM64 Details
tree_sitter_pwsh-0.38.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl CPython 3.10 abi3 Linux glibc 2.5+ x86-64, Linux glibc 2.28+ x86-64 Details
tree_sitter_pwsh-0.38.1-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
tree_sitter_pwsh-0.38.1-cp310-abi3-macosx_10_9_x86_64.whl CPython 3.10 abi3 macOS 10.9+ x86-64 Details

Total release size: 2.3 MB

Release files / tree_sitter_pwsh-0.38.1.tar.gz

Download URL tree_sitter_pwsh-0.38.1.tar.gz
Size 467.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b79141901b0f886fe2dad863d23acf0a5aab5ad33006ddb435b5010ca4c184aa
BLAKE2b-256 checksum
How to use checksums
24b621d68566e52cd5cd7977a3c71bfdf0ed5f2b7cf7006db008b47d75fecb86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 16, 2026.

Transparency log

Release files / tree_sitter_pwsh-0.38.1-cp310-abi3-win_arm64.whl

Download URL tree_sitter_pwsh-0.38.1-cp310-abi3-win_arm64.whl
Size 215.7 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
c135f1d6cb4ed6815910838d2036d27711985ba17338e74dddc1e89dd3a22944
BLAKE2b-256 checksum
How to use checksums
1cb88064f96be18917a823b85ee486df3f6b1de1751632de594d7d4a086dee7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 16, 2026.

Transparency log

Release files / tree_sitter_pwsh-0.38.1-cp310-abi3-win_amd64.whl

Download URL tree_sitter_pwsh-0.38.1-cp310-abi3-win_amd64.whl
Size 228.2 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
965e0c9d5aca59a713251a8c409c226db52f07309b8b237a0104d69c20e80ab7
BLAKE2b-256 checksum
How to use checksums
f8dc6b34f9fea00fdb3da120f1d33e752c82259d07477903b17fded3e6e337fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 16, 2026.

Transparency log

Release files / tree_sitter_pwsh-0.38.1-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL tree_sitter_pwsh-0.38.1-cp310-abi3-musllinux_1_2_x86_64.whl
Size 246.7 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
bfeb9e0b369d8e79a4aa993cca1ed8c9f9c86df9989e3bea0c9ca19738ea1272
BLAKE2b-256 checksum
How to use checksums
f8710258713a1f11c98ab1611ec908788c26d68dbc217f7e2b642c299f196eff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 16, 2026.

Transparency log

Release files / tree_sitter_pwsh-0.38.1-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL tree_sitter_pwsh-0.38.1-cp310-abi3-musllinux_1_2_aarch64.whl
Size 236.7 kB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
a42a034c6648c5ab32e1b14f5dad393ca49afc362f3d074804a903f2e91d5ede
BLAKE2b-256 checksum
How to use checksums
fae03ab0b5993dd23416473750764bbaab578459eb5d8e7e16d6d9a216a620d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 16, 2026.

Transparency log

Release files / tree_sitter_pwsh-0.38.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl

Download URL tree_sitter_pwsh-0.38.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Size 237.4 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
a26f930e45545e3b0c722b4e5133a37d9b13b587ff1b8841b3214ace8537606b
BLAKE2b-256 checksum
How to use checksums
0262f2de1bd139e6c68f15fac862d18ab9982aa87d053ce94ec905a07a32742e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 16, 2026.

Transparency log

Release files / tree_sitter_pwsh-0.38.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl

Download URL tree_sitter_pwsh-0.38.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Size 247.7 kB
Tags CPython 3.10 Linux glibc 2.28+ x86-64 Linux glibc 2.5+ x86-64 abi3
SHA-256 checksum
How to use checksums
0ffe5b41624927a67f650b430e206589fd3a629e4b59f45bd559aadc6c8805cb
BLAKE2b-256 checksum
How to use checksums
8eced518526735953f7a35b1e119dd89f7145e4a7fea210c880a444e58b4f61c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 16, 2026.

Transparency log

Release files / tree_sitter_pwsh-0.38.1-cp310-abi3-macosx_11_0_arm64.whl

Download URL tree_sitter_pwsh-0.38.1-cp310-abi3-macosx_11_0_arm64.whl
Size 222.2 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0b8b3462050600c142687d4af5ddd477113287ab392244351224b164984ab044
BLAKE2b-256 checksum
How to use checksums
80e30c3095200ae693815e9a5aeffb4b1c8c6d649b528dd65e035a50d1a4fe15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 16, 2026.

Transparency log

Release files / tree_sitter_pwsh-0.38.1-cp310-abi3-macosx_10_9_x86_64.whl

Download URL tree_sitter_pwsh-0.38.1-cp310-abi3-macosx_10_9_x86_64.whl
Size 213.7 kB
Tags CPython 3.10 abi3 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
b372297e3424dee3c2d6be393aa0e1560e8218de70f0bbb674a27209d5cfdad8
BLAKE2b-256 checksum
How to use checksums
97482e8be53949bb5e7edd75666079bc5fb597cc2753d8c39c6ac96889841423
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 16, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.38.1 This release

9 release files

0.36.0

9 release files

0.34.2

9 release files

0.34.1

9 release files

0.33.0

9 release files

0.32.0

9 release files

0.31.0

9 release files

0.30.0

9 release files

0.29.1

9 release files

0.29.0

9 release files

0.28.0

9 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page