Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pegjs-import-loader

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pegjs-import-loader

PEG.js import loader for webpack

  • 0.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

PEG.js import loader for webpack

Build Status Coverage Status npm version npm license

A simple loader for PEG.js that supports importing multiple grammars from different PEG.js files

Install

npm install --save-dev pegjs-import-loader pegjs webpack

Setup

Apply via webpack config

webpack.config.js:

module.exports = {
  ...
  module: {
    loaders: [
      {
        test: /\.pegjs$/,
        loader: 'pegjs-import-loader',
        options: { 
            ...
        }
      }
    ]
  }
};

PEG.js options

You can pass options to PEG.js through options property in webpack config. See more about PEG.js options

Usage

Importing Syntax

parser.pegjs:

{
    const str = 'This is just an example string';
    function concat(a, b) {
        return a.concat(b);
    }
}
Expression
  = head:Term tail:(_ ("+" / "-") _ Term)* {
      return tail.reduce(function(result, element) {
        if (element[1] === "+") { return result + element[3]; }
        if (element[1] === "-") { return result - element[3]; }
      }, head);
    }
    
Factor
  = "(" _ expr:Expression _ ")" { return expr; }
  / Integer
 
@import './base-rules.pegjs'
@import './keywords.pegjs'
  • Import statement must be after the initializer block of PEG.js (initializer is a piece of JavaScript code in curly braces (“{” and “}”) that precedes the first rule)
  • When importing grammars from other files, all the rules in those files are accessible in the current context
  • All the JS variables and functions in initializers will also be accessible from the current context
  • Due to the accessibility of all the rules, variables and functions from other pegjs files in current context, users must be aware of duplication of rule, variable and function names
  • Import files in one-way flow to avoid circular dependencies

Generate a parser in JS code

const parser = require('./parser.pegjs');
const result = parser.parse(content);

License

MIT (https://opensource.org/licenses/mit-license.php)

Keywords

FAQs

Package last updated on 14 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc