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

nearley

Package Overview
Dependencies
Maintainers
2
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nearley - npm Package Compare versions

Comparing version 2.19.0 to 2.19.1

44

lib/nearley.js

@@ -350,10 +350,9 @@ (function(root, factory) {

});
// Display a "state stack" for each expectant state
// - which shows you how this state came to be, step by step.
// - which shows you how this state came to be, step by step.
// If there is more than one derivation, we only display the first one.
var stateStacks = expectantStates
.map(function(state) {
var stacks = this.buildStateStacks(state, []);
return stacks[0];
return this.buildFirstStateStack(state, []);
}, this);

@@ -368,3 +367,3 @@ // Display each state that is expecting a terminal symbol next.

}, this);
lines.push("");

@@ -409,32 +408,29 @@ return lines.join("\n");

/*
Builds a number of "state stacks". You can think of a state stack as the call stack
Builds a the first state stack. You can think of a state stack as the call stack
of the recursive-descent parser which the Nearley parse algorithm simulates.
A state stack is represented as an array of state objects. Within a
A state stack is represented as an array of state objects. Within a
state stack, the first item of the array will be the starting
state, with each successive item in the array going further back into history.
This function needs to be given a starting state and an empty array representing
the visited states, and it returns an array of state stacks.
the visited states, and it returns an single state stack.
*/
Parser.prototype.buildStateStacks = function(state, visited) {
Parser.prototype.buildFirstStateStack = function(state, visited) {
if (visited.indexOf(state) !== -1) {
// Found cycle, return empty array (meaning no stacks)
// Found cycle, return null
// to eliminate this path from the results, because
// we don't know how to display it meaningfully
return [];
return null;
}
if (state.wantedBy.length === 0) {
return [[state]];
return [state];
}
var that = this;
return state.wantedBy.reduce(function(stacks, prevState) {
return stacks.concat(that.buildStateStacks(
prevState,
[state].concat(visited))
.map(function(stack) {
return [state].concat(stack);
}));
}, []);
var prevState = state.wantedBy[0];
var childVisited = [state].concat(visited);
var childResult = this.buildFirstStateStack(prevState, childVisited);
if (childResult === null) {
return null;
}
return [state].concat(childResult);
};

@@ -441,0 +437,0 @@

{
"name": "nearley",
"version": "2.19.0",
"version": "2.19.1",
"description": "Simple, fast, powerful parser toolkit for JavaScript.",

@@ -11,3 +11,3 @@ "main": "lib/nearley.js",

"semver": "^5.4.1",
"moo": "^0.4.3"
"moo": "^0.5.0"
},

@@ -14,0 +14,0 @@ "files": [

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