Package Exports
- pegjs-require-import
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pegjs-require-import) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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