parcel-transformer-nearley
v1.0.5
Published
Enable Parcel support for importing compiled Nearly grammars from Nearly files
Maintainers
Readme
Parcel transformer Nearley
A Parcel plugin which adds support for importing compiled Nearly grammars. This plugin is for Parcel v2. For the first version of parcel, see parcel-plugin-nearley.
Usage
- Install
nearleyandparcel-transformer-nearleywith yarn or with npm:
yarn add nearley
yarn add -D parcel-transformer-nearleynpm install --save nearley
npm install --save-dev parcel-transformer-nearley- Create
.parcelrcnext to yourpackage.json, with the following content in it:
{
"extends": "@parcel/config-default",
"transformers": {
"*.ne": ["parcel-transformer-nearley"]
}
}- Now you can import
*.nefiles from javascript:
import { default as nearley } from "nearley"
import grammar from "./grammar.ne"
var parser = new nearley.Parser(grammar)
parser.feed("text")
// parser.results[0]
// ...- If you use TypeScript, you'll want to install
@types/nearleyand add a module type declaration somewhere in your project:
nearley.d.ts
declare module "*.ne" {
const value: nearley.Grammar
export default value
}