0.1.0 • Published 4 years ago

nearley-auto-unwrap v0.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

nearley-auto-unwrap

Makes rules with one symbol return that symbol's value, instead of an array containing it.

Implementation of kach/nearley#505 as a package.

Install

$ npm install nearley-auto-unwrap

Usage

const {Parser, Grammar} = require('nearley');
const addAutoUnwrap = require('nearley-auto-unwrap');

const grammar = require('./grammar.js');
const autoUnwrapGrammar = addAutoUnwrap(grammar);

const parser = new Parser(Grammar.fromCompiled(autoUnwrapGrammar));

In contrast to the proposed feature at kach/nearley#505, addAutoUnwrap transforms a compiled grammar and thyu does not support the @autoUnwrap option. Instead, you can exclude rules from processing by providing an exclude function as an additional option:

const autoUnwrapGrammar = addAutoUnwrap(grammar, {
    exclude: rule => rule.name.startsWith('foo_')
});