Nonviolent Pirate Mobster
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    nearley-makepublic

    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!',
      
      // 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)
    # grammar.ne 
    main -> "the usual" {% d => output %} # output the exposed "output" variable 

    install

    npm i nearley-make

    Downloadsweekly downloads

    4

    version

    1.0.1

    license

    MIT

    repository

    githubgithub

    last publish

    collaborators

    • avatar