Comparing version 0.11.0-dev.325 to 0.11.0-master.f69239d
@@ -30,3 +30,3 @@ "use strict"; | ||
return this.rules.find( rule => rule.name === name ); | ||
return util.find( this.rules, rule => rule.name === name ); | ||
@@ -37,12 +37,4 @@ } | ||
const rules = this.rules; | ||
return util.findIndex( this.rules, rule => rule.name === name ); | ||
for ( let i = 0; i < rules.length; ++i ) { | ||
if ( rules[ i ].name === name ) return i; | ||
} | ||
return -1; | ||
} | ||
@@ -49,0 +41,0 @@ |
@@ -52,6 +52,4 @@ "use strict"; | ||
// cause its malfunction. | ||
compile( ast, session, options ) { | ||
compile( ast, session, options = {} ) { | ||
options = typeof options !== "undefined" ? options : {}; | ||
options = util.processOptions( options, { | ||
@@ -71,2 +69,5 @@ allowedStartRules: [ ast.rules[ 0 ].name ], | ||
// We want `session.vm.evalModule` to return the parser | ||
if ( options.output === "parser" ) options.format = "umd"; | ||
util.each( session.passes, stage => { | ||
@@ -85,3 +86,3 @@ | ||
case "parser": | ||
return session.vm.runInContext( ast.code, options.context ); | ||
return session.vm.evalModule( ast.code, options.context ); | ||
@@ -88,0 +89,0 @@ case "source": |
@@ -225,3 +225,3 @@ "use strict"; | ||
const pattern = JSON.stringify( cls ); | ||
const index = classes.findIndex( c => JSON.stringify( c ) === pattern ); | ||
const index = util.findIndex( classes, c => JSON.stringify( c ) === pattern ); | ||
return index === -1 ? classes.push( cls ) - 1 : index; | ||
@@ -234,3 +234,3 @@ | ||
const pattern = JSON.stringify( expected ); | ||
const index = expectations.findIndex( e => JSON.stringify( e ) === pattern ); | ||
const index = util.findIndex( expectations, e => JSON.stringify( e ) === pattern ); | ||
return index === -1 ? expectations.push( expected ) - 1 : index; | ||
@@ -244,3 +244,3 @@ | ||
const pattern = JSON.stringify( func ); | ||
const index = functions.findIndex( f => JSON.stringify( f ) === pattern ); | ||
const index = util.findIndex( functions, f => JSON.stringify( f ) === pattern ); | ||
return index === -1 ? functions.push( func ) - 1 : index; | ||
@@ -247,0 +247,0 @@ |
@@ -25,3 +25,3 @@ "use strict"; | ||
for ( const rule of ast.rules ) { | ||
ast.rules.forEach( rule => { | ||
@@ -31,3 +31,3 @@ if ( isProxyRule( rule ) ) { | ||
replaceRuleRefs( ast, rule.name, rule.expression.name ); | ||
if ( allowedStartRules.indexOf( rule.name ) < 0 ) continue; | ||
if ( allowedStartRules.indexOf( rule.name ) < 0 ) return; | ||
@@ -38,3 +38,3 @@ } | ||
} | ||
} ); | ||
@@ -41,0 +41,0 @@ ast.rules = rules; |
@@ -1,3 +0,1 @@ | ||
/* eslint no-unused-vars: 0 */ | ||
"use strict"; | ||
@@ -10,2 +8,3 @@ | ||
const util = require( "../util" ); | ||
const vm = require( "../util/vm" ); | ||
@@ -24,6 +23,4 @@ function fatal( message, location ) { | ||
constructor( config ) { | ||
constructor( config = {} ) { | ||
config = typeof config !== "undefined" ? config : {}; | ||
this.opcodes = config.opcodes || opcodes; | ||
@@ -33,5 +30,3 @@ this.parser = config.parser || parser; | ||
this.visitor = config.visitor || ast.visitor; | ||
this.vm = config.vm || { | ||
runInContext: util.runInContext | ||
}; | ||
this.vm = config.vm || vm; | ||
@@ -57,3 +52,3 @@ if ( typeof config.warn === "function" ) this.warn = config.warn; | ||
warn( message, location ) {} | ||
warn( _message, _location ) {} | ||
@@ -60,0 +55,0 @@ error( message, location ) { |
@@ -28,6 +28,4 @@ "use strict"; | ||
// generated parser and cause its malfunction. | ||
generate( grammar, options ) { | ||
generate( grammar, options = {} ) { | ||
options = typeof options !== "undefined" ? options : {}; | ||
const session = new compiler.Session( { | ||
@@ -34,0 +32,0 @@ passes: util.convertPasses( compiler.passes ) |
"use strict"; | ||
const arrays = require( "./arrays" ); | ||
const js = require( "./js" ); | ||
@@ -7,8 +8,2 @@ const objects = require( "./objects" ); | ||
objects.extend( exports, js ); | ||
objects.extend( exports, objects ); | ||
objects.extend( exports, vm ); | ||
exports.noop = function noop() { }; | ||
/** | ||
@@ -28,3 +23,3 @@ * ```ts | ||
*/ | ||
exports.convertPasses = ( () => { | ||
const convertPasses = ( () => { | ||
@@ -49,3 +44,3 @@ function convertStage( passes ) { | ||
exports.processOptions = function processOptions( options, defaults ) { | ||
function processOptions( options, defaults ) { | ||
@@ -59,2 +54,26 @@ const processedOptions = {}; | ||
} | ||
module.exports = { | ||
find: arrays.find, | ||
findIndex: arrays.findIndex, | ||
stringEscape: js.stringEscape, | ||
regexpEscape: js.regexpEscape, | ||
reservedWords: js.reservedWords, | ||
clone: objects.clone, | ||
each: objects.each, | ||
extend: objects.extend, | ||
map: objects.map, | ||
values: objects.values, | ||
enforceFastProperties: objects.enforceFastProperties, | ||
evalModule: vm.evalModule, | ||
convertPasses, | ||
processOptions, | ||
noop() { }, | ||
}; |
"use strict"; | ||
const code = ( () => { | ||
/** | ||
* `eval` the given source as a CommonJS module, using properties found in `context` as top-level variables. | ||
* | ||
* Based on `vm.runInContext` found in Node.js, this is a cross-env solution. | ||
*/ | ||
function evalModule( source, context ) { | ||
let preface = ""; | ||
const MODULE_VARS = { | ||
const argumentKeys = Object.keys( context ); | ||
const argumentValues = argumentKeys.map( argument => context[ argument ] ); | ||
"module": true, | ||
"process": true, | ||
"code": true, | ||
"runInContext": true, | ||
"source": true, | ||
"preface": true, | ||
const sandbox = { exports: {} }; | ||
argumentKeys.push( "module", "exports", source ); | ||
argumentValues.push( sandbox, sandbox.exports ); | ||
}; | ||
Function( ...argumentKeys )( ...argumentValues ); | ||
Object.keys( MODULE_VARS ).forEach( name => { | ||
return sandbox.exports; | ||
preface += `var ${ name } = void 0;`; | ||
} | ||
} ); | ||
// Exports | ||
function generate( name ) { | ||
return `${ ( MODULE_VARS[ name ] ? "" : "var " ) + name } = __context.${ name };`; | ||
} | ||
return { generate, preface }; | ||
} )(); | ||
module.exports = { | ||
// `eval` the given source, using properties found in `context` as top-level | ||
// variables, while hiding some variables in this module from the source. | ||
// | ||
// Based on `vm.runInContext` found in Node.js, this is a cross-env solution. | ||
runInContext( source, __context ) { | ||
let preface = code.preface; | ||
if ( typeof __context === "object" ) { | ||
Object.keys( __context ).forEach( name => { | ||
preface += code.generate( name ); | ||
} ); | ||
} | ||
return eval( preface + source ); | ||
}, | ||
}; | ||
module.exports = { evalModule }; |
{ | ||
"name": "pegjs", | ||
"version": "0.11.0-dev.325", | ||
"description": "Parser generator for JavaScript", | ||
"keywords": [ | ||
"PEG.js", | ||
"pegjs", | ||
"grammar", | ||
"parser", | ||
"generator", | ||
"language", | ||
"PEG" | ||
], | ||
"homepage": "https://pegjs.org/", | ||
"repository": "pegjs/pegjs", | ||
"license": "MIT", | ||
"contributors": [ | ||
"David Majda <david@majda.cz> (https://majda.cz/)", | ||
"Futago-za Ryuu <futagoza.ryuu@gmail.com>" | ||
], | ||
"types": "typings/pegjs.d.ts", | ||
"main": "lib/peg.js", | ||
"bin": "bin/peg.js", | ||
"engines": { | ||
"node": ">= 6" | ||
} | ||
"name": "pegjs", | ||
"version": "0.11.0-master.f69239d", | ||
"description": "Parser generator for JavaScript", | ||
"keywords": [ | ||
"PEG.js", | ||
"pegjs", | ||
"grammar", | ||
"parser", | ||
"generator", | ||
"language", | ||
"PEG" | ||
], | ||
"homepage": "https://pegjs.org/", | ||
"repository": "pegjs/pegjs", | ||
"license": "MIT", | ||
"contributors": [ | ||
"David Majda <david@majda.cz> (https://majda.cz/)", | ||
"Futago-za Ryuu <futagoza.ryuu@gmail.com>" | ||
], | ||
"types": "typings/pegjs.d.ts", | ||
"main": "lib/peg.js", | ||
"bin": "bin/peg.js", | ||
"engines": { | ||
"node": ">= 6" | ||
} | ||
} |
@@ -1,3 +0,4 @@ | ||
[![ci](https://img.shields.io/travis/pegjs/pegjs.svg)](https://travis-ci.org/pegjs/pegjs) | ||
[![Build Status](https://dev.azure.com/pegjs/pegjs/_apis/build/status/Azure%20Pipelines?branchName=master)](https://dev.azure.com/pegjs/pegjs/_build/latest?definitionId=1?branchName=master) | ||
[![coverage](https://img.shields.io/coveralls/github/pegjs/pegjs.svg)](https://coveralls.io/github/pegjs/pegjs) | ||
[![Maintainability](https://api.codeclimate.com/v1/badges/2d1f0313dea3e28e191f/maintainability)](https://codeclimate.com/github/pegjs/pegjs/maintainability) | ||
[![license](https://img.shields.io/badge/license-mit-blue.svg)](https://opensource.org/licenses/MIT) | ||
@@ -4,0 +5,0 @@ |
@@ -198,2 +198,3 @@ import gp from "./generated-parser"; | ||
type: "labeled"; | ||
pick?: true; | ||
label: string; | ||
@@ -438,3 +439,3 @@ expression: ( | ||
runInContext( code: string, vm$context?: { [ name: string ]: any; } ): any; | ||
evalModule( code: string, context?: { [ name: string ]: any; } ): any; | ||
@@ -486,2 +487,3 @@ } | ||
function reportInfiniteRepetition( ast: Grammar, session: Session ): void; | ||
function reportIncorrectPlucking( ast: Grammar, session: Session ): void; | ||
@@ -541,2 +543,8 @@ } | ||
interface IArrayUtils { | ||
findIndex( array: any[], condition: IIterator ): number; | ||
find( array: any[], condition: IIterator ): any; | ||
} | ||
interface IJavaScriptUtils { | ||
@@ -559,3 +567,3 @@ | ||
} | ||
interface util extends IJavaScriptUtils, IObjectUtils, compiler.ISessionVM { | ||
interface util extends IArrayUtils, IJavaScriptUtils, IObjectUtils, compiler.ISessionVM { | ||
@@ -562,0 +570,0 @@ noop(): void; |
@@ -21,2 +21,3 @@ export = generatedparser; | ||
filename?: string; | ||
start: SourcePosition; | ||
@@ -23,0 +24,0 @@ end: SourcePosition; |
@@ -118,2 +118,8 @@ /// <reference path="./api.d.ts" /> | ||
declare module "pegjs/lib/compiler/passes/report-incorrect-plucking" { | ||
export default peg.compiler.passes.check.reportIncorrectPlucking; | ||
} | ||
declare module "pegjs/lib/compiler/passes/report-infinite-recursion" { | ||
@@ -149,2 +155,9 @@ | ||
declare module "pegjs/lib/util/arrays" { | ||
const arrays: peg.IArrayUtils; | ||
export default arrays; | ||
} | ||
declare module "pegjs/lib/util/index" { | ||
@@ -151,0 +164,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1813008
41
16275
37