Comparing version 0.11.0-dev.273 to 0.11.0-dev.325
@@ -61,7 +61,40 @@ "use strict"; | ||
const extraOptions = {}; | ||
util.extend( extraOptions, config ); | ||
util.extend( extraOptions, options ); | ||
options = extraOptions; | ||
if ( config.input !== null || config.output !== null ) { | ||
// We don't want to touch the orignal config, just in case it comes from | ||
// a javascript file, in which case its possible the same object is used | ||
// for something else, somewhere else. | ||
config = util.clone( config ); | ||
const { input, output } = config; | ||
if ( input !== null ) { | ||
if ( typeof input !== "string" ) | ||
abort( "The option `input` must be a string." ); | ||
if ( inputFile !== null ) | ||
abort( `The input file is already set, cannot use: "${ input }".` ); | ||
inputFile = input; | ||
delete config.input; | ||
} | ||
if ( output !== null ) { | ||
if ( typeof output !== "string" ) | ||
abort( "The option `output` must be a string." ); | ||
outputFile = output; | ||
delete config.output; | ||
} | ||
} | ||
options = util.processOptions( config, options ); | ||
} | ||
@@ -68,0 +101,0 @@ |
"use strict"; | ||
const util = require( "../util" ); | ||
const __slice = Array.prototype.slice; | ||
@@ -20,3 +19,3 @@ // Abstract syntax tree visitor for PEG.js | ||
return fn.apply( this, arguments ); | ||
return fn.apply( this, arguments ); // eslint-disable-line prefer-rest-params | ||
@@ -49,5 +48,4 @@ } | ||
return function visitProperty( node ) { | ||
return function visitProperty( node, ...extraArgs ) { | ||
const extraArgs = __slice.call( arguments, 1 ); | ||
const value = node[ name ]; | ||
@@ -57,3 +55,3 @@ | ||
this.visit.apply( this, [ value ].concat( extraArgs ) ); | ||
this.visit( value, ...extraArgs ); | ||
@@ -71,9 +69,8 @@ else | ||
return function visitProperty( node ) { | ||
return function visitProperty( node, ...extraArgs ) { | ||
const args = __slice.call( arguments, 0 ); | ||
const children = node[ name ]; | ||
const visitor = this; | ||
const cb = args.length < 2 | ||
const cb = extraArgs.length < 1 | ||
? function withoutArgs( child ) { | ||
@@ -86,4 +83,3 @@ | ||
args[ 0 ] = child; | ||
visitor.visit.apply( visitor, args ); | ||
visitor.visit( child, ...extraArgs ); | ||
@@ -107,10 +103,7 @@ }; | ||
grammar( node ) { | ||
grammar( node, ...extraArgs ) { | ||
const args = [ void 0 ].concat( __slice.call( arguments, 1 ) ); | ||
if ( node.initializer ) { | ||
args[ 0 ] = node.initializer; | ||
this.visit.apply( this, args ); | ||
this.visit( node.initializer, ...extraArgs ); | ||
@@ -121,4 +114,3 @@ } | ||
args[ 0 ] = rule; | ||
this.visit.apply( this, args ); | ||
this.visit( rule, ...extraArgs ); | ||
@@ -125,0 +117,0 @@ } ); |
@@ -14,21 +14,9 @@ "use strict"; | ||
const inferenceMatchResult = require( "./passes/inference-match-result" ); | ||
const reportIncorrectPlucking = require( "./passes/report-incorrect-plucking" ); | ||
const Session = require( "./session" ); | ||
const util = require( "../util" ); | ||
const vm = require( "./vm" ); | ||
function processOptions( options, defaults ) { | ||
const processedOptions = {}; | ||
util.extend( processedOptions, options ); | ||
util.extend( processedOptions, defaults ); | ||
return processedOptions; | ||
} | ||
const compiler = { | ||
Session: Session, | ||
vm: vm, | ||
@@ -47,3 +35,4 @@ // Compiler passes. | ||
reportInfiniteRecursion: reportInfiniteRecursion, | ||
reportInfiniteRepetition: reportInfiniteRepetition | ||
reportInfiniteRepetition: reportInfiniteRepetition, | ||
reportIncorrectPlucking: reportIncorrectPlucking, | ||
}, | ||
@@ -69,3 +58,3 @@ transform: { | ||
options = processOptions( options, { | ||
options = util.processOptions( options, { | ||
allowedStartRules: [ ast.rules[ 0 ].name ], | ||
@@ -72,0 +61,0 @@ cache: false, |
@@ -21,2 +21,3 @@ "use strict"; | ||
TEXT: 12, // TEXT | ||
PLUCK: 41, // PLUCK n, k, p1, ..., pK | ||
@@ -23,0 +24,0 @@ // Conditions and Loops |
@@ -247,8 +247,4 @@ "use strict"; | ||
function buildSequence() { | ||
const buildSequence = ( ...parts ) => [].concat( ...parts ); | ||
return Array.prototype.concat.apply( [], arguments ); | ||
} | ||
function buildCondition( match, condCode, thenCode, elseCode ) { | ||
@@ -449,2 +445,4 @@ | ||
const TOTAL_ELEMENTS = node.elements.length; | ||
function buildElementsCode( elements, context ) { | ||
@@ -454,3 +452,3 @@ | ||
const processedCount = node.elements.length - elements.slice( 1 ).length; | ||
const processedCount = TOTAL_ELEMENTS - elements.slice( 1 ).length; | ||
@@ -461,2 +459,3 @@ return buildSequence( | ||
env: context.env, | ||
pluck: context.pluck, | ||
action: null, | ||
@@ -471,2 +470,3 @@ reportFailures: context.reportFailures | ||
env: context.env, | ||
pluck: context.pluck, | ||
action: context.action, | ||
@@ -483,15 +483,22 @@ reportFailures: context.reportFailures | ||
} else if ( context.action ) { | ||
} | ||
const functionIndex = addFunctionConst( | ||
false, | ||
Object.keys( context.env ), | ||
context.action.code | ||
if ( context.pluck.length > 0 ) | ||
return buildSequence( | ||
[ op.PLUCK, TOTAL_ELEMENTS + 1, context.pluck.length ], | ||
context.pluck.map( eSP => context.sp - eSP ) | ||
); | ||
if ( context.action ) | ||
return buildSequence( | ||
[ op.LOAD_SAVED_POS, node.elements.length ], | ||
[ op.LOAD_SAVED_POS, TOTAL_ELEMENTS ], | ||
buildCall( | ||
functionIndex, | ||
node.elements.length + 1, | ||
addFunctionConst( // functionIndex | ||
false, | ||
Object.keys( context.env ), | ||
context.action.code | ||
), | ||
TOTAL_ELEMENTS + 1, | ||
context.env, | ||
@@ -502,4 +509,3 @@ context.sp | ||
} | ||
return buildSequence( [ op.WRAP, node.elements.length ], [ op.NIP ] ); | ||
return buildSequence( [ op.WRAP, TOTAL_ELEMENTS ], [ op.NIP ] ); | ||
@@ -513,2 +519,3 @@ } | ||
env: context.env, | ||
pluck: [], | ||
action: context.action, | ||
@@ -523,6 +530,17 @@ reportFailures: context.reportFailures | ||
const env = util.clone( context.env ); | ||
let env = context.env; | ||
const label = node.label; | ||
const sp = context.sp + 1; | ||
context.env[ node.label ] = context.sp + 1; | ||
if ( label !== null ) { | ||
env = util.clone( context.env ); | ||
context.env[ label ] = sp; | ||
} | ||
if ( context.pluck && node.pick ) | ||
context.pluck.push( sp ); | ||
return generate( node.expression, { | ||
@@ -529,0 +547,0 @@ sp: context.sp, |
@@ -12,47 +12,32 @@ "use strict"; | ||
function replaceRuleRefs( ast, from, to ) { | ||
const replaceRuleRefs = session.buildVisitor( { | ||
const replace = session.buildVisitor( { | ||
rule_ref( node ) { | ||
rule_ref( node, proxy, real ) { | ||
if ( node.name === from ) { | ||
if ( node.name === proxy ) node.name = real; | ||
node.name = to; | ||
} | ||
} | ||
} ); | ||
} | ||
} ); | ||
const allowedStartRules = options.allowedStartRules; | ||
const rules = []; | ||
replace( ast ); | ||
for ( const rule of ast.rules ) { | ||
} | ||
const indices = []; | ||
ast.rules.forEach( ( rule, i ) => { | ||
if ( isProxyRule( rule ) ) { | ||
replaceRuleRefs( ast, rule.name, rule.expression.name ); | ||
if ( options.allowedStartRules.indexOf( rule.name ) === -1 ) { | ||
if ( allowedStartRules.indexOf( rule.name ) < 0 ) continue; | ||
indices.push( i ); | ||
} | ||
} | ||
} ); | ||
rules.push( rule ); | ||
indices.reverse(); | ||
} | ||
indices.forEach( i => { | ||
ast.rules = rules; | ||
ast.rules.splice( i, 1 ); | ||
} ); | ||
} | ||
module.exports = removeProxyRules; |
@@ -40,3 +40,3 @@ "use strict"; | ||
if ( __hasOwnProperty.call( env, label ) ) { | ||
if ( label && __hasOwnProperty.call( env, label ) ) { | ||
@@ -53,4 +53,5 @@ const start = env[ label ].start; | ||
check( node.expression, env ); | ||
env[ label ] = node.location; | ||
if ( label ) env[ label ] = node.location; | ||
}, | ||
@@ -57,0 +58,0 @@ |
@@ -9,3 +9,3 @@ /* eslint no-unused-vars: 0 */ | ||
const parser = require( "../parser" ); | ||
const vm = require( "./vm" ); | ||
const util = require( "../util" ); | ||
@@ -32,3 +32,5 @@ function fatal( message, location ) { | ||
this.visitor = config.visitor || ast.visitor; | ||
this.vm = config.vm || vm; | ||
this.vm = config.vm || { | ||
runInContext: util.runInContext | ||
}; | ||
@@ -35,0 +37,0 @@ if ( typeof config.warn === "function" ) this.warn = config.warn; |
@@ -11,3 +11,3 @@ "use strict"; | ||
// PEG.js version (uses semantic versioning). | ||
VERSION: "0.11.0-dev", | ||
VERSION: require( "../package.json" ).version, | ||
@@ -33,3 +33,2 @@ GrammarError: GrammarError, | ||
const plugins = "plugins" in options ? options.plugins : []; | ||
const session = new compiler.Session( { | ||
@@ -39,8 +38,12 @@ passes: util.convertPasses( compiler.passes ) | ||
plugins.forEach( p => { | ||
if ( Array.isArray( options.plugins ) ) | ||
p.use( session, options ); | ||
options.plugins.forEach( p => { | ||
} ); | ||
if ( typeof p.use !== "function" ) return; | ||
p.use( session, options ); | ||
} ); | ||
return compiler.compile( | ||
@@ -47,0 +50,0 @@ session.parse( grammar, options.parser || {} ), |
"use strict"; | ||
const js = require( "./js" ); | ||
const objects = require( "./objects" ); | ||
const vm = require( "./vm" ); | ||
objects.extend( exports, js ); | ||
objects.extend( exports, objects ); | ||
objects.extend( exports, vm ); | ||
exports.noop = function noop() { }; | ||
exports.convertPasses = require( "./convert-passes" ); | ||
/** | ||
* ```ts | ||
* type Session = peg.compiler.Session; | ||
* type Pass = ( ast: {}, session: Session, options: {} ) => void; | ||
* type StageMap = { [string]: { [string]: Pass } }; | ||
* type PassMap = { [string]: Pass[] }; | ||
* ``` | ||
* | ||
* The PEG.js compiler runs each `Pass` on the `PassMap` (the `passes` option on it's 2nd | ||
* argument), but the compiler api exposes a `StageMap` so that it is easier for plugin | ||
* developer's to access the built-in passes. | ||
* | ||
* This method takes a `StageMap`, returning a `PassMap` that can be used by the compiler. | ||
*/ | ||
exports.convertPasses = ( () => { | ||
objects.extend( exports, objects ); | ||
function convertStage( passes ) { | ||
return Array.isArray( passes ) | ||
? passes | ||
: objects.values( passes ); | ||
} | ||
function convertPasses( stages ) { | ||
return objects.map( stages, convertStage ); | ||
} | ||
return convertPasses; | ||
} )(); | ||
exports.processOptions = function processOptions( options, defaults ) { | ||
const processedOptions = {}; | ||
objects.extend( processedOptions, options ); | ||
objects.extend( processedOptions, defaults ); | ||
return processedOptions; | ||
}; |
{ | ||
"name": "pegjs", | ||
"version": "0.11.0-dev.273", | ||
"version": "0.11.0-dev.325", | ||
"description": "Parser generator for JavaScript", | ||
"keywords": [ | ||
"parser generator", | ||
"PEG.js", | ||
"pegjs", | ||
"grammar", | ||
"parser", | ||
"generator", | ||
"language", | ||
"PEG" | ||
@@ -16,51 +21,8 @@ ], | ||
], | ||
"files": [ | ||
"bin", | ||
"lib", | ||
"!lib/.eslintrc.js" | ||
], | ||
"types": "lib/typings/pegjs.d.ts", | ||
"types": "typings/pegjs.d.ts", | ||
"main": "lib/peg.js", | ||
"bin": "bin/peg.js", | ||
"scripts": { | ||
"lint": "gulp lint", | ||
"spec": "gulp test", | ||
"benchmark": "gulp benchmark", | ||
"build:parser": "gulp build:parser", | ||
"build:browser": "gulp build:browser", | ||
"clean": "gulp clean", | ||
"test:impact": "node test/impact master", | ||
"test:server": "node test/server/run", | ||
"test": "nyc gulp", | ||
"coverage": "nyc report --reporter=text-lcov | coveralls" | ||
}, | ||
"devDependencies": { | ||
"babel-core": "6.26.0", | ||
"babel-preset-env": "1.6.1", | ||
"babelify": "8.0.0", | ||
"browserify": "16.1.1", | ||
"chai": "4.1.2", | ||
"chai-like": "1.1.1", | ||
"coveralls": "3.0.0", | ||
"dedent": "0.7.0", | ||
"del": "3.0.0", | ||
"eslint-config-futagozaryuu": "4.17.x", | ||
"express": "4.16.3", | ||
"glob": "7.1.2", | ||
"gulp": "4.0.0", | ||
"gulp-eslint": "4.0.2", | ||
"gulp-header": "2.0.5", | ||
"gulp-mocha": "5.0.0", | ||
"gulp-rename": "1.2.2", | ||
"gulp-uglify": "3.0.0", | ||
"morgan": "1.9.0", | ||
"nyc": "11.6.0", | ||
"pump": "3.0.0", | ||
"sinon": "4.4.6", | ||
"vinyl-buffer": "1.0.1", | ||
"vinyl-source-stream": "2.0.0" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
"node": ">= 6" | ||
} | ||
} |
[![ci](https://img.shields.io/travis/pegjs/pegjs.svg)](https://travis-ci.org/pegjs/pegjs) | ||
[![coverage](https://img.shields.io/coveralls/github/pegjs/pegjs.svg)](https://coveralls.io/github/pegjs/pegjs) | ||
[![release](https://img.shields.io/npm/v/pegjs.svg)](https://www.npmjs.com/package/pegjs) | ||
[![dev](https://img.shields.io/npm/v/pegjs/dev.svg)](https://github.com/pegjs/pegjs) | ||
[![bower](https://img.shields.io/bower/v/pegjs.svg)](https://github.com/pegjs/bower) | ||
[![license](https://img.shields.io/badge/license-mit-blue.svg)](https://opensource.org/licenses/MIT) | ||
@@ -7,0 +4,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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
7251
0
255620
36
36