Build a parser for a custom configuration file format or domain-specific language without writing low-level parsing code.
Create an interpreter for a small programming language and use Ohm's interactive editor to debug the grammar in real time.
Extend an existing grammar to add new syntax rules without rewriting the original, using Ohm's inheritance system.
Add a formula or expression language to a web app that runs entirely in the browser with no server needed.
Ohm is a JavaScript toolkit for building parsers, interpreters, and compilers. A parser is a program that reads text written in some structured format, such as a programming language, a configuration file, or a custom data format, and converts it into a form that code can work with. Ohm gives you a way to describe the rules of that format in its own grammar language, then generate a working parser from those rules. The grammar language is based on a formalism called parsing expression grammars (PEGs), which are a precise way to describe what valid text looks like. You write the grammar as a set of rules, and Ohm handles all the parsing machinery. Separating the grammar from the code that processes matches is a design goal of the library: you define the structure in the grammar, and separately define what to do with each matched piece. This keeps both parts readable and maintainable as your language grows. Notable features include support for left-recursive rules, which makes it natural to describe left-associative arithmetic like 1+2+3, and an object-oriented extension system that lets you build a new grammar by extending an existing one rather than copying it. Ohm comes with an interactive online editor and visualizer at ohmjs.org/editor, where you can type a grammar and test inputs against it with instant feedback. This makes it much easier to debug why a grammar is or is not matching something. Installation is via npm for Node.js projects, or a single script tag for use in the browser. The README includes code examples for defining a simple grammar and checking whether input matches it. Real-world projects built with Ohm include a live programming environment for classrooms, a particle simulation language, and an audio composition tool.
← ohmjs on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.