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.9.0.tar.gz (38.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.9.0-cp310-abi3-win_arm64.whl (27.3 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_batch-0.9.0-cp310-abi3-win_amd64.whl (28.4 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_batch-0.9.0-cp310-abi3-musllinux_1_2_x86_64.whl (59.3 kB view details)

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

tree_sitter_batch-0.9.0-cp310-abi3-musllinux_1_2_aarch64.whl (64.6 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_batch-0.9.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (65.6 kB view details)

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

tree_sitter_batch-0.9.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (61.2 kB view details)

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

tree_sitter_batch-0.9.0-cp310-abi3-macosx_11_0_arm64.whl (30.6 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_batch-0.9.0-cp310-abi3-macosx_10_9_x86_64.whl (30.2 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: tree_sitter_batch-0.9.0.tar.gz
  • Upload date:
  • Size: 38.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.9.0.tar.gz
Algorithm Hash digest
SHA256 4bab177cf26ad18a9f0aa5bd6424aef94ccdab067c5e5812969f25f0ce874410
MD5 d59e2a29e18fbca182840adc8c3435cf
BLAKE2b-256 6ea75b25ab9449f371195a8ab233d23c1723993a37f288c1e92c0b2bb001f197

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.9.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 664add1772eb75c4a6cfe10d642d765891764884cbe85958e73de76e56336379
MD5 b3b89ce8e317ee89d7884269ad01e154
BLAKE2b-256 a0c0c6f8c63834f6707980e0dbf3de7366cec8469ed9f61f5202fb9693f254d6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.9.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1f2160df8561c77810a5a2a6b346ae5437262e0f08f95a5f8adc001e7d0b22f9
MD5 f5c620e01ddfa7f66ade103fd5b74627
BLAKE2b-256 52c15f4c148ead237607ec7da7bf632cebca7ce77ecc398a88c23f72f15b40c0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.9.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b7ba7081fa58b2adeaa497ece5564447ca4a6f929c3416d8a5a68980eeafd266
MD5 67598b056e8bf698dcfbadc28d74cd99
BLAKE2b-256 230c9260abd36552f850fd897cf1a800eaf818cdbb8fb87f55d6f7ba2680357b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.9.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 d4100d1f70e4154517260add9657f37ec5153ba8a90ec279771b7ed0ff12e5cb
MD5 95cf2063a44a985215cf2c2650369175
BLAKE2b-256 e1da11fb20f4aabfd783ea6c11c3ae779e1c7bdbeebe90c28e50c0fdf1d856b9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.9.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3501994e4597018bcbe2224347b8956f4562eee26495890bd4775d5035f2a50c
MD5 4486c5d3d8ef2443222d513bb75d7181
BLAKE2b-256 a81ab1ae2e44c488b47e25a6fb6570aa592d94012b9447cf8297b19d6f3960ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.9.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.9.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.9.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 0e98aafdfeb786427da562602fc310afb68f1823c6d8bf08b15be248097b2ac7
MD5 709d87af87c354c3f8562db887a6f9d7
BLAKE2b-256 f302b5fd5e28806e1ae71cee0ef4669d6ee125a26a0c2929897303a373f323f9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.9.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b931f9e882950114888c7285a98e680928f82684760b9281feee15dd68f5673b
MD5 b27dbf9527d5adf12aebc22579e737f7
BLAKE2b-256 6d3bcb0247edd260d021f7e1ef5ca103fc6583c6f7da069ea0518baca47766e9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.9.0-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 883db0c19dd8ee5a23e052ef678dba2bf2166b80973663c7f43926e8c6ba5621
MD5 f3f314246cb8d3f378b9933f6eb19bef
BLAKE2b-256 7b613c777bd9450e08037d9cbb6d101313274c8ab58b1946136f13f0b9bb17e4

See more details on using hashes here.

Provenance

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