ohmjs /ohm
A library and language for building parsers, interpreters, compilers, etc.
★ 5,556⑂ 226👁 79⑃ 282● 269▤ 19
+0
日增长
5,556
stars
226
forks
79
watchers
282
prs
269
issues
19
releases
README
Ohm ·
Ohm is a parsing toolkit consisting of a library and a domain-specific language. You can use it to parse custom file formats or quickly build parsers, interpreters, and compilers for programming languages.
The _Ohm language_ is based on parsing expression grammars
(PEGs), which are a formal way of describing syntax, similar to regular expressions and context-free
grammars. The _Ohm library_ provides a JavaScript interface for creating parsers, interpreters, and
more from the grammars you write.
- Full support for left-recursive rules means that you can define left-associative operators in a natural way.
- Object-oriented grammar extension makes it easy to extend an existing language with new syntax.
- Modular semantic actions. Unlike many similar tools, Ohm completely
separates grammars from semantic actions. This separation improves modularity and extensibility, and makes both grammars and semantic actions easier to read and understand.
- Online editor and visualizer. The Ohm Editor provides instant feedback and an interactive visualization that makes the entire execution of the parser visible and tangible. It'll make you feel like you have superpowers. 💪
Some awesome things people have built using Ohm:
- Seymour, a live programming environment for the classroom.
- Shadama, a particle simulation language designed for high-school science.
- turtle.audio, an audio environment where simple text commands generate lines that can play music.
- A browser-based tool that turns written _Konnakkol_ (a South Indian vocal percussion art) into audio.
- Wildcard, a browser extension that empowers anyone to modify websites to meet their own specific needs, uses Ohm for its spreadsheet formulas.
Getting Started
The easiest way to get started with Ohm is to use the interactive editor. Alternatively, you can play with one of the following examples on JSFiddle:
- Basic parsing example
- Arithmetic example with semantics
Resources
- Tutorial: Ohm: Parsing Made Easy
- The math example is extensively commented and is a good way to dive deeper.
- Examples
- Documentation
- For community support and discussion, join us on Discord, GitHub Discussions, or the ohm-discuss mailing list.
- For updates, follow on Bluesky or Mastodon.
Docker
You can use the Ohm CLI without a local Node.js installation via the Docker image:
sh
docker run --rm -v $(pwd):/local ohmjs/ohm:latest compile my-grammar.ohm
For full usage instructions, including how to build the image locally and set up a development container, see doc/docker.md.
Installation
On a web page
To use Ohm in the browser, just add a single tag to your page:
html
or
html
This creates a global variable named ohm.
Node.js
First, install the ohm-js package with your package manager:
- npm: npm install ohm-js
- Yarn: yarn add ohm-js
- pnpm: pnpm add ohm-js
Then, you can use require to use Ohm in a script:
s.replace('const ', 'var '));
--
js
const ohm = require('ohm-js');Top issues
#158Allow for context-sensitive parsing14 comments · 2016-09-20#57Overloading parameterized rules?12 comments · 2016-02-01#450Add ability to type operation parameters & return values11 comments · 2023-05-01#180Add built-in rules for Unicode ID_Start and ID_Continue11 comments · 2016-12-13#286Grammar syntax for imports/includes9 comments · 2021-01-21#302Adding descriptions seems to mess up error reporting8 comments · 2021-06-02#34Performance comparison5 comments · 2015-07-24#487Partially parse grammar4 comments · 2024-08-02
Discussions
#618Generating TextMate syntax highlighting grammars from Ohm grammars and semantics0 comments · 2026-05-07#550Ohm v17.4.00 comments · 2026-02-12#549v18 packages organization0 comments · 2026-02-11#545Proposals for parsing error handling0 comments · 2025-12-30#541Ohm v17.3.00 comments · 2025-12-20#540Ohm v17.3.00 comments · 2025-12-20#538Any better way for whitespace to depend on context?2 comments · 2025-12-18#537Two projects I made with ohm0 comments · 2025-12-11
Latest release
Ohm v17.5.0 v17.5.0 2026-02-14Browser bundles: ohm.js • ohm.min.js New features: - [4401f84a] feat: New forwards-compatible ohm-js/v18 submodule Fixes - [a19e69da] fix: types ordering in package.json exports