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.2.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.2-cp310-abi3-win_arm64.whl (20.4 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_batch-0.7.2-cp310-abi3-win_amd64.whl (21.7 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_batch-0.7.2-cp310-abi3-musllinux_1_2_x86_64.whl (37.2 kB view details)

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

tree_sitter_batch-0.7.2-cp310-abi3-musllinux_1_2_aarch64.whl (38.0 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_batch-0.7.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (39.3 kB view details)

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

tree_sitter_batch-0.7.2-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (37.4 kB view details)

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

tree_sitter_batch-0.7.2-cp310-abi3-macosx_11_0_arm64.whl (20.2 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_batch-0.7.2-cp310-abi3-macosx_10_9_x86_64.whl (19.9 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: tree_sitter_batch-0.7.2.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.2.tar.gz
Algorithm Hash digest
SHA256 ab3f44a7b1e805d913fe521719893db0c87d3f3b1a04ce8e9d9fb8016cdbb0c5
MD5 bcfec614d7c3f0ccaa2a4205a999b106
BLAKE2b-256 6212a7cb15f44ac647a0caf3a34a43e0ce19f22ed20eba069a29f09e68100d1a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.7.2-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 912bc9aa6757946a442e5e57f1c06e0538b6aa3112ad5416460b5deb2d1bf4a8
MD5 11b5c3764487b3a23c1bdd60b9caf8af
BLAKE2b-256 3569a1510ab1a80fcc8787ab3367d57706563003152d5ef6d4a1483dfa433cad

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.7.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ae7d6aac16abf7c3239d21919a7a97dd2b1958dcbfafc28cef214838a96c49e9
MD5 ad0eaeac3a7853d70ce2280c0ceb5e04
BLAKE2b-256 c6919b6d686a2d126f748e7db3428f02fa1237b6b648e6a06020d22cef226c2e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.7.2-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a3723f24b9146cfe01645e411926eb63ae468cfdacb0368e1588d18149a139f4
MD5 9cb279d81639918824db92325e7aacc2
BLAKE2b-256 0e2e3f1a5627d5822697c9c76f754e9cb8affe6b8c310d1fde67306ef782f987

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.7.2-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 8cc6432e6276cb98983647ef3ffdc259b8e70a6968a934df0af181409e463747
MD5 305d0a617306ee424cccb0705c9771bb
BLAKE2b-256 68607abd29131e7d4c88e8c032df9b3bc61dc56c13c42c0919eab4276c365232

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.7.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 77de4567c3ce4cc5f526cb5e193df0a57080c0441cd80787d1beef477676c0d2
MD5 bb71b385cb9bc782ccf6cab144d47d50
BLAKE2b-256 eb88896d09b7bf3c6eea0fa0641e6d6dbae476dffc31b5ed06534975707b4674

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.7.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.7.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.7.2-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 c99a3492fbecfd50ad0c795a4049ba24ab45e539982f8a529072cf89fd3982b2
MD5 b08103deb5c98a26ec46855b824724e4
BLAKE2b-256 57230c031485c43f9614186fe31d26419fb9662c34780156ce272ad59ee7a3ac

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.7.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 83e0d602dd21d412f74ada17f1d13a63c4244f2f4640f0457afed4da1ffd10ea
MD5 25f7c11dfdd70324d0189e5079f3a949
BLAKE2b-256 9537866d804ecd8e5b0bc66d7a4b29810dc33b8a3e9e81a6beafd1890a38c82f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.7.2-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 28d8679f7c57e4fc17804de8f679422e246fc30c0ead5567afd0a1a8e13045b3
MD5 4a98775c2fbdc41a2df73a15152df323
BLAKE2b-256 887b5264baf52245b342dbab73bd0eac6dba9781653aad022f077725af08e6c4

See more details on using hashes here.

Provenance

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