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"

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.4.1.tar.gz (25.9 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.4.1-cp310-abi3-win_arm64.whl (19.0 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_batch-0.4.1-cp310-abi3-win_amd64.whl (20.2 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_batch-0.4.1-cp310-abi3-musllinux_1_2_x86_64.whl (34.5 kB view details)

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

tree_sitter_batch-0.4.1-cp310-abi3-musllinux_1_2_aarch64.whl (35.4 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_batch-0.4.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (36.5 kB view details)

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

tree_sitter_batch-0.4.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (35.0 kB view details)

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

tree_sitter_batch-0.4.1-cp310-abi3-macosx_11_0_arm64.whl (18.6 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_batch-0.4.1-cp310-abi3-macosx_10_9_x86_64.whl (18.2 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: tree_sitter_batch-0.4.1.tar.gz
  • Upload date:
  • Size: 25.9 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.4.1.tar.gz
Algorithm Hash digest
SHA256 7da657fec825c0e6a338506e866e5d6318b6a57b7f618d923d320367d6f0087c
MD5 92430d2a2354a039553ddbfb60756451
BLAKE2b-256 3df28254a48240d1bfd28f7f56cdef7dbb11000870cd2d332c76a4c0439af424

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.4.1-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 31b628a48f3a75b5b6a6ea7dfff74c2ab3078aa83ec65fa9f51493526c5f1dae
MD5 56e6a0c9668f42857a7501d939003587
BLAKE2b-256 7b0639d7e6406d42fcaf21b0edaa0e5b06f55424f0391718378fa7e68800b1f1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.4.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 0417ab09fb60818916d6948bf7368dfcf99daa25ee16fb9a96ccd63256aea5ed
MD5 c9258da038f3f45ad8f7d1a61baafa17
BLAKE2b-256 1322ed36713ab464a452648ee1e31d3791ad8008c3e5129efc4be639205b85d0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.4.1-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 538ca6f000954d7bb6f881f69e643b9f4e54ed75c2faa962d352cfffc6e392ab
MD5 315e8b743ddd768b87f9ac84d2c89c00
BLAKE2b-256 3f022228235d0e326ebf9506eb627a0ca72bb4fa85df4c41c1b4ab21e1ba692e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.4.1-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 a381e216b458690feda5cb260a3784b31283c02473db477d1f15e7f8d996ec0f
MD5 51c54d3f31d0521974890bfb0451a2d3
BLAKE2b-256 f98d0eb7f60e2dc49964026ebda264c64cc500758da76bf59b1b17a304b604ee

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.4.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b4da87f9674cfac9662c4f896a7db9ebfe5103d59221afb0214d51d2a2f9bf0d
MD5 e5a0b363ca2e3504ed91b09af1dbc22d
BLAKE2b-256 dbad5ca329d4da0f2383b76a4f13f2315f722b49245bea43a5c061ba53cf5051

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.4.1-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.4.1-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.4.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 38d421b8cd1b4cdab2d5d30b3cc7f1f3ee1b202622507423ff1b783db92112f7
MD5 667cf095a39b5d44174787453627c8e1
BLAKE2b-256 d5a8f465dd3b8533423654f1c9779226b8f2e459f171dd07672b1a329d21b3f6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.4.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5e992e2e8b4f84950d9994ba015e08d7196c855f618fc30eb26dc72abf91b40c
MD5 909bf368c7a3a4f0f27a5dd147d6120c
BLAKE2b-256 428310919f68a1a6db1339fab6ae7b8ffc5270d7bbe37c86f8633b8893ff8e45

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.4.1-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 45f14d24a8ff80b3f8a27ab54831c5d885fa6abce598e7846d413b76c235d5f6
MD5 1a761494aa41f2b1406ded9dedbb81d3
BLAKE2b-256 37d9657d78d04970e5bebd7f3db18c7828e29d79ce6694be19b129d56d8f407b

See more details on using hashes here.

Provenance

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