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.2.tar.gz (24.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_batch-0.3.2-cp310-abi3-win_arm64.whl (18.2 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_batch-0.3.2-cp310-abi3-win_amd64.whl (19.5 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_batch-0.3.2-cp310-abi3-musllinux_1_2_x86_64.whl (33.1 kB view details)

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

tree_sitter_batch-0.3.2-cp310-abi3-musllinux_1_2_aarch64.whl (33.8 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_batch-0.3.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (35.0 kB view details)

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

tree_sitter_batch-0.3.2-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (33.4 kB view details)

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

tree_sitter_batch-0.3.2-cp310-abi3-macosx_11_0_arm64.whl (17.7 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_batch-0.3.2-cp310-abi3-macosx_10_9_x86_64.whl (17.5 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: tree_sitter_batch-0.3.2.tar.gz
  • Upload date:
  • Size: 24.6 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.2.tar.gz
Algorithm Hash digest
SHA256 e7e25e6fff32de99efff4507850547c1d0633118f40879d6b2c022888a4637d1
MD5 daa0cddcf1a00eca4365616eb858e238
BLAKE2b-256 7681cd0798639d183e42a7e07e5f144dac54d01963618ecb0514afc0e948262e

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.3.2.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.2-cp310-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_batch-0.3.2-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 4c61e28263f6b9a805c2bd58833eeb2f1ac8bca9023f87f492611e07460a6d54
MD5 7b4440dd98c2947b4212d31586d1e8e9
BLAKE2b-256 ad1861e9e28f3d2d1b20afc3d1835e6e27bc841af3dfe774a3761367905f89f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.3.2-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.2-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tree_sitter_batch-0.3.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b9decb1ca9d29e330029c3eec86d4f3ed3bd62373b0872cd5e3bd143ff86a225
MD5 0a4ba0266fadeda5cc185ee877b8013d
BLAKE2b-256 a17f29bbc04c86a0abc3d214ec0c37f575b82c1802b4a92c599ff40961c75015

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.3.2-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.2-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_batch-0.3.2-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 708f0159544e9579aa5d8158f3651c993aaf743256c020dd66ba990548fb9861
MD5 da8c4c38939026f62391a0f5341e3b06
BLAKE2b-256 56ce4451659026119ce3d9dd663c76e06a273e60fd1f89b9730cccba9a6f3c5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.3.2-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.2-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_batch-0.3.2-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 573a71df5a61e6790143249c6a6ca933fa76f1aa08818b2e74ad215417f560ae
MD5 353999698fe98955a8a71d313be329d7
BLAKE2b-256 08ca42750b1de8ac0569b2bcc75643caaa6ee6946fcf3c39f5e4f880e7c99ed3

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.3.2-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.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_batch-0.3.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9cd3ce173e5383e818a3f833aa11f3a6c5ce7b3ccb79fb46ef450cd35bee0e86
MD5 a544cf26f583008c63968918e92c98c3
BLAKE2b-256 78c2075c340993a8fe520cb713d778ebacba04f8e840f9594ca50ea90f98da8e

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.3.2-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.2-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.2-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 96840e4977ab73ab097bbb4394200429b9896bba4a6ece0b82087b9cc31d2da6
MD5 8eee9f0f8df9db65f37005957d306ae0
BLAKE2b-256 08cf238fe1ce2adf37a3883941fa8ff3e717609d5fd144f9af46eec91a0c5d0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.3.2-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.2-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_batch-0.3.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 79677bbe062d8de85dac7003ab2241a2cfe2e029fb934886305c0ec85034674f
MD5 099d157a3f04cd58dc0c104542b57552
BLAKE2b-256 d51e70fa7e82b98f69b4e9951e88c2b0fd54e74a9fd1693cac764bbd10db761a

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.3.2-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.2-cp310-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_batch-0.3.2-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 51ccec2d91fdc7ca7872a5ab603591974e5a039442d4e8fa99ff9eab07c0af77
MD5 8d432c30f097fba6f08771c8e9f5524a
BLAKE2b-256 a8e20aaac97e4e0ae76d4af890e620d4727eacbc931ac2bb590c5084fa5997d2

See more details on using hashes here.

Provenance

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