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

pegjs-require-import

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pegjs-require-import

PEG.js Require Extension

  • 0.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

PEG.js Require Extension

A simple require extension for PEG.js that supports importing syntax

If you're using webpack, it's recommended to use pegjs-import-loader

Install

npm install --save-dev pegjs-require-import

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 syntax is the same as in pegjs-import-loader

Generate a parser in JS code using require

const pegjs_require = require('pegjs-require-import');
const parser = pegjs_require('./parser.pegjs', {
  format: 'commonjs',
  dependencies: {
    _: 'lodash'
  }
});
const result = parser.parse(content);

API

pegjs_require(file_path, options)

options

Type: object
See more about PEG.js options

Keywords

FAQs

Package last updated on 02 Aug 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