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

Uploaded CPython 3.10+Windows ARM64

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

Uploaded CPython 3.10+Windows x86-64

tree_sitter_batch-0.1.0-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.1.0-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.1.0-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.1.0-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.1.0-cp310-abi3-macosx_11_0_arm64.whl (20.9 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_batch-0.1.0-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.1.0.tar.gz.

File metadata

  • Download URL: tree_sitter_batch-0.1.0.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.1.0.tar.gz
Algorithm Hash digest
SHA256 a76db22a2aa034fc4e15398fda537b4eba0e98f07ddf704b05ab5b5a9145e31b
MD5 c2873064bb414d1062d80c2c4fc808d8
BLAKE2b-256 13f5a934858b8c170214e7e5281cbc2de396ad1df59611398cbad3f16436511c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.1.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 fb91cbbcd9ac28737aaa0fa7471c70befaf0a52e15aca59ad2c173815123b530
MD5 68d5dde1e01752074123e215c46fa42f
BLAKE2b-256 db8c3f049445ec59b5494b4861437fd2c47a8cc7c32e27ce339a671f563fbf57

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.1.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 15660d6db95029a6a5f17cd8280d18ce05044438cc0b6359a43391847479f09d
MD5 f30582940f15bda5c2ec806d2d2ec63c
BLAKE2b-256 a9cd466c57ba0792031e35f1bc7232fb805884dd181b3d904dcfc303b5ea9e50

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fb2c247b8568f3bab29830de79259e764daafc369aa7fa331b64c760881a3760
MD5 89ed661c5b02e128546b9839309fa286
BLAKE2b-256 8a4585e02a4cf8eff846f6d313bacd908d4a5c1be7825150c723aa16886cf6ae

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.1.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 0d18c4357fc875b606dd24ca466fbb71f877bed45f17c2ca52e990c4f9d42e76
MD5 4a00f15b77bc0cf341230972eebe0c67
BLAKE2b-256 e37b4ad30ef93bb1937dc281f2256daf54634c9ff6567fa3232a5d0d3724d55a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.1.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 441ce05089446fe4b118691e4dfa25e494003b53d934a5bee8e1ecba831492d9
MD5 86445992c7e261ac23226016f7d081af
BLAKE2b-256 8d8924da67e1f4446af507d74c3ab3fdd2d67497874166c26dc12d1678dfc42e

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.1.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.1.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.1.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 914099d2e4a96e6cc6e4a6f201ed47bef403d0e654d567e8c27cbd74badbd843
MD5 ed0eee434d6cfc4e29fc0f2789e4afa4
BLAKE2b-256 368abe29c5ae8003f8095d4d717e1d8bd4d11477da71ede135438f7fd4869a6b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9b34630c3f2c73c226b4b7b90b96e5371fa141b20abfb650b97e11adb5957629
MD5 78ec03f756ed0f6d19a27eef991fab4a
BLAKE2b-256 d560ebb321dd3f9c9d2cb0c6a14d0dbfdeb65b82bb3e4109071a26037f12f433

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.1.0-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ee6a3b2fd3f1e328b642f6df7f85d8a90afed5f902aaa868b2226e36de26fb52
MD5 d6ded3027e3ba9d9759b10621e6a56fc
BLAKE2b-256 d95a193ddfa0c006f488e029a0b92eae6281e7f73f05b2798329a6b0c24de417

See more details on using hashes here.

Provenance

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