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.2.tar.gz (26.3 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.2-cp310-abi3-win_arm64.whl (19.2 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_batch-0.4.2-cp310-abi3-win_amd64.whl (20.5 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_batch-0.4.2-cp310-abi3-musllinux_1_2_x86_64.whl (35.1 kB view details)

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

tree_sitter_batch-0.4.2-cp310-abi3-musllinux_1_2_aarch64.whl (35.9 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_batch-0.4.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (37.0 kB view details)

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

tree_sitter_batch-0.4.2-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (35.5 kB view details)

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

tree_sitter_batch-0.4.2-cp310-abi3-macosx_11_0_arm64.whl (18.8 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_batch-0.4.2-cp310-abi3-macosx_10_9_x86_64.whl (18.4 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: tree_sitter_batch-0.4.2.tar.gz
  • Upload date:
  • Size: 26.3 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.2.tar.gz
Algorithm Hash digest
SHA256 d933669a0c24f9629d87dff54371ca076110833cf348ae8319f347c870761495
MD5 c01eb57f54cb67df179acd8bedf4d832
BLAKE2b-256 4cd40789a177b7d9a79ba06c751b856c90372ee846a841954038180e2e4e7da5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.4.2-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 868b412f90e07c39a6ca671a651f097014f6855061120d8b297950120f038728
MD5 a68048445a27a2eaddf6dab720378e6a
BLAKE2b-256 2f420261567444d46dfcd4e5519aaae9d18abb2e35df4e7b11736196c7d339cf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.4.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 77e982abe7e2ce11cdb008700a8e4b81a110a6f3cc76ccf45921f59e536d6347
MD5 bc9ac13e1261307c445b3b6d4b4b39ee
BLAKE2b-256 9637f7f223b12bce063d0eb1223ee41b8db4f2e5a665d307edb18bc59b762e9d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.4.2-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6883e8794f2ef3cb8854b2b3323aeddfd5a3fcff0ad71468647807284851b27b
MD5 b7449a2adb9ffddb12728041a4d436b0
BLAKE2b-256 2f71dc06a2b19e51496e4b13f4ac621b9c32bd207983a8a411511ab0c2a8536d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.4.2-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 4b3c5891a38353a9473a07937f09048d90916e5edabbd071fe965374176f31ce
MD5 380af6941c4c8b2995c97c391ca71c14
BLAKE2b-256 4b1c1026901ca0281fbc9a5c8b9d42da45fab3021e5ce44e11f88e935d5216df

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.4.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f728229712fb18052ae784035f379797c0054d09673166aa2170a0f7276698ac
MD5 67836ddcac608f8683a0c3af37295bc0
BLAKE2b-256 feee236a7aa82140034aa28abc8a70f66518ea1b3d47e8c0deffa0a26af69471

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.4.2-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.2-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.2-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 9ae27d0ebff53c3076d308b3fced22de4ae9455f3d40bba85d58977134dc8369
MD5 f2a110ce462a8c1db6085ea986af58c9
BLAKE2b-256 ca66334e2194a440ff637bb16e5f29a8ff47ff75f40431a0f2ec867f8613c32a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.4.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a4d64dcdc668d075d4404620f3f2e759873cc6a6efc75e4b244cf83cd8ddea82
MD5 279c9cc3297b3cd33092b664c177f7f2
BLAKE2b-256 8825ee7a4076495725c61449bac2bd13d324b7e5ac1608201b613a7a103f0658

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.4.2-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 71c81fdb849786b1752f98aa8ff8155f4f14a9e8ff52804acf9f2ed07699c6fa
MD5 949058cfe802dd15e4df3c8b3695626c
BLAKE2b-256 c2fcf2c611bfc66aa4e06bb85b9dbc9c7eb89709a5597314d76fec6cf85b20e7

See more details on using hashes here.

Provenance

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