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/
ember install ember-cli-nearley
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
- 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
See the Contributing guide for details.
This project is licensed under the MIT License.