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, EXIT /B
  • VariablesSET (plain, /A arithmetic, /P prompt), %VAR%, !VAR!, %%i, %~dp0, %VAR:old=new%, escaped forms %%VAR%% %%%%i
  • Echo — free-form text with literal ( ) ! %, inline strings, and variable references
  • Operators — pipes |, redirects > >> 2> 2>&1, conditional && ||, separator &
  • Structure — labels :name, comments REM ::, parenthesized blocks, @ECHO OFF, macro invocations
  • 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) (arithmetic_assignment (set_option) (arithmetic_expression)))
  (if_stmt
    (string)
    (parenthesized
      (cmd (command_name) (argument_list (argument_value)))))
  (for_stmt
    (for_variable)
    (for_set (for_set_literal))
    (parenthesized
      (cmd (command_name) (argument_list (string) (string)))))
  (if_stmt
    (variable_reference)
    (comparison_op)
    (argument_value)
    (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.10.1.tar.gz (42.2 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.10.1-cp310-abi3-win_arm64.whl (31.8 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_batch-0.10.1-cp310-abi3-win_amd64.whl (33.2 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_batch-0.10.1-cp310-abi3-musllinux_1_2_x86_64.whl (39.7 kB view details)

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

tree_sitter_batch-0.10.1-cp310-abi3-musllinux_1_2_aarch64.whl (39.9 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_batch-0.10.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (40.3 kB view details)

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

tree_sitter_batch-0.10.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (40.0 kB view details)

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

tree_sitter_batch-0.10.1-cp310-abi3-macosx_11_0_arm64.whl (31.7 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_batch-0.10.1-cp310-abi3-macosx_10_9_x86_64.whl (30.3 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: tree_sitter_batch-0.10.1.tar.gz
  • Upload date:
  • Size: 42.2 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.10.1.tar.gz
Algorithm Hash digest
SHA256 8a8b850943afdeb75a90a36423babae0d58b901647d0d76bee80624d737a9cfa
MD5 2ab208396aeb9de361f73d9ee53b196c
BLAKE2b-256 327081417e2c6fedfdb6f37be5bd511877ce251a22fa59fee9dbb8519f26622a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.10.1-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 02ce84eb28e6bcc75ce44f4ab938fa910f8e2c438aa9edc23e2b27f7e7cd2bf7
MD5 93f354d9424bfcb2f678fb3a04c346cf
BLAKE2b-256 ac6ada2590062afc369bade4f40913e63743c01a871a0acc425dd106851c4ecb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.10.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ce8f66f8c729aada529971240bb36f9c0d96ee0b70b481d0642b3157248c23c2
MD5 7610e25e2544983acf5c7d578cd2c102
BLAKE2b-256 7f98e4ced9b5d5bb8fe2975705d530a735fd58786439965fb8f7f4656f3295a0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.10.1-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c4c1d6cd5b65276afea026fdbcf6ca0cb926c72c10139fbd2e1eddc9d26942ff
MD5 15f5f9761e8c94f9a3f08a7ad54d95b7
BLAKE2b-256 ea487a470d25c16bd3fc69fba221d8a2dde59fb9d132860be05b5b6d9d30ba05

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.10.1-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 d28eecae290c3ff3b501c1ce9b81decb317d5b9c41c25542edcb8f9766940d06
MD5 de33ae7d5a52d4fd4a7e6bca0a37a4a9
BLAKE2b-256 c5d9c212ceda6b0d3b2b9b0992f615917dff164a86a6d85194ca177ca50e8ab3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.10.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f836d58568aee987aa9f977b5dd84d13948d3cbde79d79e57c2dc8db3b0494bb
MD5 b34509d0c1c980d8462f468afb7fd648
BLAKE2b-256 4790dde3ffc5325b001a975d7e9089d46d6a79a1273f1f2f649d0dc6f434de9c

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.10.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.10.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.10.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 351365b922e8b0d596deb43d363e40e67dfe04d513018d1df7e37c79ca52e169
MD5 caee0d7335d7e17ead3c1dec3668104f
BLAKE2b-256 736ef93942d0a4168f2046941d7280669543393dcef6f0d3ab857364ef7c6274

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.10.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f97826d4c0f667b7681bfe7e09a84f560ddcac83feb6ea4cf6c1ea2ad9cc2ac9
MD5 51fc0673a443aaf49723fe87af59f565
BLAKE2b-256 25ca1e04993d0a5290b790498e3d50dad7322ced0b81389b5e58921d0c84ec12

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.10.1-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 c100b301e28589837e284d60afd536754125e8dec2bdc962c861bc6b6f0ee1db
MD5 f0ead39c7391aeaae0fbb4c80866a0e0
BLAKE2b-256 86e301f3d30afd0484312fa86c409847f543268681b5977ca889d1d446ae377c

See more details on using hashes here.

Provenance

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