ember-cli-nearley
v2.0.6
Published
Wrapper around nearley js to allow for language creation / parsing in ember js
Downloads
6
Maintainers
Readme
ember-cli-nearley
Simple Wrapper around Nearley. This provides a service that can be used to parse source code and also automatically compiles the index.ne file in app/grammar/
Installation
ember install ember-cli-nearley
Usage
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
<div>
{{#nearley-parse
value=(concat input1 operator input2)
as |computed|}}
Result: {{computed}}
{{/nearley-parse}}
</div>
- Note this also includes Moo for tokenizing if needed
- To use tokens from a different file file must be called
tokens.js
withinapp/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);
%}
# Pass your lexer object using the @lexer option:
@lexer lexer
Contributing
See the Contributing guide for details.
License
This project is licensed under the MIT License.