Wondering what’s next for npm?Check out our public roadmap! »

    pegjs-require-import

    0.0.6 • Public • Published

    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

    Install

    npm i pegjs-require-import

    DownloadsWeekly Downloads

    140

    Version

    0.0.6

    License

    MIT

    Unpacked Size

    7.18 kB

    Total Files

    6

    Last publish

    Collaborators

    • avatar