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.11.0 to 1.11.1

2

build/parsimmon.umd.min.js

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

!function(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Parsimmon=t():n.Parsimmon=t()}("undefined"!=typeof self?self:this,function(){return function(n){var t={};function r(e){if(t[e])return t[e].exports;var u=t[e]={i:e,l:!1,exports:{}};return n[e].call(u.exports,u,u.exports,r),u.l=!0,u.exports}return r.m=n,r.c=t,r.d=function(n,t,e){r.o(n,t)||Object.defineProperty(n,t,{configurable:!1,enumerable:!0,get:e})},r.r=function(n){Object.defineProperty(n,"__esModule",{value:!0})},r.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return r.d(t,"a",t),t},r.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},r.p="",r(r.s=0)}([function(n,t,r){"use strict";function e(n){if(!(this instanceof e))return new e(n);this._=n}var u=e.prototype;function o(n,t){for(var r=0;r<n;r++)t(r)}function i(n,t,r){return function(n,t){o(t.length,function(r){n(t[r],r,t)})}(function(r,e,u){t=n(t,r,e,u)},r),t}function a(n,t){return i(function(t,r,e,u){return t.concat([n(r,e,u)])},[],t)}function f(n,t){var r={v:0,buf:t};return o(n,function(){var n;r={v:r.v<<1|(n=r.buf,n[0]>>7),buf:function(n){var t=i(function(n,t,r,e){return n.concat(r===e.length-1?Buffer.from([t,0]).readUInt16BE(0):e.readUInt16BE(r))},[],n);return Buffer.from(a(function(n){return(n<<1&65535)>>8},t))}(r.buf)}}),r}function c(){return"undefined"!=typeof Buffer}function s(){if(!c())throw new Error("Buffer global does not exist; please consider using https://github.com/feross/buffer if you are running Parsimmon in a browser.")}function l(n){s();var t=i(function(n,t){return n+t},0,n);if(t%8!=0)throw new Error("The bits ["+n.join(", ")+"] add up to "+t+" which is not an even number of bytes; the total should be divisible by 8");var r,u=t/8,o=(r=function(n){return n>48},i(function(n,t){return n||(r(t)?t:n)},null,n));if(o)throw new Error(o+" bit range requested exceeds 48 bit (6 byte) Number max.");return new e(function(t,r){var e=u+r;return e>t.length?g(r,u.toString()+" bytes"):v(e,i(function(n,t){var r=f(t,n.buf);return{coll:n.coll.concat(r.v),buf:r.buf}},{coll:[],buf:t.slice(r,e)},n).coll)})}function h(n){return n instanceof e}function p(n){return"[object Array]"==={}.toString.call(n)}function d(n){return c()&&Buffer.isBuffer(n)}function v(n,t){return{status:!0,index:n,value:t,furthest:-1,expected:[]}}function g(n,t){return p(t)||(t=[t]),{status:!1,index:-1,value:null,furthest:n,expected:t}}function m(n,t){if(!t)return n;if(n.furthest>t.furthest)return n;var r=n.furthest===t.furthest?function(n,t){for(var r={},e=0;e<n.length;e++)r[n[e]]=!0;for(var u=0;u<t.length;u++)r[t[u]]=!0;var o=[];for(var i in r)({}).hasOwnProperty.call(r,i)&&o.push(i);return o.sort(),o}(n.expected,t.expected):t.expected;return{status:n.status,index:n.index,value:n.value,furthest:t.furthest,expected:r}}function y(n,t){if(d(n))return{offset:t,line:-1,column:-1};var r=n.slice(0,t).split("\n");return{offset:t,line:r.length,column:r[r.length-1].length+1}}function w(n){if(!h(n))throw new Error("not a parser: "+n)}function x(n,t){return"string"==typeof n?n.charAt(t):n[t]}function b(n){if("number"!=typeof n)throw new Error("not a number: "+n)}function E(n){if("function"!=typeof n)throw new Error("not a function: "+n)}function j(n){if("string"!=typeof n)throw new Error("not a string: "+n)}var O=2,_=3,B=8,S=5*B,P=4*B,k=16,q=2,A=" ";function z(n,t){return new Array(t+1).join(n)}function M(n,t,r){var e=t-n.length;return e<=0?n:z(r,e)+n}function F(n,t,r,e){return{from:n-t>0?n-t:0,to:n+r>e?e:n+r}}function I(n,t){var r,e,u,o,f=t.index,c=f.offset,s=1;if(c===n.length)return"Got the end of the input";if(d(n)){var l=c-c%B,h=c-l,p=F(l,S,P+B,n.length),v=a(function(n){return a(function(n){return M(n.toString(k),q,"0")},n)},function(n,t){var r=n.length,e=[],u=0;if(r<=t)return[n.slice()];for(var o=0;o<r;o++)e[u]||e.push([]),e[u].push(n[o]),(o+1)%t==0&&u++;return e}(n.slice(p.from,p.to).toJSON().data,B));o=function(n){return 0===n.from&&1===n.to?{from:n.from,to:n.to}:{from:n.from/B,to:Math.floor(n.to/B)}}(p),e=l/B,r=3*h,h>4&&(r+=1),s=q,u=a(function(n){return n.length<=4?n.join(" "):n.slice(0,4).join(" ")+" "+n.slice(4).join(" ")},v)}else{var g=n.split(/\r\n|[\n\r\u2028\u2029]/);r=f.column-1,e=f.line-1,o=F(e,O,_,g.length),u=g.slice(o.from,o.to)}var m=e-o.from,y=o.to.toString().length;return d(n)&&(y=(8*(o.to>0?o.to-1:o.to)).toString(16).length)<2&&(y=2),i(function(t,e,u){var i=u===m,a=i?"> ":A,f=d(n)?(8*(o.from+u)).toString(16):(o.from+u+1).toString();d(n)&&f.length<2&&(f=M(f,2,"0"));var c=f.length<y?M(f,y,d(n)?"0":" "):f;return[].concat(t,[a+c+" | "+e],i?[A+z(" ",y)+" | "+M("",r," ")+z("^",s)]:[])},[],u).join("\n")}function R(n,t){return["\n","-- PARSING FAILED "+z("-",50),"\n\n",I(n,t),"\n\n",(r=t.expected,1===r.length?"Expected:\n\n"+r[0]:"Expected one of the following: \n\n"+r.join(", ")),"\n"].join("");var r}function W(n){var t=""+n;return t.slice(t.lastIndexOf("/")+1)}function L(){for(var n=[].slice.call(arguments),t=n.length,r=0;r<t;r+=1)w(n[r]);return e(function(r,e){for(var u,o=new Array(t),i=0;i<t;i+=1){if(!(u=m(n[i]._(r,e),u)).status)return u;o[i]=u.value,e=u.index}return m(v(e,o),u)})}function N(){var n=[].slice.call(arguments);if(0===n.length)throw new Error("seqMap needs at least one argument");var t=n.pop();return E(t),L.apply(null,n).map(function(n){return t.apply(null,n)})}function G(){var n=[].slice.call(arguments),t=n.length;if(0===t)return C("zero alternates");for(var r=0;r<t;r+=1)w(n[r]);return e(function(t,r){for(var e,u=0;u<n.length;u+=1)if((e=m(n[u]._(t,r),e)).status)return e;return e})}function U(n,t){return D(n,t).or(V([]))}function D(n,t){return w(n),w(t),N(n,t.then(n).many(),function(n,t){return[n].concat(t)})}function J(n){j(n);var t="'"+n+"'";return e(function(r,e){var u=e+n.length,o=r.slice(e,u);return o===n?v(u,o):g(e,t)})}function T(n,t){!function(n){if(!(n instanceof RegExp))throw new Error("not a regexp: "+n);for(var t=W(n),r=0;r<t.length;r++){var e=t.charAt(r);if("i"!==e&&"m"!==e&&"u"!==e)throw new Error('unsupported regexp flag "'+e+'": '+n)}}(n),arguments.length>=2?b(t):t=0;var r=function(n){return RegExp("^(?:"+n.source+")",W(n))}(n),u=""+n;return e(function(n,e){var o=r.exec(n.slice(e));if(o){if(0<=t&&t<=o.length){var i=o[0],a=o[t];return v(e+i.length,a)}return g(e,"valid match group (0 to "+o.length+") in "+u)}return g(e,u)})}function V(n){return e(function(t,r){return v(r,n)})}function C(n){return e(function(t,r){return g(r,n)})}function H(n){if(h(n))return e(function(t,r){var e=n._(t,r);return e.index=r,e.value="",e});if("string"==typeof n)return H(J(n));if(n instanceof RegExp)return H(T(n));throw new Error("not a string, regexp, or parser: "+n)}function K(n){return w(n),e(function(t,r){var e=n._(t,r),u=t.slice(r,e.index);return e.status?g(r,'not "'+u+'"'):v(r,null)})}function Q(n){return E(n),e(function(t,r){var e=x(t,r);return r<t.length&&n(e)?v(r+1,e):g(r,"a character/byte matching "+n)})}function X(n,t){arguments.length<2&&(t=n,n=void 0);var r=e(function(n,e){return r._=t()._,r._(n,e)});return n?r.desc(n):r}function Y(){return C("fantasy-land/empty")}u.parse=function(n){if("string"!=typeof n&&!d(n))throw new Error(".parse must be called with a string or Buffer as its argument");var t=this.skip(tn)._(n,0);return t.status?{status:!0,value:t.value}:{status:!1,index:y(n,t.furthest),expected:t.expected}},u.tryParse=function(n){var t=this.parse(n);if(t.status)return t.value;var r=R(n,t),e=new Error(r);throw e.type="ParsimmonError",e.result=t,e},u.or=function(n){return G(this,n)},u.trim=function(n){return this.wrap(n,n)},u.wrap=function(n,t){return N(n,this,t,function(n,t){return t})},u.thru=function(n){return n(this)},u.then=function(n){return w(n),L(this,n).map(function(n){return n[1]})},u.many=function(){var n=this;return e(function(t,r){for(var e=[],u=void 0;;){if(!(u=m(n._(t,r),u)).status)return m(v(r,e),u);if(r===u.index)throw new Error("infinite loop detected in .many() parser --- calling .many() on a parser which can accept zero characters is usually the cause");r=u.index,e.push(u.value)}})},u.tieWith=function(n){return j(n),this.map(function(t){if(function(n){if(!p(n))throw new Error("not an array: "+n)}(t),t.length){j(t[0]);for(var r=t[0],e=1;e<t.length;e++)j(t[e]),r+=n+t[e];return r}return""})},u.tie=function(){return this.tieWith("")},u.times=function(n,t){var r=this;return arguments.length<2&&(t=n),b(n),b(t),e(function(e,u){for(var o=[],i=void 0,a=void 0,f=0;f<n;f+=1){if(a=m(i=r._(e,u),a),!i.status)return a;u=i.index,o.push(i.value)}for(;f<t&&(a=m(i=r._(e,u),a),i.status);f+=1)u=i.index,o.push(i.value);return m(v(u,o),a)})},u.result=function(n){return this.map(function(){return n})},u.atMost=function(n){return this.times(0,n)},u.atLeast=function(n){return N(this.times(n),this.many(),function(n,t){return n.concat(t)})},u.map=function(n){E(n);var t=this;return e(function(r,e){var u=t._(r,e);return u.status?m(v(u.index,n(u.value)),u):u})},u.contramap=function(n){E(n);var t=this;return e(function(r,e){var u=t.parse(n(r.slice(e)));return u.status?v(e+r.length,u.value):u})},u.promap=function(n,t){return E(n),E(t),this.contramap(n).map(t)},u.skip=function(n){return L(this,n).map(function(n){return n[0]})},u.mark=function(){return N(Z,this,Z,function(n,t,r){return{start:n,value:t,end:r}})},u.node=function(n){return N(Z,this,Z,function(t,r,e){return{name:n,value:r,start:t,end:e}})},u.sepBy=function(n){return U(this,n)},u.sepBy1=function(n){return D(this,n)},u.lookahead=function(n){return this.skip(H(n))},u.notFollowedBy=function(n){return this.skip(K(n))},u.desc=function(n){p(n)||(n=[n]);var t=this;return e(function(r,e){var u=t._(r,e);return u.status||(u.expected=n),u})},u.fallback=function(n){return this.or(V(n))},u.ap=function(n){return N(n,this,function(n,t){return n(t)})},u.chain=function(n){var t=this;return e(function(r,e){var u=t._(r,e);return u.status?m(n(u.value)._(r,u.index),u):u})},u.concat=u.or,u.empty=Y,u.of=V,u["fantasy-land/ap"]=u.ap,u["fantasy-land/chain"]=u.chain,u["fantasy-land/concat"]=u.concat,u["fantasy-land/empty"]=u.empty,u["fantasy-land/of"]=u.of,u["fantasy-land/map"]=u.map;var Z=e(function(n,t){return v(t,y(n,t))}),$=e(function(n,t){return t>=n.length?g(t,"any character/byte"):v(t+1,x(n,t))}),nn=e(function(n,t){return v(n.length,n.slice(t))}),tn=e(function(n,t){return t<n.length?g(t,"EOF"):v(t,null)}),rn=T(/[0-9]/).desc("a digit"),en=T(/[0-9]*/).desc("optional digits"),un=T(/[a-z]/i).desc("a letter"),on=T(/[a-z]*/i).desc("optional letters"),an=T(/\s*/).desc("optional whitespace"),fn=T(/\s+/).desc("whitespace"),cn=J("\r"),sn=J("\n"),ln=J("\r\n"),hn=G(ln,sn,cn).desc("newline"),pn=G(hn,tn);e.all=nn,e.alt=G,e.any=$,e.cr=cn,e.createLanguage=function(n){var t={};for(var r in n)({}).hasOwnProperty.call(n,r)&&function(r){t[r]=X(function(){return n[r](t)})}(r);return t},e.crlf=ln,e.custom=function(n){return e(n(v,g))},e.digit=rn,e.digits=en,e.empty=Y,e.end=pn,e.eof=tn,e.fail=C,e.formatError=R,e.index=Z,e.isParser=h,e.lazy=X,e.letter=un,e.letters=on,e.lf=sn,e.lookahead=H,e.makeFailure=g,e.makeSuccess=v,e.newline=hn,e.noneOf=function(n){return Q(function(t){return n.indexOf(t)<0}).desc("none of '"+n+"'")},e.notFollowedBy=K,e.of=V,e.oneOf=function(n){for(var t=n.split(""),r=0;r<t.length;r++)t[r]="'"+t[r]+"'";return Q(function(t){return n.indexOf(t)>=0}).desc(t)},e.optWhitespace=an,e.Parser=e,e.range=function(n,t){return Q(function(r){return n<=r&&r<=t}).desc(n+"-"+t)},e.regex=T,e.regexp=T,e.sepBy=U,e.sepBy1=D,e.seq=L,e.seqMap=N,e.seqObj=function(){for(var n,t={},r=0,u=(n=arguments,Array.prototype.slice.call(n)),o=u.length,i=0;i<o;i+=1){var a=u[i];if(!h(a)){if(p(a)&&2===a.length&&"string"==typeof a[0]&&h(a[1])){var f=a[0];if(Object.prototype.hasOwnProperty.call(t,f))throw new Error("seqObj: duplicate key "+f);t[f]=!0,r++;continue}throw new Error("seqObj arguments must be parsers or [string, parser] array pairs.")}}if(0===r)throw new Error("seqObj expects at least one named parser, found zero");return e(function(n,t){for(var r,e={},i=0;i<o;i+=1){var a,f;if(p(u[i])?(a=u[i][0],f=u[i][1]):(a=null,f=u[i]),!(r=m(f._(n,t),r)).status)return r;a&&(e[a]=r.value),t=r.index}return m(v(t,e),r)})},e.string=J,e.succeed=V,e.takeWhile=function(n){return E(n),e(function(t,r){for(var e=r;e<t.length&&n(x(t,e));)e++;return v(e,t.slice(r,e))})},e.test=Q,e.whitespace=fn,e["fantasy-land/empty"]=Y,e["fantasy-land/of"]=V,e.Binary={bitSeq:l,bitSeqObj:function(n){s();var t={},r=0,e=a(function(n){if(p(n)){var e=n;if(2!==e.length)throw new Error("["+e.join(", ")+"] should be length 2, got length "+e.length);if(j(e[0]),b(e[1]),Object.prototype.hasOwnProperty.call(t,e[0]))throw new Error("duplicate key in bitSeqObj: "+e[0]);return t[e[0]]=!0,r++,e}return b(n),[null,n]},n);if(r<1)throw new Error("bitSeqObj expects at least one named pair, got ["+n.join(", ")+"]");var u=a(function(n){return n[0]},e);return l(a(function(n){return n[1]},e)).map(function(n){return i(function(n,t){return null!==t[0]&&(n[t[0]]=t[1]),n},{},a(function(t,r){return[t,n[r]]},u))})},byte:function(n){if(s(),b(n),n>255)throw new Error("Value specified to byte constructor ("+n+"=0x"+n.toString(16)+") is larger in value than a single byte.");var t=(n>15?"0x":"0x0")+n.toString(16);return e(function(r,e){var u=x(r,e);return u===n?v(e+1,u):g(e,t)})}},n.exports=e}])});
!function(n,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Parsimmon=t():n.Parsimmon=t()}("undefined"!=typeof self?self:this,function(){return function(n){var t={};function r(e){if(t[e])return t[e].exports;var u=t[e]={i:e,l:!1,exports:{}};return n[e].call(u.exports,u,u.exports,r),u.l=!0,u.exports}return r.m=n,r.c=t,r.d=function(n,t,e){r.o(n,t)||Object.defineProperty(n,t,{configurable:!1,enumerable:!0,get:e})},r.r=function(n){Object.defineProperty(n,"__esModule",{value:!0})},r.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return r.d(t,"a",t),t},r.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},r.p="",r(r.s=0)}([function(n,t,r){"use strict";function e(n){if(!(this instanceof e))return new e(n);this._=n}var u=e.prototype;function o(n,t){for(var r=0;r<n;r++)t(r)}function i(n,t,r){return function(n,t){o(t.length,function(r){n(t[r],r,t)})}(function(r,e,u){t=n(t,r,e,u)},r),t}function a(n,t){return i(function(t,r,e,u){return t.concat([n(r,e,u)])},[],t)}function f(n,t){var r={v:0,buf:t};return o(n,function(){var n;r={v:r.v<<1|(n=r.buf,n[0]>>7),buf:function(n){var t=i(function(n,t,r,e){return n.concat(r===e.length-1?Buffer.from([t,0]).readUInt16BE(0):e.readUInt16BE(r))},[],n);return Buffer.from(a(function(n){return(n<<1&65535)>>8},t))}(r.buf)}}),r}function c(){return"undefined"!=typeof Buffer}function s(){if(!c())throw new Error("Buffer global does not exist; please consider using https://github.com/feross/buffer if you are running Parsimmon in a browser.")}function l(n){s();var t=i(function(n,t){return n+t},0,n);if(t%8!=0)throw new Error("The bits ["+n.join(", ")+"] add up to "+t+" which is not an even number of bytes; the total should be divisible by 8");var r,u=t/8,o=(r=function(n){return n>48},i(function(n,t){return n||(r(t)?t:n)},null,n));if(o)throw new Error(o+" bit range requested exceeds 48 bit (6 byte) Number max.");return new e(function(t,r){var e=u+r;return e>t.length?g(r,u.toString()+" bytes"):v(e,i(function(n,t){var r=f(t,n.buf);return{coll:n.coll.concat(r.v),buf:r.buf}},{coll:[],buf:t.slice(r,e)},n).coll)})}function h(n){return n instanceof e}function p(n){return"[object Array]"==={}.toString.call(n)}function d(n){return c()&&Buffer.isBuffer(n)}function v(n,t){return{status:!0,index:n,value:t,furthest:-1,expected:[]}}function g(n,t){return p(t)||(t=[t]),{status:!1,index:-1,value:null,furthest:n,expected:t}}function m(n,t){if(!t)return n;if(n.furthest>t.furthest)return n;var r=n.furthest===t.furthest?function(n,t){for(var r={},e=0;e<n.length;e++)r[n[e]]=!0;for(var u=0;u<t.length;u++)r[t[u]]=!0;var o=[];for(var i in r)({}).hasOwnProperty.call(r,i)&&o.push(i);return o.sort(),o}(n.expected,t.expected):t.expected;return{status:n.status,index:n.index,value:n.value,furthest:t.furthest,expected:r}}function y(n,t){if(d(n))return{offset:t,line:-1,column:-1};var r=n.slice(0,t).split("\n");return{offset:t,line:r.length,column:r[r.length-1].length+1}}function w(n){if(!h(n))throw new Error("not a parser: "+n)}function x(n,t){return"string"==typeof n?n.charAt(t):n[t]}function b(n){if("number"!=typeof n)throw new Error("not a number: "+n)}function E(n){if("function"!=typeof n)throw new Error("not a function: "+n)}function j(n){if("string"!=typeof n)throw new Error("not a string: "+n)}var O=2,_=3,B=8,S=5*B,P=4*B,k=" ";function q(n,t){return new Array(t+1).join(n)}function A(n,t,r){var e=t-n.length;return e<=0?n:q(r,e)+n}function z(n,t,r,e){return{from:n-t>0?n-t:0,to:n+r>e?e:n+r}}function M(n,t){var r,e,u,o,f,c=t.index,s=c.offset,l=1;if(s===n.length)return"Got the end of the input";if(d(n)){var h=s-s%B,p=s-h,v=z(h,S,P+B,n.length),g=a(function(n){return a(function(n){return A(n.toString(16),2,"0")},n)},function(n,t){var r=n.length,e=[],u=0;if(r<=t)return[n.slice()];for(var o=0;o<r;o++)e[u]||e.push([]),e[u].push(n[o]),(o+1)%t==0&&u++;return e}(n.slice(v.from,v.to).toJSON().data,B));o=function(n){return 0===n.from&&1===n.to?{from:n.from,to:n.to}:{from:n.from/B,to:Math.floor(n.to/B)}}(v),e=h/B,r=3*p,p>=4&&(r+=1),l=2,u=a(function(n){return n.length<=4?n.join(" "):n.slice(0,4).join(" ")+" "+n.slice(4).join(" ")},g),(f=(8*(o.to>0?o.to-1:o.to)).toString(16).length)<2&&(f=2)}else{var m=n.split(/\r\n|[\n\r\u2028\u2029]/);r=c.column-1,e=c.line-1,o=z(e,O,_,m.length),u=m.slice(o.from,o.to),f=o.to.toString().length}var y=e-o.from;return i(function(t,e,u){var i,a=u===y,c=a?"> ":k;return i=d(n)?A((8*(o.from+u)).toString(16),f,"0"):A((o.from+u+1).toString(),f," "),[].concat(t,[c+i+" | "+e],a?[k+q(" ",f)+" | "+A("",r," ")+q("^",l)]:[])},[],u).join("\n")}function F(n,t){return["\n","-- PARSING FAILED "+q("-",50),"\n\n",M(n,t),"\n\n",(r=t.expected,1===r.length?"Expected:\n\n"+r[0]:"Expected one of the following: \n\n"+r.join(", ")),"\n"].join("");var r}function I(n){var t=""+n;return t.slice(t.lastIndexOf("/")+1)}function R(){for(var n=[].slice.call(arguments),t=n.length,r=0;r<t;r+=1)w(n[r]);return e(function(r,e){for(var u,o=new Array(t),i=0;i<t;i+=1){if(!(u=m(n[i]._(r,e),u)).status)return u;o[i]=u.value,e=u.index}return m(v(e,o),u)})}function W(){var n=[].slice.call(arguments);if(0===n.length)throw new Error("seqMap needs at least one argument");var t=n.pop();return E(t),R.apply(null,n).map(function(n){return t.apply(null,n)})}function L(){var n=[].slice.call(arguments),t=n.length;if(0===t)return T("zero alternates");for(var r=0;r<t;r+=1)w(n[r]);return e(function(t,r){for(var e,u=0;u<n.length;u+=1)if((e=m(n[u]._(t,r),e)).status)return e;return e})}function N(n,t){return G(n,t).or(J([]))}function G(n,t){return w(n),w(t),W(n,t.then(n).many(),function(n,t){return[n].concat(t)})}function U(n){j(n);var t="'"+n+"'";return e(function(r,e){var u=e+n.length,o=r.slice(e,u);return o===n?v(u,o):g(e,t)})}function D(n,t){!function(n){if(!(n instanceof RegExp))throw new Error("not a regexp: "+n);for(var t=I(n),r=0;r<t.length;r++){var e=t.charAt(r);if("i"!==e&&"m"!==e&&"u"!==e)throw new Error('unsupported regexp flag "'+e+'": '+n)}}(n),arguments.length>=2?b(t):t=0;var r=function(n){return RegExp("^(?:"+n.source+")",I(n))}(n),u=""+n;return e(function(n,e){var o=r.exec(n.slice(e));if(o){if(0<=t&&t<=o.length){var i=o[0],a=o[t];return v(e+i.length,a)}return g(e,"valid match group (0 to "+o.length+") in "+u)}return g(e,u)})}function J(n){return e(function(t,r){return v(r,n)})}function T(n){return e(function(t,r){return g(r,n)})}function V(n){if(h(n))return e(function(t,r){var e=n._(t,r);return e.index=r,e.value="",e});if("string"==typeof n)return V(U(n));if(n instanceof RegExp)return V(D(n));throw new Error("not a string, regexp, or parser: "+n)}function C(n){return w(n),e(function(t,r){var e=n._(t,r),u=t.slice(r,e.index);return e.status?g(r,'not "'+u+'"'):v(r,null)})}function H(n){return E(n),e(function(t,r){var e=x(t,r);return r<t.length&&n(e)?v(r+1,e):g(r,"a character/byte matching "+n)})}function K(n,t){arguments.length<2&&(t=n,n=void 0);var r=e(function(n,e){return r._=t()._,r._(n,e)});return n?r.desc(n):r}function Q(){return T("fantasy-land/empty")}u.parse=function(n){if("string"!=typeof n&&!d(n))throw new Error(".parse must be called with a string or Buffer as its argument");var t=this.skip($)._(n,0);return t.status?{status:!0,value:t.value}:{status:!1,index:y(n,t.furthest),expected:t.expected}},u.tryParse=function(n){var t=this.parse(n);if(t.status)return t.value;var r=F(n,t),e=new Error(r);throw e.type="ParsimmonError",e.result=t,e},u.or=function(n){return L(this,n)},u.trim=function(n){return this.wrap(n,n)},u.wrap=function(n,t){return W(n,this,t,function(n,t){return t})},u.thru=function(n){return n(this)},u.then=function(n){return w(n),R(this,n).map(function(n){return n[1]})},u.many=function(){var n=this;return e(function(t,r){for(var e=[],u=void 0;;){if(!(u=m(n._(t,r),u)).status)return m(v(r,e),u);if(r===u.index)throw new Error("infinite loop detected in .many() parser --- calling .many() on a parser which can accept zero characters is usually the cause");r=u.index,e.push(u.value)}})},u.tieWith=function(n){return j(n),this.map(function(t){if(function(n){if(!p(n))throw new Error("not an array: "+n)}(t),t.length){j(t[0]);for(var r=t[0],e=1;e<t.length;e++)j(t[e]),r+=n+t[e];return r}return""})},u.tie=function(){return this.tieWith("")},u.times=function(n,t){var r=this;return arguments.length<2&&(t=n),b(n),b(t),e(function(e,u){for(var o=[],i=void 0,a=void 0,f=0;f<n;f+=1){if(a=m(i=r._(e,u),a),!i.status)return a;u=i.index,o.push(i.value)}for(;f<t&&(a=m(i=r._(e,u),a),i.status);f+=1)u=i.index,o.push(i.value);return m(v(u,o),a)})},u.result=function(n){return this.map(function(){return n})},u.atMost=function(n){return this.times(0,n)},u.atLeast=function(n){return W(this.times(n),this.many(),function(n,t){return n.concat(t)})},u.map=function(n){E(n);var t=this;return e(function(r,e){var u=t._(r,e);return u.status?m(v(u.index,n(u.value)),u):u})},u.contramap=function(n){E(n);var t=this;return e(function(r,e){var u=t.parse(n(r.slice(e)));return u.status?v(e+r.length,u.value):u})},u.promap=function(n,t){return E(n),E(t),this.contramap(n).map(t)},u.skip=function(n){return R(this,n).map(function(n){return n[0]})},u.mark=function(){return W(X,this,X,function(n,t,r){return{start:n,value:t,end:r}})},u.node=function(n){return W(X,this,X,function(t,r,e){return{name:n,value:r,start:t,end:e}})},u.sepBy=function(n){return N(this,n)},u.sepBy1=function(n){return G(this,n)},u.lookahead=function(n){return this.skip(V(n))},u.notFollowedBy=function(n){return this.skip(C(n))},u.desc=function(n){p(n)||(n=[n]);var t=this;return e(function(r,e){var u=t._(r,e);return u.status||(u.expected=n),u})},u.fallback=function(n){return this.or(J(n))},u.ap=function(n){return W(n,this,function(n,t){return n(t)})},u.chain=function(n){var t=this;return e(function(r,e){var u=t._(r,e);return u.status?m(n(u.value)._(r,u.index),u):u})},u.concat=u.or,u.empty=Q,u.of=J,u["fantasy-land/ap"]=u.ap,u["fantasy-land/chain"]=u.chain,u["fantasy-land/concat"]=u.concat,u["fantasy-land/empty"]=u.empty,u["fantasy-land/of"]=u.of,u["fantasy-land/map"]=u.map;var X=e(function(n,t){return v(t,y(n,t))}),Y=e(function(n,t){return t>=n.length?g(t,"any character/byte"):v(t+1,x(n,t))}),Z=e(function(n,t){return v(n.length,n.slice(t))}),$=e(function(n,t){return t<n.length?g(t,"EOF"):v(t,null)}),nn=D(/[0-9]/).desc("a digit"),tn=D(/[0-9]*/).desc("optional digits"),rn=D(/[a-z]/i).desc("a letter"),en=D(/[a-z]*/i).desc("optional letters"),un=D(/\s*/).desc("optional whitespace"),on=D(/\s+/).desc("whitespace"),an=U("\r"),fn=U("\n"),cn=U("\r\n"),sn=L(cn,fn,an).desc("newline"),ln=L(sn,$);e.all=Z,e.alt=L,e.any=Y,e.cr=an,e.createLanguage=function(n){var t={};for(var r in n)({}).hasOwnProperty.call(n,r)&&function(r){t[r]=K(function(){return n[r](t)})}(r);return t},e.crlf=cn,e.custom=function(n){return e(n(v,g))},e.digit=nn,e.digits=tn,e.empty=Q,e.end=ln,e.eof=$,e.fail=T,e.formatError=F,e.index=X,e.isParser=h,e.lazy=K,e.letter=rn,e.letters=en,e.lf=fn,e.lookahead=V,e.makeFailure=g,e.makeSuccess=v,e.newline=sn,e.noneOf=function(n){return H(function(t){return n.indexOf(t)<0}).desc("none of '"+n+"'")},e.notFollowedBy=C,e.of=J,e.oneOf=function(n){for(var t=n.split(""),r=0;r<t.length;r++)t[r]="'"+t[r]+"'";return H(function(t){return n.indexOf(t)>=0}).desc(t)},e.optWhitespace=un,e.Parser=e,e.range=function(n,t){return H(function(r){return n<=r&&r<=t}).desc(n+"-"+t)},e.regex=D,e.regexp=D,e.sepBy=N,e.sepBy1=G,e.seq=R,e.seqMap=W,e.seqObj=function(){for(var n,t={},r=0,u=(n=arguments,Array.prototype.slice.call(n)),o=u.length,i=0;i<o;i+=1){var a=u[i];if(!h(a)){if(p(a)&&2===a.length&&"string"==typeof a[0]&&h(a[1])){var f=a[0];if(Object.prototype.hasOwnProperty.call(t,f))throw new Error("seqObj: duplicate key "+f);t[f]=!0,r++;continue}throw new Error("seqObj arguments must be parsers or [string, parser] array pairs.")}}if(0===r)throw new Error("seqObj expects at least one named parser, found zero");return e(function(n,t){for(var r,e={},i=0;i<o;i+=1){var a,f;if(p(u[i])?(a=u[i][0],f=u[i][1]):(a=null,f=u[i]),!(r=m(f._(n,t),r)).status)return r;a&&(e[a]=r.value),t=r.index}return m(v(t,e),r)})},e.string=U,e.succeed=J,e.takeWhile=function(n){return E(n),e(function(t,r){for(var e=r;e<t.length&&n(x(t,e));)e++;return v(e,t.slice(r,e))})},e.test=H,e.whitespace=on,e["fantasy-land/empty"]=Q,e["fantasy-land/of"]=J,e.Binary={bitSeq:l,bitSeqObj:function(n){s();var t={},r=0,e=a(function(n){if(p(n)){var e=n;if(2!==e.length)throw new Error("["+e.join(", ")+"] should be length 2, got length "+e.length);if(j(e[0]),b(e[1]),Object.prototype.hasOwnProperty.call(t,e[0]))throw new Error("duplicate key in bitSeqObj: "+e[0]);return t[e[0]]=!0,r++,e}return b(n),[null,n]},n);if(r<1)throw new Error("bitSeqObj expects at least one named pair, got ["+n.join(", ")+"]");var u=a(function(n){return n[0]},e);return l(a(function(n){return n[1]},e)).map(function(n){return i(function(n,t){return null!==t[0]&&(n[t[0]]=t[1]),n},{},a(function(t,r){return[t,n[r]]},u))})},byte:function(n){if(s(),b(n),n>255)throw new Error("Value specified to byte constructor ("+n+"=0x"+n.toString(16)+") is larger in value than a single byte.");var t=(n>15?"0x":"0x0")+n.toString(16);return e(function(r,e){var u=x(r,e);return u===n?v(e+1,u):g(e,t)})}},n.exports=e}])});

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

## version 1.11.1 (2018-06-27)
- Fixes a bug where the error indicator (`^^`) was misaligned on the fifth byte
in a given visual line for a binary parse error message
## version 1.11.0 (2018-06-23)

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

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

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

@@ -374,4 +374,2 @@ "use strict";

var bytesAfter = bytesPerLine * 4;
var radix = 16;
var byteLength = 2;
var defaultLinePrefix = " ";

@@ -456,2 +454,3 @@

var lineRange;
var lastLineNumberLabelLength;

@@ -476,4 +475,4 @@ if (i === input.length) {

return map(function(byteValue) {
// Prefix byte values with a `0`
return leftPad(byteValue.toString(radix), byteLength, "0");
// Prefix byte values with a `0` if they are shorter than 2 characters.
return leftPad(byteValue.toString(16), 2, "0");
}, byteRow);

@@ -487,6 +486,7 @@ }, bytesInChunks);

// Account for an extra space.
if (columnByteIndex > 4) {
if (columnByteIndex >= 4) {
column += 1;
}
verticalMarkerLength = byteLength;
verticalMarkerLength = 2;
lines = map(function(byteLine) {

@@ -497,2 +497,9 @@ return byteLine.length <= 4

}, byteLines);
lastLineNumberLabelLength = (
(lineRange.to > 0 ? lineRange.to - 1 : lineRange.to) * 8
).toString(16).length;
if (lastLineNumberLabelLength < 2) {
lastLineNumberLabelLength = 2;
}
} else {

@@ -510,17 +517,6 @@ var inputLines = input.split(/\r\n|[\n\r\u2028\u2029]/);

lines = inputLines.slice(lineRange.from, lineRange.to);
lastLineNumberLabelLength = lineRange.to.toString().length;
}
var lineWithErrorCurrentIndex = lineWithErrorIndex - lineRange.from;
var lastLineNumberLabelLength = lineRange.to.toString().length;
if (isBuffer(input)) {
lastLineNumberLabelLength = (
(lineRange.to > 0 ? lineRange.to - 1 : lineRange.to) * 8
).toString(16).length;
if (lastLineNumberLabelLength < 2) {
lastLineNumberLabelLength = 2;
}
}
var linesWithLineNumbers = reduce(

@@ -530,18 +526,17 @@ function(acc, lineSource, index) {

var prefix = isLineWithError ? "> " : defaultLinePrefix;
var lineNumber = isBuffer(input)
? ((lineRange.from + index) * 8).toString(16)
: (lineRange.from + index + 1).toString();
var lineNumberLabel;
if (isBuffer(input)) {
if (lineNumber.length < 2) {
lineNumber = leftPad(lineNumber, 2, "0");
}
lineNumberLabel = leftPad(
((lineRange.from + index) * 8).toString(16),
lastLineNumberLabelLength,
"0"
);
} else {
lineNumberLabel = leftPad(
(lineRange.from + index + 1).toString(),
lastLineNumberLabelLength,
" "
);
}
var lineNumberLabel =
lineNumber.length < lastLineNumberLabelLength
? leftPad(
lineNumber,
lastLineNumberLabelLength,
isBuffer(input) ? "0" : " "
)
: lineNumber;

@@ -553,3 +548,2 @@ return [].concat(

? [
// (isBuffer(input) ? " " : "") +
defaultLinePrefix +

@@ -556,0 +550,0 @@ repeat(" ", lastLineNumberLabelLength) +

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