Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bates64/nearley-make
Compile nearley grammars at run-time
https://github.com/bates64/nearley-make
Last synced: 14 days ago
JSON representation
Compile nearley grammars at run-time
- Host: GitHub
- URL: https://github.com/bates64/nearley-make
- Owner: bates64
- License: mit
- Created: 2016-07-20T15:35:03.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-06-27T16:03:35.000Z (over 7 years ago)
- Last Synced: 2024-12-07T02:37:26.426Z (16 days ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/nearley-make
- Size: 4.88 KB
- Stars: 4
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# nearley-make
> Compile [nearley](https://github.com/Hardmath123/nearley/) grammars at run-time`nearley-make` allows you to use [nearley](https://github.com/Hardmath123/nearley/) in Node.js, without requiring you to compile your grammar first.
Very useful for debug/development modes.
## Install
```sh
$ npm install nearley-make --save
```## Usage
Examples speak 1000 words.```js
const make = require('nearley-make')
const fs = require('fs')const grammar = fs.readFileSync('grammar.ne', 'utf-8') // note that this is a *nearley* file
const parser = make(grammar, {
// anything you want to expose to the grammar as variables
// for example builtins or flavour settings
output: 'Hello, World!',
// if you want to use `require` in your grammar, make sure you do the following:
require: require
})const trees = parser.feed('the usual').results
const tree = trees[0]// logs "Hello, World!"
console.log(tree)
``````python
# grammar.ne
main -> "the usual" {% d => output %} # output the exposed "output" variable
```