npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tree-sitter-batch

v0.5.0

Published

A Windows Batch/CMD grammar for tree-sitter

Readme

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