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

@arrmee/tree-sitter-vba

v1.0.0

Published

Tree-sitter grammar for Visual Basic for Applications (VBA) — case-insensitive, with full statement coverage

Readme

tree-sitter-vba

A Tree-sitter grammar for Visual Basic for Applications (VBA).

Test

Fills the gap of the long-missing tree-sitter VBA parser — the only production-ready open-source VBA grammar for tree-sitter.

Features

  • Case-insensitive keywords — VBA is case-insensitive by nature; Sub, sub, and SUB all match correctly
  • Line continuation — supports VBA's _ line continuation character
  • Full VBA statement coverageSub/Function/Property, If/ElseIf/Else, For/For Each/While/Do loops, Select Case, With, Dim, Const, Set, GoTo, error handling, file I/O, and more
  • Expression hierarchy — proper operator precedence for arithmetic, comparison, logical, and concatenation operators
  • Pre-built DLL — compiled for Windows with MSVC ABI compatibility (via Zig)

Project Structure

tree-sitter-vba/
├── grammar.js              # Tree-sitter grammar definition
├── src/
│   ├── parser.c            # Generated C parser (1.2M)
│   ├── node-types.json     # AST node type definitions
│   └── grammar.json        # Grammar metadata
├── tree_sitter_vba.dll     # Pre-built Windows DLL (MSVC compatible)
├── sgconfig.yml            # ast-grep custom language config
├── rules/                  # ast-grep search rules
│   └── find_subs.yml       # Example rule: find all Sub procedures
├── test/
│   ├── sample.bas          # Sample VBA test file
│   └── simple.bas          # Simple VBA test file
└── tree-sitter.json        # Tree-sitter configuration

Usage

As a Tree-sitter grammar

# Install the grammar
npm install tree-sitter-vba

# Or generate from source
npx tree-sitter generate
npx tree-sitter build

With Python

import ctypes
from tree_sitter import Language, Parser

lib = ctypes.CDLL('./tree_sitter_vba.dll')
lib.tree_sitter_vba.restype = ctypes.c_void_p
lang = Language(lib.tree_sitter_vba())

parser = Parser(lang)
tree = parser.parse(bytes(code, 'utf-8'))

With C/C++

#include "tree_sitter/api.h"
TSLanguage *tree_sitter_vba();

TSLanguage *vba = tree_sitter_vba();
TSParser *parser = ts_parser_new();
ts_parser_set_language(parser, vba);

With ast-grep (custom language)

# sgconfig.yml
customLanguages:
  vba:
    libraryPath: ./tree_sitter_vba.dll
    extensions:
      - .bas
      - .cls
      - .frm

Building from Source

Prerequisites

Generate & Build

# Generate the C parser from grammar.js
npx tree-sitter generate

# Compile the shared library with Zig (MSVC compatible)
zig cc -shared -O3 -I src src/parser.c -o tree_sitter_vba.dll -target x86_64-windows-msvc

License

MIT. This grammar is an independent implementation based on the publicly available Microsoft VBA Language Specification (MS-VBAL). It does not derive from any GPL-licensed ANTLR4 grammar or other third-party VBA parser implementation.

Why another VBA parser?

Existing tree-sitter VBA grammars were either:

  • Incomplete — only parsing a subset of VBScript (tree-sitter-vbscript)
  • Wrong language — targeting VB.NET (tree-sitter-vb-dotnet) which has significant syntax differences from VBA
  • Abandoned — started but never reached production quality

This grammar is implemented from scratch based on the Microsoft VBA Language Specification. It was developed using AI-assisted translation with manual validation and extensive testing against real-world VBA codebases.