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 1.1.0 to 1.2.0

27

build/parsimmon.browser.js

@@ -505,24 +505,15 @@ /* global module, define */

function lookahead(x) {
if (typeof x === 'string') {
// similar to string, but does not consume
if (isParser(x)) {
return Parsimmon(function(input, i) {
var j = i + x.length;
var head = input.slice(i, j);
if (head === x) {
return makeSuccess(i, '');
} else {
return makeFailure(i, x);
}
var result = x._(input, i);
result.index = i;
result.value = '';
return result;
});
} else if (typeof x === 'string') {
return lookahead(string(x));
} else if (x instanceof RegExp) {
assertRegexp(x);
var regexp = anchoredRegexp(x);
return Parsimmon(function(str, i) {
if (regexp.test(str.slice(i))) {
return makeSuccess(i, '');
}
return makeFailure(i, '' + regexp);
});
return lookahead(regexp(x));
}
throw new Error('not a string or regexp: '+x);
throw new Error('not a string, regexp, or parser: ' + x);
}

@@ -529,0 +520,0 @@

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

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

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

## version 1.2.0 (2016-12-22)
* Adds `Parsimmon.lookahead(parser)`
* Adds `parser.lookahead(anotherParser)`
## version 1.1.0 (2016-12-21)

@@ -2,0 +7,0 @@

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

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

@@ -505,24 +505,15 @@ /* global module, define */

function lookahead(x) {
if (typeof x === 'string') {
// similar to string, but does not consume
if (isParser(x)) {
return Parsimmon(function(input, i) {
var j = i + x.length;
var head = input.slice(i, j);
if (head === x) {
return makeSuccess(i, '');
} else {
return makeFailure(i, x);
}
var result = x._(input, i);
result.index = i;
result.value = '';
return result;
});
} else if (typeof x === 'string') {
return lookahead(string(x));
} else if (x instanceof RegExp) {
assertRegexp(x);
var regexp = anchoredRegexp(x);
return Parsimmon(function(str, i) {
if (regexp.test(str.slice(i))) {
return makeSuccess(i, '');
}
return makeFailure(i, '' + regexp);
});
return lookahead(regexp(x));
}
throw new Error('not a string or regexp: '+x);
throw new Error('not a string, regexp, or parser: ' + x);
}

@@ -529,0 +520,0 @@

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