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

Uploaded CPython 3.10+Windows ARM64

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

Uploaded CPython 3.10+Windows x86-64

tree_sitter_batch-0.2.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.2.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.2.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.2.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.2.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.2.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.2.0.tar.gz.

File metadata

  • Download URL: tree_sitter_batch-0.2.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.2.0.tar.gz
Algorithm Hash digest
SHA256 9dbea6bb2dad8801d3ca7807e255751fcc3577cd7e8da2c39cb5050fa2e9f202
MD5 c18ea646aaefeba4c13720852e82c70e
BLAKE2b-256 c5aaa88fb29cd30ea872d5884eb07b2407cf7a13a02b144db7b412b8e22395ea

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.2.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 66309f1a48ca91c8a85a2dcf311bd88a09d10ea7779d069ed4b449f3e42ddf40
MD5 8a04c26e8f374e2e3c91a4a2ee6628a5
BLAKE2b-256 9b7d51ff35c7c2b2bcabbe3e3fc26b1c384d3542e5020086d6e384802af14c8c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.2.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 35e4913d91d5ff9b217983de7a0e5348c8365902bb0a888d9fa47b59140910b5
MD5 a78168266b79f61aa05afeec97e3577a
BLAKE2b-256 69395a9a5aeaa467e7cb86f7cbf5a4517e558c3931aeb86c9953ed69df818ded

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.2.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 abc3c03abdaabf5f7f5392819f9eae95dc969f3fda3075db4c441f28b0a601f4
MD5 6e2a5938de641eb5bd18ccbd22f8f52e
BLAKE2b-256 4aa0283b0afb4d0b46d688948ebb21447f33c8d6327a53db77480dd3309f1e78

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.2.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 0ea674190672ac74b7b95b030f3df02a284a2c48b02c88d74049261121904b72
MD5 381732482a72ee44c50ec614cdbd3912
BLAKE2b-256 9494e4070aa263ecf991db9bae77c89eb31f74eb8155235023081f43d38ad4fe

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.2.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b5a5e4c30c186571b42521bb859d023ce9cddf5fcd658f81589514ffe4e4aa51
MD5 43330b8f25e22b69371eeb2fc9f46d3c
BLAKE2b-256 206870b5a544cbd55a481aa2de87c747992f352886ff9abf29d89183854bbc62

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.2.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.2.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.2.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 9a0d101d3e906dad62c7951801163f3bd2f47d9c5b578eb87d9eb8016af91e35
MD5 51b14131e5cd74e39884bd73515e4345
BLAKE2b-256 77b3551910585d8c1bc9f7b76b066703f33d82a77272517458e0187fb204877d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 901ceb2f01e75c3fc18a3402570470eef302c7e2671dc3b5240eb99a6cada3e1
MD5 15c7c4827ceddf6f5f0019deab476c4c
BLAKE2b-256 8347a6833a82f2c6902e4c5008f9e474100e3265756e2b942662861a162b8d94

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.2.0-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 93ecad995e707ea9baaabef5d5bb5874cfcfdf5659a5e87d5a16b9cf694d19b4
MD5 200e8afa6d77528f197055605e0dd88b
BLAKE2b-256 ac2c490c458f4fd799e94eb5740dc8b882c6d7d4dce8f7487191bdce82c623f3

See more details on using hashes here.

Provenance

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