Skip to content

devotox/ember-cli-nearley

Repository files navigation

Ember Observer Score Build Status Coverage Status NPM Version NPM Downloads Dependency Status DevDependency Status Greenkeeper

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/

DEMO

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 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);
%}
# 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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •