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.5.0.tar.gz (26.5 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.5.0-cp310-abi3-win_arm64.whl (19.4 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_batch-0.5.0-cp310-abi3-win_amd64.whl (20.7 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_batch-0.5.0-cp310-abi3-musllinux_1_2_x86_64.whl (35.3 kB view details)

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

tree_sitter_batch-0.5.0-cp310-abi3-musllinux_1_2_aarch64.whl (36.1 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_batch-0.5.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (37.2 kB view details)

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

tree_sitter_batch-0.5.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (35.8 kB view details)

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

tree_sitter_batch-0.5.0-cp310-abi3-macosx_11_0_arm64.whl (19.0 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_batch-0.5.0-cp310-abi3-macosx_10_9_x86_64.whl (18.6 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: tree_sitter_batch-0.5.0.tar.gz
  • Upload date:
  • Size: 26.5 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.5.0.tar.gz
Algorithm Hash digest
SHA256 815ea458cc6de3cce759658e7edb81f34c8a671aeadf70cdc05b1b4c5e1bfece
MD5 1219d2e87a230c39e28de9072d0110fe
BLAKE2b-256 936dc0c31754ef48a78e968524aa82977167459a7283e599a8beddbc7e2e29ed

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.5.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 534da062fc1a401a65aca2e062d8535faf0b41a7671fb97b4181a3b6e8ee13f2
MD5 78012af4f655fb8c681af2cf921e43f9
BLAKE2b-256 f27c0bff8c828fbb34010d1bc008d31c3d11f5272c951a40d6aa3643bbea95d7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.5.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9f8c722ffd9b869627efe1ee789d12ea77ec113c779419efa25f13714862ceda
MD5 db7d1a5c4d482bbad09b852876f7ac15
BLAKE2b-256 84514f43c50036c843342b5ff4b8bfbda42e87b155d2bfe0a951616a5cdc35dd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.5.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c3836ad069777fd408515db943062b1a6cbdced892ac74ca575f33262f254fac
MD5 a0e666ce51a29a413321809c2396f56f
BLAKE2b-256 3412446bcc36c3f68c1a680e3b2c2d0fc25676777af7969a650bbfe8c0c56c8f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.5.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 a9dec91a345c87d126583e00b2d049324905d5df342d9c835cc82e9a5ca5a511
MD5 9678009ecfbe49c5952ac7eb02456663
BLAKE2b-256 db6278ed7cabde3abfe19e4467b549f9d9fec6e5802c6911bc73cf75e7aa70e1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.5.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d3e4ec33b80f55223ead4c6dbcd4946a6a6797f4efdd5a07cf18c5fd52726d6d
MD5 f571eece7204d7135fdd708c6bf49cf1
BLAKE2b-256 2b5a16ebafc2f085360d3cd9c682b56131195d541c97a8637a054a8a5e419f00

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.5.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.5.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.5.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 ce2350826a0a66dc4db2b045977ad132166cdb746c9db2271ee8c99c5ce4ec79
MD5 4d4e4ea1a6c9ac3e36f5a2e2a7ff124b
BLAKE2b-256 a11b1564a7ba19771212e95500cf9e38db88c49782a755f171f4a650fc0b99b5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.5.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2b527b49d14c330fb1743d0936822751889febc62db063b7fad6841cee1e7680
MD5 7a79f49ab5bb3258433e0c62189b9165
BLAKE2b-256 edf7377674e60c49ba59bfa37abb2c71d1aba834c98d7708238895f3cecd984b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.5.0-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 29ecf7501d9835ee33936a6fbd67035145710d09d0772663ee73e7e17caa18d8
MD5 f1241fb3e2ac817621f2e58a84fc73f0
BLAKE2b-256 43ea01f6415e89d1b30e43029ae8d9d0b1fe86279881f76e7d8582de76c558c0

See more details on using hashes here.

Provenance

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