Sign in

OhmJS

@ohmjs.org
89 followers 55 following 32 posts

A user-friendly parsing toolkit for JavaScript and TypeScript ∙ ohmjs.org

PostsRepliesMedia
OhmJS @ohmjs.org · 27/02/2026
Whoah. Today we discovered that ohm-js is now a "high-impact" NPM package (>1M downloads/week). The mystery was: why? Turns out it's now a transitive dependency of the Vercel CLI, via pip-requirements-js, an Ohm-based package for parsing requirements.txt files: github.com/Twixes/pip-r...
Line chart showing weekly downloads for the npm package "ohm-js" from February 28, 2025 to February 26, 2026. The graph displays relatively flat growth at around 200,000 weekly downloads for most of the year, then shows dramatic exponential growth starting in late January 2026, skyrocketing from approximately 200,000 to 1.8 million weekly downloads by late February 2026. The y-axis shows weekly downloads ranging from 0 to 1.8M, and the x-axis shows dates with major tick marks every few months
040
OhmJS @ohmjs.org · 14/01/2026
Oh hey, we're in JavaScript Weekly again 😊 javascriptweekly.com/issues/768
Ohm: A Parsing Toolkit for JavaScript and TypeScript — It’s been a few years since we covered this project and it’s come along a lot since. It’s a library for building PEG-based parsers you can use in interpreters, compilers, analysis tools, etc. and you can even play with its grammar online.

Warth, Dubroy, et al.
010
OhmJS @ohmjs.org · 10/12/2025
Just added an example to the Ohm repo of implementing something like Zed's SumTree. (aka "monoid-cached trees" if you want to sound clever) Full example here: github.com/ohmjs/ohm/bl...
Screenshot of the following code:

// In abstract algebra, a _monoid_ is a set (or a data type) that has
// (a) a "combine" operation that's associative, i.e. (a + b) + c = a + (b + c)
// (b) an identity or neutral element.
// This is our identity element…
const LOC_IDENTITY = {line: 0, col: 0};

// …and this is our "combine" operator.
function sumLocations(a, b) {
  return {
    line: a.line + b.line,
    // If `b` has more than one line, we can ignore `a.col`.
    col: b.line > 0 ? b.col : a.col + b.col,
  };
}

function compareLocations(a, b) {
  return a.line - b.line || a.col - b.col;
}

const semantics = g.createSemantics();

// A helper operation to get the "size" of a node, such that
// endLoc = sumLocations(startLoc, size).
semantics.addAttribute('_size', {
  _default(...children) {
    return children.reduce((acc, node) => sumLocations(acc, node._size), LOC_IDENTITY);
  },
  _terminal() {
    const lines = this.sourceString.split('\n');
    return {
      line: lines.length - 1,
      col: lines.at(-1)?.length || 0,
    };
  },
});
031
OhmJS @ohmjs.org · 23/06/2025
Ever wanted to use Ohm from another language? Go, Python, Rust? See the brand new, experimental support for compiling Ohm grammars to Wasm: github.com/ohmjs/ohm/d... It wasn't the main goal, but it also appears to be a perf win — parsing is about 10x faster on real-world grammars (e.g. ES5).
A couple months ago, I started prototyping a new feature: the ability to compile an Ohm grammar to WebAssembly, so that it can be used from languages other than JS. You can find more background (use cases and implementation details) in #503.  The MVP is complete, and this feature is now available for early testing (with some limitations). We're very interested to get feedback and hear what uses cases people have for this.  Although it wasn't the main motivation for this work, early benchmarks are showing ~10x improvement in parse times. Take this with a grain of salt — since the implementation isn't yet complete, it's hard to know what the final performance will look like. But it looks like this will be a significant performance win for real-world grammars!
142
OhmJS @ohmjs.org · 12/03/2025
Very cool to learn that Ohm was used to create Gambu-Script, which is used to teach programming to over 90k students in Austria! It's part of SchuBu, a free-to-use digital schoolbook: www.schubu.org/p768/progra...
An illustration explaining computer programming basics titled 'Sequence'. The top contains text explaining that a computer program is a set of instructions. Below is a cartoon illustration showing a purple robot sitting at a computer with a confused green monitor display. The robot is speaking in binary code (shown in a speech bubble), while the monitor shows question marks in a thought bubble. The scene includes bookshelves in the background. The caption reads 'Fig. 1 Learning languages pays off.'An educational diagram explaining loops in programming using GamBu-Script. The image shows text explaining that loops are a way to handle repeated actions in programming, with two syntax examples: 'repeat x seconds [command]' and 'repeat x times [command]'. At the bottom, there's a code example in a red-bordered box showing 'right 100' followed by 'repeat 100 times left 1'.
073
OhmJS @ohmjs.org · 17/02/2025
Anyone catch Ohm in the current edition of JavaScript Weekly? javascriptweekly.com/issues/723
010