ember-cli-nearley
Version:
Wrapper around nearley js to allow for language creation / parsing in ember js
83 lines (62 loc) • 2.84 kB
Markdown
[](http://emberobserver.com/addons/ember-cli-nearley)
[](http://travis-ci.org/devotox/ember-cli-nearley)
[](https://codecov.io/gh/devotox/ember-cli-nearley)
[](http://badge.fury.io/js/ember-cli-nearley)
[](https://www.npmjs.org/package/ember-cli-nearley)
[](https://david-dm.org/poetic/ember-cli-nearley)
[](https://david-dm.org/poetic/ember-cli-nearley#info=devDependencies)
[](https://greenkeeper.io/)
ember-cli-nearley
==============================================================================
Simple Wrapper around [Nearley](https://github.com/Hardmath123/nearley).
This provides a service that can be used to parse source code and also automatically compiles
the index.ne file in app/grammar/
[](https://devotox.github.io/ember-cli-nearley)
Installation
------------------------------------------------------------------------------
```
ember install ember-cli-nearley
```
Usage
------------------------------------------------------------------------------
```js
import Route from '@ember/routing/route';
import { inject } from '@ember/service';
export default Route.extend({
nearley: inject(),
actions: {
onClick() {
let value = this.controller.get('value');
this.get('nearley').parse(value);
}
}
});
```
OR
```hbs
<div>
{{
value=(concat input1 operator input2)
as |computed|}}
Result: {{computed}}
{{/nearley-parse}}
</div>
```
* Note this also includes [Moo](https://github.com/no-context/moo) for tokenizing if needed
* To use tokens from a different file file must be called `tokens.js` within `app/grammar` directory
* and in your index.ne you must do this below. grammar-tokens is a shim created to allow you to import into your grammar.js file created from index.ne
```
@{%
let moo = require('moo').default;
let tokens = require('grammar-tokens').default;
let lexer = moo.compile(tokens);
%}
@lexer lexer
```
Contributing
------------------------------------------------------------------------------
See the [Contributing](CONTRIBUTING.md) guide for details.
License
------------------------------------------------------------------------------
This project is licensed under the [MIT License](LICENSE.md).