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-hledger

v0.1.6

Published

Tree-sitter grammar for hledger journal files

Readme

tree-sitter-hledger

CI npm

A Tree-sitter grammar for hledger journal files.

Features

  • Full parsing support for hledger journal syntax
  • Transactions with dates, status markers, codes, descriptions, and tags
  • Postings with accounts, amounts, costs, and balance assertions
  • All major directives: account, commodity, payee, tag, include, alias, decimal-mark, P, D, Y, apply account
  • Line comments (;, #), block comments, and inline comments with tag support
  • Flexible amount formats (commodity before/after, signed amounts, various separators)
  • Syntax highlighting and code folding queries included

Installation

Node.js

npm install tree-sitter-hledger
const Parser = require('tree-sitter');
const hledger = require('tree-sitter-hledger');

const parser = new Parser();
parser.setLanguage(hledger);

const tree = parser.parse(`
2024-01-15 * Grocery Store
    Expenses:Food        $50.00
    Assets:Checking
`);

console.log(tree.rootNode.toString());

Rust

Add to your Cargo.toml:

[dependencies]
tree-sitter = "0.25"
tree-sitter-hledger = { git = "https://github.com/ptimoney/tree-sitter-hledger" }

Python

pip install tree-sitter-hledger
import tree_sitter_hledger as ts_hledger
from tree_sitter import Language, Parser

parser = Parser(Language(ts_hledger.language()))

Supported Syntax

Transactions

2024-01-15 * (CHECK-123) Grocery Store  ; category:food
    Expenses:Food:Groceries     $125.50  ; item:weekly
    Assets:Checking            -$125.50

2024-01-16 ! Pending Payment
    Liabilities:Credit Card     $50.00
    Assets:Cash

Amounts

Various formats are supported:

$100.00          ; Symbol before amount
100.00 USD       ; Symbol after amount
-$50             ; Negative with symbol before
$-50             ; Negative with symbol after
€1.000,50        ; European format
10 AAPL @ $150   ; Unit cost
10 AAPL @@ $1500 ; Total cost
$500 = $2500     ; Balance assertion

Directives

account Assets:Checking
commodity $1,000.00
payee Whole Foods
tag project
include monthly/january.journal
alias Debit=Assets:Bank:Debit Card
decimal-mark .
P 2024-01-01 EUR $1.10
D $1,000.00
Y 2024
apply account Assets:Checking

Comments

; Line comment with semicolon
# Line comment with hash

comment
Multi-line block comment
Can span multiple lines
end comment

2024-01-15 * Purchase  ; inline comment with tag:value
    Expenses:Food  $50  ; receipt:yes, store:walmart
    Assets:Cash

Queries

Syntax Highlighting

The queries/highlights.scm file provides highlighting for:

  • Dates, status markers, codes
  • Account names, amounts, commodities
  • Directives and their arguments
  • Comments and tags

Code Folding

The queries/folds.scm file enables folding for:

  • Transactions (fold postings)
  • Block comments
  • Consecutive line comments

Development

Building

npm install
tree-sitter generate   # Generate parser from grammar.js
tree-sitter build      # Build native bindings

Testing

tree-sitter test       # Run corpus tests
npm test               # Run Node.js binding test

Interactive Development

npm start              # Opens tree-sitter playground in browser

Test Corpus

Tests are located in test/corpus/:

  • transactions.txt - Transaction parsing
  • directives.txt - Directive parsing
  • comments.txt - Comment parsing

File Types

This grammar recognizes:

  • .journal files
  • .hledger files

Related Projects

  • hledger - Plain-text accounting software
  • hledger-lsp - Language Server Protocol implementation for hledger
  • Tree-sitter - Parser generator and incremental parsing library

License

MIT