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.10.0.tar.gz (42.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.10.0-cp310-abi3-win_arm64.whl (31.7 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_batch-0.10.0-cp310-abi3-win_amd64.whl (33.1 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_batch-0.10.0-cp310-abi3-musllinux_1_2_x86_64.whl (39.6 kB view details)

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

tree_sitter_batch-0.10.0-cp310-abi3-musllinux_1_2_aarch64.whl (39.8 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_batch-0.10.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (40.2 kB view details)

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

tree_sitter_batch-0.10.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (39.9 kB view details)

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

tree_sitter_batch-0.10.0-cp310-abi3-macosx_11_0_arm64.whl (31.6 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_batch-0.10.0-cp310-abi3-macosx_10_9_x86_64.whl (30.1 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: tree_sitter_batch-0.10.0.tar.gz
  • Upload date:
  • Size: 42.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.10.0.tar.gz
Algorithm Hash digest
SHA256 38502835f447cad67e9873aa0d58af39772287ce8d61b952fdd831f951390899
MD5 34759954fe131ed0fb447fa2b531864f
BLAKE2b-256 02eb9c3a5720040a25388f7a1642492f793938eda1c8ec3531ece8a58250b790

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.10.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 377d6d012dcd5050a3bef9aa4334ba394ae8b6cfa4ee78681bdbd8ae906b03cb
MD5 d40e26460edf00021c16eea812e1e150
BLAKE2b-256 99641b593e24f2c735d84a860a6242bef62737d29e57c91cff87e703bf9c599e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.10.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 8a3a786bbd62b7ff3e3a546f345b2a57487558bb1a64b1dfd9c13b4fd11ee8e8
MD5 bc0d702120a5110ccac44e37a5000450
BLAKE2b-256 109a9c8d286c9fe7f0041959c97298c5a4976c0c09a3ff8d345ebe85a6cf8f9e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.10.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6390073fbc5a1d2165465a7c6281e72b1b8226c68dcba9f7d258c8d9d712594b
MD5 52b31542c7001e0a117cf2d844cef8bb
BLAKE2b-256 b429c19227135733ed81430cef214c1ada9cc7616321623a4a079d6429ce0409

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.10.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 65c3055c4d5ee46e214e5d6b00ffefd9c531b2e927a4f76ccbf8c53aad4fcee7
MD5 278995364d43aa1db83c090ec73193a4
BLAKE2b-256 169fc7e75ad8a7f0f7064c4efe98891bde8316f6a50b2bde89071a3a22d52320

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.10.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 71125f5cfca491392d6d668672b9d9edcd136c7496053022a5abadf9fb330b36
MD5 27f9b4f9103d98c032a2b5caf769a70f
BLAKE2b-256 a7df953c302414632fdfec658e6d4e2c58e5c91c31f6300cbb02e117147390c0

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_batch-0.10.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.10.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.10.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 be9823f9353e21bca93bdf7b7c4cab15d980b0e42c46a11ed69c3ca4880aa81b
MD5 aacbca7c455b2962dfe92fac323628cd
BLAKE2b-256 54ab1d16fe90733d25426b25a68c17f1100c306aa498808089f3ef8dd639f7bd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.10.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8d6c2214bbf55ea5b1135cd713bf140738d633a0a8ec532c0bf665cde7ff31d4
MD5 979dc8b4a247c3092aa40d51806185a4
BLAKE2b-256 ad6813b1d0e8ff3cd5e7099968a890d730d24ade839df6f05962e59b783357ad

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_batch-0.10.0-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9171b1d3a4aeb7d4fa6889ee6faecd91b773e0d164a99a6c76091f0b2ed441ea
MD5 238c4e76aa4d8f44c5e4cf37d1432151
BLAKE2b-256 47b05674f1bd777dafbc4dd98cde99ff72573fb254aeef8d4533251512d5b61d

See more details on using hashes here.

Provenance

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