Socket
Socket
Sign inDemoInstall

parsimmon

Package Overview
Dependencies
Maintainers
3
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parsimmon - npm Package Compare versions

Comparing version 0.8.0 to 0.8.1

18

build/parsimmon.browser.js

@@ -62,3 +62,3 @@ // This unsightly UMD-module header is here to make this code work without

var expected = (result.furthest === last.furthest)
? union(result.expected, last.expected)
? unsafeUnion(result.expected, last.expected)
: last.expected;

@@ -75,13 +75,15 @@

// Returns the sorted set union of two arrays of strings
function union(xs, ys) {
// Returns the sorted set union of two arrays of strings. Note that if both
// arrays are empty, it simply returns the first array, and if exactly one
// array is empty, it returns the other one unsorted. This is safe because
// expectation arrays always start as [] or [x], so as long as we merge with
// this function, we know they stay in sorted order.
function unsafeUnion(xs, ys) {
// Exit early if either array is empty (common case)
var xn = xs.length;
var yn = ys.length;
if (xn === 0 && yn === 0) {
return [];
} else if (xn === 0) {
return ys.slice().sort();
if (xn === 0) {
return ys;
} else if (yn === 0) {
return xs.slice().sort();
return xs;
}

@@ -88,0 +90,0 @@ // Two non-empty arrays: do the full algorithm

@@ -1,1 +0,1 @@

(function(r,t){if(typeof define==="function"&&define.amd){define([],t)}else if(typeof module==="object"&&module.exports){module.exports=t()}else{r.Parsimmon=t()}})(this,function(){"use strict";var r={};function t(r){if(!(this instanceof t))return new t(r);this._=r}r.Parser=t;var n=t.prototype;function e(r,t){return{status:true,index:r,value:t,furthest:-1,expected:[]}}function u(r,t){return{status:false,index:-1,value:null,furthest:r,expected:[t]}}function i(r,t){if(!t)return r;if(r.furthest>t.furthest)return r;var n=r.furthest===t.furthest?a(r.expected,t.expected):t.expected;return{status:r.status,index:r.index,value:r.value,furthest:t.furthest,expected:n}}function a(r,t){var n=r.length;var e=t.length;if(n===0&&e===0){return[]}else if(n===0){return t.slice().sort()}else if(e===0){return r.slice().sort()}var u={};for(var i=0;i<n;i++){u[r[i]]=true}for(var i=0;i<e;i++){u[t[i]]=true}var a=[];for(var f in u){if(u.hasOwnProperty(f)){a.push(f)}}a.sort();return a}function f(r){if(!(r instanceof t))throw new Error("not a parser: "+r)}function o(r){if(typeof r!=="number")throw new Error("not a number: "+r)}function s(r){if(!(r instanceof RegExp))throw new Error("not a regex: "+r)}function c(r){if(typeof r!=="function")throw new Error("not a function: "+r)}function l(r){if(typeof r!=="string")throw new Error("not a string: "+r)}function v(r){if(r.length===1)return r[0];return"one of "+r.join(", ")}function h(r,t){var n=t.index;var e=n.offset;if(e===r.length)return", got the end of the stream";var u=e>0?"'...":"'";var i=r.length-e>12?"...'":"'";return" at line "+n.line+" column "+n.column+", got "+u+r.slice(e,e+12)+i}var p=r.formatError=function(r,t){return"expected "+v(t.expected)+h(r,t)};n.parse=function(r){if(typeof r!=="string"){throw new Error(".parse must be called with a string as its argument")}var t=this.skip(R)._(r,0);return t.status?{status:true,value:t.value}:{status:false,index:D(r,t.furthest),expected:t.expected}};var d=r.seq=function(){var r=[].slice.call(arguments);var n=r.length;for(var u=0;u<n;u+=1){f(r[u])}return t(function(t,u){var a;var f=new Array(n);for(var o=0;o<n;o+=1){a=i(r[o]._(t,u),a);if(!a.status)return a;f[o]=a.value;u=a.index}return i(e(u,f),a)})};var g=r.seqMap=function(){var r=[].slice.call(arguments);var t=r.pop();return d.apply(null,r).map(function(r){return t.apply(null,r)})};var x=r.custom=function(r){return t(r(e,u))};var m=r.alt=function(){var r=[].slice.call(arguments);var n=r.length;if(n===0)return b("zero alternates");for(var e=0;e<n;e+=1){f(r[e])}return t(function(t,n){var e;for(var u=0;u<r.length;u+=1){e=i(r[u]._(t,n),e);if(e.status)return e}return e})};var y=r.sepBy=function(t,n){return w(t,n).or(r.of([]))};var w=r.sepBy1=function(r,t){f(r);f(t);var n=t.then(r).many();return r.chain(function(r){return n.map(function(t){return[r].concat(t)})})};n.or=function(r){return m(this,r)};n.then=function(r){if(typeof r==="function"){throw new Error("chaining features of .then are no longer supported, use .chain instead")}f(r);return d(this,r).map(function(r){return r[1]})};n.many=function(){var r=this;return t(function(t,n){var u=[];var a;var f;for(;;){a=i(r._(t,n),a);if(a.status){n=a.index;u.push(a.value)}else{return i(e(n,u),a)}}})};n.times=function(r,n){if(arguments.length<2)n=r;var u=this;o(r);o(n);return t(function(t,a){var f=[];var o=a;var s;var c;for(var l=0;l<r;l+=1){s=u._(t,a);c=i(s,c);if(s.status){a=s.index;f.push(s.value)}else return c}for(;l<n;l+=1){s=u._(t,a);c=i(s,c);if(s.status){a=s.index;f.push(s.value)}else break}return i(e(a,f),c)})};n.result=function(r){return this.map(function(t){return r})};n.atMost=function(r){return this.times(0,r)};n.atLeast=function(r){var t=this;return g(this.times(r),this.many(),function(r,t){return r.concat(t)})};n.map=function(r){c(r);var n=this;return t(function(t,u){var a=n._(t,u);if(!a.status)return a;return i(e(a.index,r(a.value)),a)})};n.skip=function(r){return d(this,r).map(function(r){return r[0]})};n.mark=function(){return g(G,this,G,function(r,t,n){return{start:r,value:t,end:n}})};n.desc=function(r){var n=this;return t(function(t,e){var u=n._(t,e);if(!u.status)u.expected=[r];return u})};var _=r.string=function(r){var n=r.length;var i="'"+r+"'";l(r);return t(function(t,a){var f=t.slice(a,a+n);if(f===r){return e(a+n,f)}else{return u(a,i)}})};var E=r.regex=function(r,n){s(r);if(n)o(n);var i=RegExp("^(?:"+r.source+")",(""+r).slice((""+r).lastIndexOf("/")+1));var a=""+r;if(n==null)n=0;return t(function(r,t){var f=i.exec(r.slice(t));if(f){var o=f[0];var s=f[n];if(s!=null)return e(t+o.length,s)}return u(t,a)})};var O=r.succeed=function(r){return t(function(t,n){return e(n,r)})};var b=r.fail=function(r){return t(function(t,n){return u(n,r)})};var k=r.letter=E(/[a-z]/i).desc("a letter");var z=r.letters=E(/[a-z]*/i);var A=r.digit=E(/[0-9]/).desc("a digit");var P=r.digits=E(/[0-9]*/);var j=r.whitespace=E(/\s+/).desc("whitespace");var q=r.optWhitespace=E(/\s*/);var B=r.any=t(function(r,t){if(t>=r.length)return u(t,"any character");return e(t+1,r.charAt(t))});var M=r.all=t(function(r,t){return e(r.length,r.slice(t))});var R=r.eof=t(function(r,t){if(t<r.length)return u(t,"EOF");return e(t,null)});var W=r.test=function(r){c(r);return t(function(t,n){var i=t.charAt(n);if(n<t.length&&r(i)){return e(n+1,i)}else{return u(n,"a character matching "+r)}})};var F=r.oneOf=function(r){return W(function(t){return r.indexOf(t)>=0})};var I=r.noneOf=function(r){return W(function(t){return r.indexOf(t)<0})};var L=r.takeWhile=function(r){c(r);return t(function(t,n){var u=n;while(u<t.length&&r(t.charAt(u)))u+=1;return e(u,t.slice(n,u))})};var C=r.lazy=function(r,n){if(arguments.length<2){n=r;r=undefined}var e=t(function(r,t){e._=n()._;return e._(r,t)});if(r)e=e.desc(r);return e};var D=function(r,t){var n=r.slice(0,t).split("\n");var e=n.length;var u=n[n.length-1].length+1;return{offset:t,line:e,column:u}};var G=r.index=t(function(r,t){return e(t,D(r,t))});n.concat=n.or;n.empty=b("empty");n.of=t.of=r.of=O;n.ap=function(r){return g(this,r,function(r,t){return r(t)})};n.chain=function(r){var n=this;return t(function(t,e){var u=n._(t,e);if(!u.status)return u;var a=r(u.value);return i(a._(t,u.index),u)})};return r});
(function(r,t){if(typeof define==="function"&&define.amd){define([],t)}else if(typeof module==="object"&&module.exports){module.exports=t()}else{r.Parsimmon=t()}})(this,function(){"use strict";var r={};function t(r){if(!(this instanceof t))return new t(r);this._=r}r.Parser=t;var n=t.prototype;function e(r,t){return{status:true,index:r,value:t,furthest:-1,expected:[]}}function u(r,t){return{status:false,index:-1,value:null,furthest:r,expected:[t]}}function i(r,t){if(!t)return r;if(r.furthest>t.furthest)return r;var n=r.furthest===t.furthest?a(r.expected,t.expected):t.expected;return{status:r.status,index:r.index,value:r.value,furthest:t.furthest,expected:n}}function a(r,t){var n=r.length;var e=t.length;if(n===0){return t}else if(e===0){return r}var u={};for(var i=0;i<n;i++){u[r[i]]=true}for(var i=0;i<e;i++){u[t[i]]=true}var a=[];for(var f in u){if(u.hasOwnProperty(f)){a.push(f)}}a.sort();return a}function f(r){if(!(r instanceof t))throw new Error("not a parser: "+r)}function o(r){if(typeof r!=="number")throw new Error("not a number: "+r)}function s(r){if(!(r instanceof RegExp))throw new Error("not a regex: "+r)}function c(r){if(typeof r!=="function")throw new Error("not a function: "+r)}function v(r){if(typeof r!=="string")throw new Error("not a string: "+r)}function l(r){if(r.length===1)return r[0];return"one of "+r.join(", ")}function h(r,t){var n=t.index;var e=n.offset;if(e===r.length)return", got the end of the stream";var u=e>0?"'...":"'";var i=r.length-e>12?"...'":"'";return" at line "+n.line+" column "+n.column+", got "+u+r.slice(e,e+12)+i}var p=r.formatError=function(r,t){return"expected "+l(t.expected)+h(r,t)};n.parse=function(r){if(typeof r!=="string"){throw new Error(".parse must be called with a string as its argument")}var t=this.skip(R)._(r,0);return t.status?{status:true,value:t.value}:{status:false,index:D(r,t.furthest),expected:t.expected}};var d=r.seq=function(){var r=[].slice.call(arguments);var n=r.length;for(var u=0;u<n;u+=1){f(r[u])}return t(function(t,u){var a;var f=new Array(n);for(var o=0;o<n;o+=1){a=i(r[o]._(t,u),a);if(!a.status)return a;f[o]=a.value;u=a.index}return i(e(u,f),a)})};var g=r.seqMap=function(){var r=[].slice.call(arguments);var t=r.pop();return d.apply(null,r).map(function(r){return t.apply(null,r)})};var x=r.custom=function(r){return t(r(e,u))};var m=r.alt=function(){var r=[].slice.call(arguments);var n=r.length;if(n===0)return b("zero alternates");for(var e=0;e<n;e+=1){f(r[e])}return t(function(t,n){var e;for(var u=0;u<r.length;u+=1){e=i(r[u]._(t,n),e);if(e.status)return e}return e})};var y=r.sepBy=function(t,n){return w(t,n).or(r.of([]))};var w=r.sepBy1=function(r,t){f(r);f(t);var n=t.then(r).many();return r.chain(function(r){return n.map(function(t){return[r].concat(t)})})};n.or=function(r){return m(this,r)};n.then=function(r){if(typeof r==="function"){throw new Error("chaining features of .then are no longer supported, use .chain instead")}f(r);return d(this,r).map(function(r){return r[1]})};n.many=function(){var r=this;return t(function(t,n){var u=[];var a;var f;for(;;){a=i(r._(t,n),a);if(a.status){n=a.index;u.push(a.value)}else{return i(e(n,u),a)}}})};n.times=function(r,n){if(arguments.length<2)n=r;var u=this;o(r);o(n);return t(function(t,a){var f=[];var o=a;var s;var c;for(var v=0;v<r;v+=1){s=u._(t,a);c=i(s,c);if(s.status){a=s.index;f.push(s.value)}else return c}for(;v<n;v+=1){s=u._(t,a);c=i(s,c);if(s.status){a=s.index;f.push(s.value)}else break}return i(e(a,f),c)})};n.result=function(r){return this.map(function(t){return r})};n.atMost=function(r){return this.times(0,r)};n.atLeast=function(r){var t=this;return g(this.times(r),this.many(),function(r,t){return r.concat(t)})};n.map=function(r){c(r);var n=this;return t(function(t,u){var a=n._(t,u);if(!a.status)return a;return i(e(a.index,r(a.value)),a)})};n.skip=function(r){return d(this,r).map(function(r){return r[0]})};n.mark=function(){return g(G,this,G,function(r,t,n){return{start:r,value:t,end:n}})};n.desc=function(r){var n=this;return t(function(t,e){var u=n._(t,e);if(!u.status)u.expected=[r];return u})};var _=r.string=function(r){var n=r.length;var i="'"+r+"'";v(r);return t(function(t,a){var f=t.slice(a,a+n);if(f===r){return e(a+n,f)}else{return u(a,i)}})};var E=r.regex=function(r,n){s(r);if(n)o(n);var i=RegExp("^(?:"+r.source+")",(""+r).slice((""+r).lastIndexOf("/")+1));var a=""+r;if(n==null)n=0;return t(function(r,t){var f=i.exec(r.slice(t));if(f){var o=f[0];var s=f[n];if(s!=null)return e(t+o.length,s)}return u(t,a)})};var O=r.succeed=function(r){return t(function(t,n){return e(n,r)})};var b=r.fail=function(r){return t(function(t,n){return u(n,r)})};var k=r.letter=E(/[a-z]/i).desc("a letter");var z=r.letters=E(/[a-z]*/i);var A=r.digit=E(/[0-9]/).desc("a digit");var P=r.digits=E(/[0-9]*/);var j=r.whitespace=E(/\s+/).desc("whitespace");var q=r.optWhitespace=E(/\s*/);var B=r.any=t(function(r,t){if(t>=r.length)return u(t,"any character");return e(t+1,r.charAt(t))});var M=r.all=t(function(r,t){return e(r.length,r.slice(t))});var R=r.eof=t(function(r,t){if(t<r.length)return u(t,"EOF");return e(t,null)});var W=r.test=function(r){c(r);return t(function(t,n){var i=t.charAt(n);if(n<t.length&&r(i)){return e(n+1,i)}else{return u(n,"a character matching "+r)}})};var F=r.oneOf=function(r){return W(function(t){return r.indexOf(t)>=0})};var I=r.noneOf=function(r){return W(function(t){return r.indexOf(t)<0})};var L=r.takeWhile=function(r){c(r);return t(function(t,n){var u=n;while(u<t.length&&r(t.charAt(u)))u+=1;return e(u,t.slice(n,u))})};var C=r.lazy=function(r,n){if(arguments.length<2){n=r;r=undefined}var e=t(function(r,t){e._=n()._;return e._(r,t)});if(r)e=e.desc(r);return e};var D=function(r,t){var n=r.slice(0,t).split("\n");var e=n.length;var u=n[n.length-1].length+1;return{offset:t,line:e,column:u}};var G=r.index=t(function(r,t){return e(t,D(r,t))});n.concat=n.or;n.empty=b("empty");n.of=t.of=r.of=O;n.ap=function(r){return g(this,r,function(r,t){return r(t)})};n.chain=function(r){var n=this;return t(function(t,e){var u=n._(t,e);if(!u.status)return u;var a=r(u.value);return i(a._(t,u.index),u)})};return r});

@@ -0,1 +1,5 @@

## version 0.8.1 (2016-06-30)
* Optimizes internal set union function, which should result in slightly faster parsing
## version 0.8.0 (2016-06-28)

@@ -2,0 +6,0 @@

{
"name": "parsimmon",
"version": "0.8.0",
"version": "0.8.1",
"description": "A monadic LL(infinity) parser combinator library",

@@ -5,0 +5,0 @@ "keywords": [

@@ -62,3 +62,3 @@ // This unsightly UMD-module header is here to make this code work without

var expected = (result.furthest === last.furthest)
? union(result.expected, last.expected)
? unsafeUnion(result.expected, last.expected)
: last.expected;

@@ -75,13 +75,15 @@

// Returns the sorted set union of two arrays of strings
function union(xs, ys) {
// Returns the sorted set union of two arrays of strings. Note that if both
// arrays are empty, it simply returns the first array, and if exactly one
// array is empty, it returns the other one unsorted. This is safe because
// expectation arrays always start as [] or [x], so as long as we merge with
// this function, we know they stay in sorted order.
function unsafeUnion(xs, ys) {
// Exit early if either array is empty (common case)
var xn = xs.length;
var yn = ys.length;
if (xn === 0 && yn === 0) {
return [];
} else if (xn === 0) {
return ys.slice().sort();
if (xn === 0) {
return ys;
} else if (yn === 0) {
return xs.slice().sort();
return xs;
}

@@ -88,0 +90,0 @@ // Two non-empty arrays: do the full algorithm

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