Skip to content

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

License

Notifications You must be signed in to change notification settings

raphinesse/nearley-auto-unwrap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nearley-auto-unwrap

Makes nearley 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 thus does not support the @autoUnwrap option. Instead, you can exclude rules from being transformed by providing an exclude function as an additional option:

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published