Skip to content

Latest commit

 

History

History
32 lines (24 loc) · 1.41 KB

publishing-grammars.md

File metadata and controls

32 lines (24 loc) · 1.41 KB

Publishing Grammars

One of the core ideas behind Ohm is that grammars are APIs. If you have developed a grammar for a particular language and would like to share it for other people to use and build upon, here's what we suggest:

Module Exports

By convention, modules should export an object with a grammar property, and optionally a semantics property. For example, see the ES5 module in the examples/ directory. If a single package contains multiple languages, each language should be exported as a separate object. E.g., a package supporting multiple versions of Python might be used like this:

const {python2} = require('./your-python-package');
const result = python2.grammar.match('print 3');
python2.createSemantics(result).eval();

To package a single primary language along with other variants, you can expose the primary language from the top-level module, and the other languages as separate modules within the same package:

const smalltalk = require('./your-smalltalk-package');
const smalltalk72 = require('./your-smalltalk-package/smalltalk72');

Package Naming

To help users find your package, we suggest using a name of the form "ohm-grammar-someLanguage". E.g., the ES5 grammar in the examples directory is published on NPM as ohm-grammar-ecmascript.