Skip to main content

A Windows Batch/CMD grammar for tree-sitter

Project description

tree-sitter-batch

Windows Batch/CMD grammar for tree-sitter.

Parses .bat and .cmd files into a concrete syntax tree for syntax highlighting, code navigation, and analysis.

Features

  • Control flowIF/ELSE (EXIST, DEFINED, ERRORLEVEL, comparison with NOT), FOR (/D /R /L /F), GOTO, CALL
  • VariablesSET (plain, /A arithmetic, /P prompt), %VAR%, !VAR!, %%i, %~dp0, %VAR:old=new%
  • Operators — pipes |, redirects > >> 2> 2>&1, conditional && ||
  • Structure — labels :name, comments REM ::, parenthesized blocks, @ECHO OFF
  • ScopeSETLOCAL/ENDLOCAL with ENABLEDELAYEDEXPANSION
  • Case-insensitive — all keywords match regardless of casing

Example

@echo off
REM Build script
setlocal enabledelayedexpansion

set "PROJECT=MyApp"
set /a VERSION=1

if not exist "dist" (
  mkdir dist
)

for %%f in (src\*.txt) do (
  copy "%%f" "dist\"
)

if %ERRORLEVEL% == 0 (
  echo Build successful
) else (
  echo Build failed
  exit /b 1
)

exit /b 0

Parsed tree:

(program
  (echo_off)
  (comment)
  (setlocal_stmt)
  (variable_assignment)
  (variable_assignment)
  (if_stmt
    (string)
    (parenthesized
      (cmd (command_name) (argument_list (argument_value)))))
  (for_stmt
    (for_variable)
    (for_set)
    (parenthesized
      (cmd (command_name) (argument_list (string) (string)))))
  (if_stmt
    (variable_reference)
    (comparison_op)
    (integer)
    (parenthesized
      (cmd (command_name) (argument_list (argument_value) (argument_value))))
    (else_clause
      (parenthesized
        (cmd (command_name) (argument_list (argument_value) (argument_value)))
        (exit_stmt (integer)))))
  (exit_stmt (integer)))

Installation

npm

npm install tree-sitter-batch

Cargo

cargo add tree-sitter-batch

PyPI

pip install tree-sitter-batch

Go

import tree_sitter_batch "github.com/wharflab/tree-sitter-batch/bindings/go"

Usage

Node.js

import Parser from "tree-sitter";
import Batch from "tree-sitter-batch";

const parser = new Parser();
parser.setLanguage(Batch);

const tree = parser.parse(`@echo off\necho Hello World\n`);
console.log(tree.rootNode.toString());

Rust

let mut parser = tree_sitter::Parser::new();
let language = tree_sitter_batch::LANGUAGE;
parser.set_language(&language.into()).unwrap();

let tree = parser.parse("@echo off\necho Hello\n", None).unwrap();
println!("{}", tree.root_node().to_sexp());

Python

from tree_sitter import Language, Parser
import tree_sitter_batch

parser = Parser(Language(tree_sitter_batch.language()))
tree = parser.parse(b"@echo off\necho Hello\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

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_batch-0.3.1.tar.gz (26.1 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_batch-0.3.1-cp310-abi3-win_arm64.whl (21.6 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_batch-0.3.1-cp310-abi3-win_amd64.whl (22.8 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_batch-0.3.1-cp310-abi3-musllinux_1_2_x86_64.whl (27.4 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

tree_sitter_batch-0.3.1-cp310-abi3-musllinux_1_2_aarch64.whl (28.0 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_batch-0.3.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (28.3 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

tree_sitter_batch-0.3.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (27.4 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

tree_sitter_batch-0.3.1-cp310-abi3-macosx_11_0_arm64.whl (20.9 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_batch-0.3.1-cp310-abi3-macosx_10_9_x86_64.whl (19.7 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

Details for the file tree_sitter_batch-0.3.1.tar.gz.

File metadata

  • Download URL: tree_sitter_batch-0.3.1.tar.gz
  • Upload date:
  • Size: 26.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tree_sitter_batch-0.3.1.tar.gz
Algorithm Hash digest
SHA256 5fcbc8d074569d46da567e9ae21a7166dd8cb6c7b0731f20b0ec262564f55f25
MD5 e3a30c9920a12ade971a46f02374b3ec
BLAKE2b-256 6d68a101193a422be5baaa5024c49b9a29f7de6addcd430992975754685504d1

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.3.1.tar.gz:

Publisher: publish_pypi.yml on wharflab/tree-sitter-batch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_batch-0.3.1-cp310-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_batch-0.3.1-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 cd7f0171b9855e59d5adb0730debc2a85aec2f6908b591883d793c5017b5a390
MD5 7d4bde340bfdcf9a624f4ea42f337305
BLAKE2b-256 a9c0606fc47a9e1533b57d9a63ad52617dd342cf1cf667a443a623b92ecb4652

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.3.1-cp310-abi3-win_arm64.whl:

Publisher: publish_pypi.yml on wharflab/tree-sitter-batch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_batch-0.3.1-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tree_sitter_batch-0.3.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9144edf7efef5e85f57891b4f6334274febbdc105099a5245ab88e04cb906c6a
MD5 df70c7c8e25ce83fee05f5dfe43cbfeb
BLAKE2b-256 5b6135b8f4f971b0a54da36d74a077edb81d2a1cb434fe59b4eeaef724dcac28

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.3.1-cp310-abi3-win_amd64.whl:

Publisher: publish_pypi.yml on wharflab/tree-sitter-batch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_batch-0.3.1-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_batch-0.3.1-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c4ccf2c33e8e619ce4cecb8453ae20d05509ce41abcf9acd452d5ae811acabfa
MD5 98ecd2f7d6031fb3a6f59b308427dd8a
BLAKE2b-256 5ce16782d15e20336da79c57b11c85016a126296e4defa5a71fdf13bf55d2151

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.3.1-cp310-abi3-musllinux_1_2_x86_64.whl:

Publisher: publish_pypi.yml on wharflab/tree-sitter-batch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_batch-0.3.1-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_batch-0.3.1-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 f389d15e04c899aba713f2f7222557e059c8ae5f14a217a77801808e768e660e
MD5 06a551e52b37af78bba00b7c5ad4e8fb
BLAKE2b-256 26d28fe3c4f7898c788c2f16c61344302e81f1fd45e56ee194ada17e3cf21133

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.3.1-cp310-abi3-musllinux_1_2_aarch64.whl:

Publisher: publish_pypi.yml on wharflab/tree-sitter-batch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_batch-0.3.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_batch-0.3.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ad4e6e202ad1e1e38bd2f459d938aacae06754bd31d5e30987fbcb702564175a
MD5 013b2cd732ecccaff21b15e8e47a773a
BLAKE2b-256 d49fdca8eaf026aa38d23502b9a4e373ebc67ea40b1a3ca7b34341d820ce80c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.3.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl:

Publisher: publish_pypi.yml on wharflab/tree-sitter-batch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_batch-0.3.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_batch-0.3.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 e6087f9de7c61e51c751651dd44be598dacf6b283efa70625a3d0ec20a197aa8
MD5 7bd8098a8ee0503d4cd301ec5e5056f7
BLAKE2b-256 f8244b6d6b8bcc9d87c03c005f97c1808fffd63d38156853e4c8717e733b49ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.3.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-batch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_batch-0.3.1-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_batch-0.3.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cfe532e590e9e3f1250c858defe92736129c4db5b0a76042511424568c69c798
MD5 d101fe4a7ac70e9736fc6d8dc12b7ce6
BLAKE2b-256 b1ec22c3354f6e2dfef303913f20cfcac983bf2bbebcbd111f8d876f95b5ffb9

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.3.1-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: publish_pypi.yml on wharflab/tree-sitter-batch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_batch-0.3.1-cp310-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_batch-0.3.1-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1a113f7def8e2c4ebc7e413e710ce22ef155c68eb6674d6fce32479ad626f842
MD5 0712d764ba997272f730835372caa701
BLAKE2b-256 8b2f685475104efc845792b883016d012177b13a93c376701070a358c11bc4ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.3.1-cp310-abi3-macosx_10_9_x86_64.whl:

Publisher: publish_pypi.yml on wharflab/tree-sitter-batch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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