Ohm combines a parsing expression grammar language with a JavaScript library for building parsers, interpreters, and compilers from custom grammars.
Overview
Ohm is a parsing toolkit built around parsing expression grammars (PEGs), a formal way to describe syntax. You write grammars in the Ohm language and use the library to recognize input, build parse trees, and attach semantic actions.
The design separates grammars from semantic actions, which the project describes as improving modularity and readability. It supports left-recursive rules so left-associative operators can be defined naturally, and grammars can be extended in an object-oriented style.
You can define grammars inline in JavaScript, in separate `.ohm` files, or use the interactive editor. The library runs in browsers via a script tag and in Node.js, Deno, and other environments through package installs. A Docker image also supports running the Ohm CLI without a local Node.js install.
Debugging aids include a text trace of parser decisions and an online visualizer for grammars. The project documents patterns for publishing shared grammars and points to examples such as classroom live programming environments built on Ohm.
Key features
- PEG-based grammar language
- JavaScript parser interface
- Left-recursive rule support
- Grammar extension syntax
- Separated semantic actions
- Browser and Node.js usage
- Interactive grammar editor
- Trace and visual debugging
Use cases
- Custom file format parsers
- Programming language prototypes
- Interpreter and compiler experiments
- Teaching parsing concepts