node package manager

nearley-make

nearley-make

Compile nearley grammars at run-time

nearley-make allows you to use nearley in Node.js, without requiring you to compile your grammar first.

Very useful for debug/development modes.

Install

$ npm install nearley-make --save

Usage

Examples speak 1000 words.

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!'
})
 
const trees = parser.feed('the usual').results
const tree = trees[0]
 
// logs "Hello, World!" 
console.log(tree)
# grammar.ne 
main -> "the usual" {% d => output %} # output the exposed "output" variable