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
    (set_keyword) (variable_name) (assignment_value))
  (variable_assignment
    (set_keyword) (set_option) (variable_name) (assignment_value))
  (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"

The root package also exports the bundled queries/highlights.scm via go:embed:

import batch "github.com/wharflab/tree-sitter-batch"

lang := batch.GetLanguage()
query, _ := batch.GetHighlightsQuery()
// or access the raw .scm source:
// raw := batch.HighlightsQuery

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.7.0.tar.gz (28.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.7.0-cp310-abi3-win_arm64.whl (20.5 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_batch-0.7.0-cp310-abi3-win_amd64.whl (21.9 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_batch-0.7.0-cp310-abi3-musllinux_1_2_x86_64.whl (37.6 kB view details)

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

tree_sitter_batch-0.7.0-cp310-abi3-musllinux_1_2_aarch64.whl (38.2 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_batch-0.7.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (39.6 kB view details)

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

tree_sitter_batch-0.7.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (37.7 kB view details)

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

tree_sitter_batch-0.7.0-cp310-abi3-macosx_11_0_arm64.whl (20.4 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_batch-0.7.0-cp310-abi3-macosx_10_9_x86_64.whl (20.0 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

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

File metadata

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

File hashes

Hashes for tree_sitter_batch-0.7.0.tar.gz
Algorithm Hash digest
SHA256 8dce8fa342e530b288cb69680401a574a7ae84ce51779a8748a5c0513161eb20
MD5 05d75fb27542144ce1ffcb4e7b79245f
BLAKE2b-256 6feb6c982fbe1385a1265d1ae74eecb153fb425a6d52d8eb5118770e45469b66

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.7.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 e83a48f2195424c440da82121a2ad4eefd8518f99420caf7a18e771b7d299559
MD5 ca1884cc3f8cca5059aec635262db44c
BLAKE2b-256 c01ec165598f2312231dfae4a05c7bf28dc1f837dac1e14492cfc1d8f081f993

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.7.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 71298b90b42840f3a1630d8d9f8407e7cc8fee3f93ecda3477b8e81832b3c057
MD5 a59a873235eeb1323f557ea9b923d948
BLAKE2b-256 af0925bf72fafd5a9b2e0539712cc49c74c4e61c3cbb69fa763cd82efa8ec2ca

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.7.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 958aa691b543483721ce137276c953bbe177f0bbee4fa7fd736bb923d5c3e4ba
MD5 8e29e28b35960efc91752fbd5a35fdb4
BLAKE2b-256 9898bb42b39dd8daaa9c9790d0d1577fdd3f6abf64fcf3f9a256ce6e312aa19c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.7.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 cf64cdf498a39f7ca507563d7981f43ba52d62c21bf6f234da8df4e4f9619981
MD5 b2ddb9623a5d867599e6da881d839bcc
BLAKE2b-256 8e30967562e8fc189124dd61fb0c032acae0a2da0439049de778ef01ffec87c1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.7.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 bc9af9191e518334bff30cf9c9b5a65e1aa8f729e52ceca5be823f110d4b23d2
MD5 d48c6eb82885cca244e2d1ce30f60608
BLAKE2b-256 32474048e6c46245472cb213e063232b13ab244eb357be34980fdec3e97bb71a

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.7.0-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.7.0-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.7.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 2614e3d4f8a3b817b24486c26ed3945bff5aec6a1f8da7aac66bbfe4f6c23f9a
MD5 16fa25423c83cc99243eab45ab615e09
BLAKE2b-256 23b816b0a1c4cd4ae62f7f69605609bed1d60293d41e836406b3e4b495919324

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.7.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ec195883d6c832ee1e3ae84f94904cdc49ff965c87aaea5c8c964974c44a3f25
MD5 377554dc2c8eee121e9cfb3174a6ffcb
BLAKE2b-256 4aeb2f1eb642780625aef4c86b03eab457e882ccb0aa44d8fbf1d578f54b994c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.7.0-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9b0b05589b89550b3e2e2d8714d3fca6f8401ae5112a7b91ae6c3f3817155c0f
MD5 2020fab4350edee7e200f3ec387e3093
BLAKE2b-256 395627ee076219c10ec6477daa622ea8071aac819e3417639d2cfc2bb13c9dc6

See more details on using hashes here.

Provenance

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