https://github.com/raphinesse/nearley-auto-unwrap
Makes nearley rules with one symbol return that symbol's value, instead of an array containing it.
https://github.com/raphinesse/nearley-auto-unwrap
nearley nearleyjs
Last synced: 3 months ago
JSON representation
Makes nearley rules with one symbol return that symbol's value, instead of an array containing it.
- Host: GitHub
- URL: https://github.com/raphinesse/nearley-auto-unwrap
- Owner: raphinesse
- License: mit
- Created: 2020-06-07T15:58:09.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-07-22T09:04:58.000Z (almost 5 years ago)
- Last Synced: 2025-01-28T13:16:51.906Z (4 months ago)
- Topics: nearley, nearleyjs
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nearley-auto-unwrap
Makes [nearley](https://nearley.js.org/) 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
```js
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:
```js
const autoUnwrapGrammar = addAutoUnwrap(grammar, {
exclude: rule => rule.name.startsWith('foo_')
});
```[kach/nearley#505]: https://github.com/kach/nearley/pull/505