Comparing version 1.8.0 to 1.9.0
@@ -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{status:!1,index:-1,value:null,furthest:n,expected:[t]}}function y(n,t){if(!t)return n;if(n.furthest>t.furthest)return n;var r=n.furthest===t.furthest?function(n,t){var r=n.length,e=t.length;if(0===r)return t;if(0===e)return n;for(var u={},o=0;o<r;o++)u[n[o]]=!0;for(var i=0;i<e;i++)u[t[i]]=!0;var a=[];for(var f in u)u.hasOwnProperty(f)&&a.push(f);return a.sort(),a}(n.expected,t.expected):t.expected;return{status:n.status,index:n.index,value:n.value,furthest:t.furthest,expected:r}}function m(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 O(n){if("string"!=typeof n)throw new Error("not a string: "+n)}function _(n,t){return"expected "+(1===(r=t.expected).length?r[0]:"one of "+r.join(", "))+function(n,t){var r=t.index,e=r.offset;if(e===n.length)return", got the end of the input";if(d(n))return" at byte "+r.offset;var u=e>0?"'...":"'",o=n.length-e>12?"...'":"'";return" at line "+r.line+" column "+r.column+", got "+u+n.slice(e,e+12)+o}(n,t);var r}function j(n){var t=""+n;return t.slice(t.lastIndexOf("/")+1)}function B(){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=y(n[i]._(r,e),u)).status)return u;o[i]=u.value,e=u.index}return y(v(e,o),u)})}function P(){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),B.apply(null,n).map(function(n){return t.apply(null,n)})}function k(){var n=[].slice.call(arguments),t=n.length;if(0===t)return F("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=y(n[u]._(t,r),e)).status)return e;return e})}function q(n,t){return S(n,t).or(M([]))}function S(n,t){return w(n),w(t),P(n,t.then(n).many(),function(n,t){return[n].concat(t)})}function z(n){O(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 A(n,t){!function(n){if(!(n instanceof RegExp))throw new Error("not a regexp: "+n);for(var t=j(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+")",j(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 M(n){return e(function(t,r){return v(r,n)})}function F(n){return e(function(t,r){return g(r,n)})}function W(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 W(z(n));if(n instanceof RegExp)return W(A(n));throw new Error("not a string, regexp, or parser: "+n)}function I(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 R(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 L(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 U(){return F("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(C)._(n,0);return t.status?{status:!0,value:t.value}:{status:!1,index:m(n,t.furthest),expected:t.expected}},u.tryParse=function(n){var t=this.parse(n);if(t.status)return t.value;var r=_(n,t),e=new Error(r);throw e.type="ParsimmonError",e.result=t,e},u.or=function(n){return k(this,n)},u.trim=function(n){return this.wrap(n,n)},u.wrap=function(n,t){return P(n,this,t,function(n,t){return t})},u.thru=function(n){return n(this)},u.then=function(n){return w(n),B(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=y(n._(t,r),u)).status)return y(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 O(n),this.map(function(t){if(function(n){if(!p(n))throw new Error("not an array: "+n)}(t),t.length){O(t[0]);for(var r=t[0],e=1;e<t.length;e++)O(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=y(i=r._(e,u),a),!i.status)return a;u=i.index,o.push(i.value)}for(;f<t&&(a=y(i=r._(e,u),a),i.status);f+=1)u=i.index,o.push(i.value);return y(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 P(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?y(v(u.index,n(u.value)),u):u})},u.skip=function(n){return B(this,n).map(function(n){return n[0]})},u.mark=function(){return P(N,this,N,function(n,t,r){return{start:n,value:t,end:r}})},u.node=function(n){return P(N,this,N,function(t,r,e){return{name:n,value:r,start:t,end:e}})},u.sepBy=function(n){return q(this,n)},u.sepBy1=function(n){return S(this,n)},u.lookahead=function(n){return this.skip(W(n))},u.notFollowedBy=function(n){return this.skip(I(n))},u.desc=function(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(M(n))},u.ap=function(n){return P(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?y(n(u.value)._(r,u.index),u):u})},u.concat=u.or,u.empty=U,u.of=M,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 N=e(function(n,t){return v(t,m(n,t))}),T=e(function(n,t){return t>=n.length?g(t,"any character/byte"):v(t+1,x(n,t))}),V=e(function(n,t){return v(n.length,n.slice(t))}),C=e(function(n,t){return t<n.length?g(t,"EOF"):v(t,null)}),D=A(/[0-9]/).desc("a digit"),G=A(/[0-9]*/).desc("optional digits"),H=A(/[a-z]/i).desc("a letter"),J=A(/[a-z]*/i).desc("optional letters"),K=A(/\s*/).desc("optional whitespace"),Q=A(/\s+/).desc("whitespace"),X=z("\r"),Y=z("\n"),Z=z("\r\n"),$=k(Z,Y,X).desc("newline"),nn=k($,C);e.all=V,e.alt=k,e.any=T,e.cr=X,e.createLanguage=function(n){var t={};for(var r in n)({}).hasOwnProperty.call(n,r)&&function(r){t[r]=L(function(){return n[r](t)})}(r);return t},e.crlf=Z,e.custom=function(n){return e(n(v,g))},e.digit=D,e.digits=G,e.empty=U,e.end=nn,e.eof=C,e.fail=F,e.formatError=_,e.index=N,e.isParser=h,e.lazy=L,e.letter=H,e.letters=J,e.lf=Y,e.lookahead=W,e.makeFailure=g,e.makeSuccess=v,e.newline=$,e.noneOf=function(n){return R(function(t){return n.indexOf(t)<0})},e.notFollowedBy=I,e.of=M,e.oneOf=function(n){return R(function(t){return n.indexOf(t)>=0})},e.optWhitespace=K,e.Parser=e,e.range=function(n,t){return R(function(r){return n<=r&&r<=t}).desc(n+"-"+t)},e.regex=A,e.regexp=A,e.sepBy=q,e.sepBy1=S,e.seq=B,e.seqMap=P,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=y(f._(n,t),r)).status)return r;a&&(e[a]=r.value),t=r.index}return y(v(t,e),r)})},e.string=z,e.succeed=M,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=R,e.whitespace=Q,e["fantasy-land/empty"]=U,e["fantasy-land/of"]=M,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(O(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 y(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 m(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 O(n){if("string"!=typeof n)throw new Error("not a string: "+n)}function _(n,t){return"expected "+(1===(r=t.expected).length?r[0]:"one of "+r.join(", "))+function(n,t){var r=t.index,e=r.offset;if(e===n.length)return", got the end of the input";if(d(n))return" at byte "+r.offset;var u=e>0?"'...":"'",o=n.length-e>12?"...'":"'";return" at line "+r.line+" column "+r.column+", got "+u+n.slice(e,e+12)+o}(n,t);var r}function j(n){var t=""+n;return t.slice(t.lastIndexOf("/")+1)}function B(){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=y(n[i]._(r,e),u)).status)return u;o[i]=u.value,e=u.index}return y(v(e,o),u)})}function P(){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),B.apply(null,n).map(function(n){return t.apply(null,n)})}function k(){var n=[].slice.call(arguments),t=n.length;if(0===t)return F("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=y(n[u]._(t,r),e)).status)return e;return e})}function q(n,t){return S(n,t).or(M([]))}function S(n,t){return w(n),w(t),P(n,t.then(n).many(),function(n,t){return[n].concat(t)})}function z(n){O(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 A(n,t){!function(n){if(!(n instanceof RegExp))throw new Error("not a regexp: "+n);for(var t=j(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+")",j(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 M(n){return e(function(t,r){return v(r,n)})}function F(n){return e(function(t,r){return g(r,n)})}function W(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 W(z(n));if(n instanceof RegExp)return W(A(n));throw new Error("not a string, regexp, or parser: "+n)}function I(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 R(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 L(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 U(){return F("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(C)._(n,0);return t.status?{status:!0,value:t.value}:{status:!1,index:m(n,t.furthest),expected:t.expected}},u.tryParse=function(n){var t=this.parse(n);if(t.status)return t.value;var r=_(n,t),e=new Error(r);throw e.type="ParsimmonError",e.result=t,e},u.or=function(n){return k(this,n)},u.trim=function(n){return this.wrap(n,n)},u.wrap=function(n,t){return P(n,this,t,function(n,t){return t})},u.thru=function(n){return n(this)},u.then=function(n){return w(n),B(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=y(n._(t,r),u)).status)return y(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 O(n),this.map(function(t){if(function(n){if(!p(n))throw new Error("not an array: "+n)}(t),t.length){O(t[0]);for(var r=t[0],e=1;e<t.length;e++)O(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=y(i=r._(e,u),a),!i.status)return a;u=i.index,o.push(i.value)}for(;f<t&&(a=y(i=r._(e,u),a),i.status);f+=1)u=i.index,o.push(i.value);return y(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 P(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?y(v(u.index,n(u.value)),u):u})},u.skip=function(n){return B(this,n).map(function(n){return n[0]})},u.mark=function(){return P(N,this,N,function(n,t,r){return{start:n,value:t,end:r}})},u.node=function(n){return P(N,this,N,function(t,r,e){return{name:n,value:r,start:t,end:e}})},u.sepBy=function(n){return q(this,n)},u.sepBy1=function(n){return S(this,n)},u.lookahead=function(n){return this.skip(W(n))},u.notFollowedBy=function(n){return this.skip(I(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(M(n))},u.ap=function(n){return P(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?y(n(u.value)._(r,u.index),u):u})},u.concat=u.or,u.empty=U,u.of=M,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 N=e(function(n,t){return v(t,m(n,t))}),T=e(function(n,t){return t>=n.length?g(t,"any character/byte"):v(t+1,x(n,t))}),V=e(function(n,t){return v(n.length,n.slice(t))}),C=e(function(n,t){return t<n.length?g(t,"EOF"):v(t,null)}),D=A(/[0-9]/).desc("a digit"),G=A(/[0-9]*/).desc("optional digits"),H=A(/[a-z]/i).desc("a letter"),J=A(/[a-z]*/i).desc("optional letters"),K=A(/\s*/).desc("optional whitespace"),Q=A(/\s+/).desc("whitespace"),X=z("\r"),Y=z("\n"),Z=z("\r\n"),$=k(Z,Y,X).desc("newline"),nn=k($,C);e.all=V,e.alt=k,e.any=T,e.cr=X,e.createLanguage=function(n){var t={};for(var r in n)({}).hasOwnProperty.call(n,r)&&function(r){t[r]=L(function(){return n[r](t)})}(r);return t},e.crlf=Z,e.custom=function(n){return e(n(v,g))},e.digit=D,e.digits=G,e.empty=U,e.end=nn,e.eof=C,e.fail=F,e.formatError=_,e.index=N,e.isParser=h,e.lazy=L,e.letter=H,e.letters=J,e.lf=Y,e.lookahead=W,e.makeFailure=g,e.makeSuccess=v,e.newline=$,e.noneOf=function(n){return R(function(t){return n.indexOf(t)<0}).desc("none of '"+n+"'")},e.notFollowedBy=I,e.of=M,e.oneOf=function(n){for(var t=n.split(""),r=0;r<t.length;r++)t[r]="'"+t[r]+"'";return R(function(t){return n.indexOf(t)>=0}).desc(t)},e.optWhitespace=K,e.Parser=e,e.range=function(n,t){return R(function(r){return n<=r&&r<=t}).desc(n+"-"+t)},e.regex=A,e.regexp=A,e.sepBy=q,e.sepBy1=S,e.seq=B,e.seqMap=P,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=y(f._(n,t),r)).status)return r;a&&(e[a]=r.value),t=r.index}return y(v(t,e),r)})},e.string=z,e.succeed=M,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=R,e.whitespace=Q,e["fantasy-land/empty"]=U,e["fantasy-land/of"]=M,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(O(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}])}); |
183
CHANGELOG.md
@@ -0,129 +1,147 @@ | ||
## version 1.9.0 (2018-06-15) | ||
- Adds `parser.desc(array)` signature and `Parsimmon.makeFailure(index, array)` | ||
signature to support starting with an array of expectations | ||
## version 1.8.0 (2018-06-04) | ||
* Adds `parser.tieWith(separator)`, a generalized version of `parser.tie()` | ||
- Adds `parser.tieWith(separator)`, a generalized version of `parser.tie()` | ||
## version 1.7.3 (2018-04-22) | ||
* Shrinks UMD build from ~33 kb to ~11 kb | ||
- Shrinks UMD build from ~33 kb to ~11 kb | ||
## version 1.7.2 (2018-04-05) | ||
* Fixes a bug where `seqObj` and `bitSeqObj` wouldn't work with keys that were already part of `Object.prototype` | ||
- Fixes a bug where `seqObj` and `bitSeqObj` wouldn't work with keys that were | ||
already part of `Object.prototype` | ||
## version 1.7.1 (2018-03-22) | ||
* Fixes a bug where `bitSeq` consumed the wrong input | ||
- Fixes a bug where `bitSeq` consumed the wrong input | ||
## version 1.7.0 (2018-03-10) | ||
* Adds support for binary parsing using Node.js Buffers | ||
* Adds `Parsimmon.Binary.bitSeq` | ||
* Adds `Parsimmon.Binary.bitSeqObj` | ||
* Adds `Parsimmon.Binary.byte` | ||
- Adds support for binary parsing using Node.js Buffers | ||
- Adds `Parsimmon.Binary.bitSeq` | ||
- Adds `Parsimmon.Binary.bitSeqObj` | ||
- Adds `Parsimmon.Binary.byte` | ||
## version 1.6.4 (2018-01-01) | ||
* Fixes `parser.many()` to throw an error if it detects an infinite parse loop. | ||
- Fixes `parser.many()` to throw an error if it detects an infinite parse loop. | ||
## version 1.6.3 (2018-01-01) | ||
* Unpublished due to a Travis CI build issues. | ||
- Unpublished due to a Travis CI build issues. | ||
## version 1.6.2 (2017-07-08) | ||
* Fixes another bug with match groups outside the correct range in `Parsimmon.regexp(regexp, group)`. | ||
- Fixes another bug with match groups outside the correct range in | ||
`Parsimmon.regexp(regexp, group)`. | ||
## version 1.6.1 (2017-07-01) | ||
* **100% unit test coverage!** This does not mean bugs won't exist, but it keeps us much safer against regressions in the future. | ||
* **BUGFIX:** `Parsimmon.regexp(regexp, group)` will now correctly fail to parse if the `group` number is out of range for the `regexp` number of groups. This worked correctly in the past, but was broken during a minor code clean up due to missing tests. | ||
- **100% unit test coverage!** This does not mean bugs won't exist, but it keeps | ||
us much safer against regressions in the future. | ||
- **BUGFIX:** `Parsimmon.regexp(regexp, group)` will now correctly fail to parse | ||
if the `group` number is out of range for the `regexp` number of groups. This | ||
worked correctly in the past, but was broken during a minor code clean up due | ||
to missing tests. | ||
## version 1.6.0 (2017-06-26) | ||
* Adds `Parsimmon.seqObj(...args)` | ||
- Adds `Parsimmon.seqObj(...args)` | ||
## version 1.5.0 (2017-06-17) | ||
NOTE: Code was completed on 2017-06-17, but due to human error, was not published on npm until 2017-06-26. | ||
NOTE: Code was completed on 2017-06-17, but due to human error, was not | ||
published on npm until 2017-06-26. | ||
* Adds `parser.sepBy(separator)` alias for `Parsimmon.sepBy(parser, separator)` | ||
* Adds `parser.sepBy1(separator)` alias for `Parsimmon.sepBy1(parser, separator)` | ||
* Adds `Parsimmon.range(begin, end)` | ||
* Adds `parser.wrap(before, after)` | ||
* Adds `parser.trim(anotherParser)` | ||
* Adds `parser.tie()` | ||
- Adds `parser.sepBy(separator)` alias for `Parsimmon.sepBy(parser, separator)` | ||
- Adds `parser.sepBy1(separator)` alias for `Parsimmon.sepBy1(parser, separator)` | ||
- Adds `Parsimmon.range(begin, end)` | ||
- Adds `parser.wrap(before, after)` | ||
- Adds `parser.trim(anotherParser)` | ||
- Adds `parser.tie()` | ||
## version 1.4.0 (2017-06-05) | ||
* Adds `Parsimmon.createLanguage(parsers)` | ||
* Adds `parser.thru(wrapper)` | ||
* Adds `parser.node(name)` | ||
- Adds `Parsimmon.createLanguage(parsers)` | ||
- Adds `parser.thru(wrapper)` | ||
- Adds `parser.node(name)` | ||
## version 1.3.0 (2017-05-28) | ||
* Adds `Parsimmon.notFollowedBy(parser)` | ||
* Adds `parser.notFollowedBy(anotherParser)` | ||
- Adds `Parsimmon.notFollowedBy(parser)` | ||
- Adds `parser.notFollowedBy(anotherParser)` | ||
## version 1.2.0 (2016-12-22) | ||
* Adds `Parsimmon.lookahead(parser)` | ||
* Adds `parser.lookahead(anotherParser)` | ||
- Adds `Parsimmon.lookahead(parser)` | ||
- Adds `parser.lookahead(anotherParser)` | ||
## version 1.1.0 (2016-12-21) | ||
* Adds `Parsimmon.lookahead(string)` | ||
* Adds `Parsimmon.lookahead(regexp)` | ||
* Adds `parser.lookahead(string)` | ||
* Adds `parser.lookahead(regexp)` | ||
- Adds `Parsimmon.lookahead(string)` | ||
- Adds `Parsimmon.lookahead(regexp)` | ||
- Adds `parser.lookahead(string)` | ||
- Adds `parser.lookahead(regexp)` | ||
## version 1.0.0 (2016-11-02) | ||
* **BREAKING:** `parser.empty` is now a function (`parser.empty()`). | ||
* **BREAKING:** `f.ap(x)` is now `x.ap(f)`. | ||
* Adds `parser.tryParse(str)` which either returns the parsed value or throws an exception. | ||
* Adds support for `fantasy-land/*` prefixed versions of methods. | ||
* `Parsimmon.empty()` is a copy of `parser.empty()`. | ||
* Adds `.desc` descriptions for `digits`, `letters`, `optWhitespace`. | ||
* Adds `Parsimmon.isParser`. | ||
* Adds `parser.fallback(value)`. | ||
* Parsimmon now only has one namespace. `Parsimmon.Parser` is equal to `Parsimmon` itself for backwards compatibility purposes. | ||
* Exposes `Parsimmon.makeSuccess` and `Parsimmon.makeFailure`. | ||
* Documentation for `Parsimmon.formatError`, `Parsimmon.parse`, `Parsimmon.Parser`, `Parsimmon.makeSuccess`, `Parsimmon.makeFailure`, `Parsimmon.isParser`, `parser.fallback`. | ||
- **BREAKING:** `parser.empty` is now a function (`parser.empty()`). | ||
- **BREAKING:** `f.ap(x)` is now `x.ap(f)`. | ||
- Adds `parser.tryParse(str)` which either returns the parsed value or throws an | ||
exception. | ||
- Adds support for `fantasy-land/*` prefixed versions of methods. | ||
- `Parsimmon.empty()` is a copy of `parser.empty()`. | ||
- Adds `.desc` descriptions for `digits`, `letters`, `optWhitespace`. | ||
- Adds `Parsimmon.isParser`. | ||
- Adds `parser.fallback(value)`. | ||
- Parsimmon now only has one namespace. `Parsimmon.Parser` is equal to | ||
`Parsimmon` itself for backwards compatibility purposes. | ||
- Exposes `Parsimmon.makeSuccess` and `Parsimmon.makeFailure`. | ||
- Documentation for `Parsimmon.formatError`, `Parsimmon.parse`, | ||
`Parsimmon.Parser`, `Parsimmon.makeSuccess`, `Parsimmon.makeFailure`, | ||
`Parsimmon.isParser`, `parser.fallback`. | ||
## version 0.9.2 (2016-08-07) | ||
* Adds `browser` field to `package.json` so unpkg serves the correct file. | ||
* Documentation overhaul in `README.md`. | ||
* Examples overhaul. | ||
- Adds `browser` field to `package.json` so unpkg serves the correct file. | ||
- Documentation overhaul in `README.md`. | ||
- Examples overhaul. | ||
## version 0.9.1 (2016-07-08) | ||
* **BREAKING:** `P.seqMap` now throws when passed zero arguments, or when the final argument is not a function. | ||
* `P.regex` is now an alias for `P.regexp`. | ||
- **BREAKING:** `P.seqMap` now throws when passed zero arguments, or when the | ||
final argument is not a function. | ||
- `P.regex` is now an alias for `P.regexp`. | ||
## version 0.9.0 (2016-07-07) | ||
* **BREAKING:** `P.regex` throws on regexps with flags other than `imu` now. | ||
- **BREAKING:** `P.regex` throws on regexps with flags other than `imu` now. | ||
## version 0.8.1 (2016-06-30) | ||
* Optimizes internal set union function, which should result in slightly faster parsing | ||
- Optimizes internal set union function, which should result in slightly faster | ||
parsing | ||
## version 0.8.0 (2016-06-28) | ||
* The `.expected` array on parse results is now unique and sorted | ||
* Updated Mocha and Chai versions | ||
* Updated README a bit (mostly line wrapping stuff) | ||
- The `.expected` array on parse results is now unique and sorted | ||
- Updated Mocha and Chai versions | ||
- Updated README a bit (mostly line wrapping stuff) | ||
## version 0.7.2 (2016-06-26) | ||
* No API changes | ||
* Switches to npm-based task running | ||
* Switches to UMD-based code | ||
- No API changes | ||
- Switches to npm-based task running | ||
- Switches to UMD-based code | ||
## version 0.7.1 (2016-06-04) | ||
* Documentation updates | ||
* Adds line/column information to `P.index` and `.mark()` | ||
* Adds additional type assertions | ||
- Documentation updates | ||
- Adds line/column information to `P.index` and `.mark()` | ||
- Adds additional type assertions | ||
@@ -136,55 +154,58 @@ ## version 0.7.0 (???) | ||
* add a second optional argument to `regex()` indicating group selection | ||
* eliminates pjs dependency | ||
* add seqMap, oneOf, and noneOf | ||
- add a second optional argument to `regex()` indicating group selection | ||
- eliminates pjs dependency | ||
- add seqMap, oneOf, and noneOf | ||
## version 0.5.1 (2014-06-25) | ||
* Added .custom, .test, and .takeWhile for folks who don't like to use regexes. | ||
- Added .custom, .test, and .takeWhile for folks who don't like to use regexes. | ||
## version 0.5.0 (2014-06-15) | ||
* Added `.desc()` for custom parse error messages | ||
- Added `.desc()` for custom parse error messages | ||
## version 0.4.0 (2014-04-18) | ||
* **BREAKING:** deprecated use of `.then(function(result) { ... })`. Use `chain` instead. | ||
* **BREAKING:** errors are no longer thrown on invalid parses. Instead, `.parse(str)` returns | ||
an object with a `status` tag, indicating whether the parse was successful. | ||
- **BREAKING:** deprecated use of `.then(function(result) { ... })`. Use `chain` | ||
instead. | ||
- **BREAKING:** errors are no longer thrown on invalid parses. Instead, | ||
`.parse(str)` returns an object with a `status` tag, indicating whether the | ||
parse was successful. | ||
## version 0.3.2 (2014-04-18) | ||
* never throw strings, always throw error objects | ||
* add the MIT license | ||
- never throw strings, always throw error objects | ||
- add the MIT license | ||
## version 0.3.1 (2014-03-12) | ||
* add browser files to the npm package | ||
- add browser files to the npm package | ||
## version 0.3.0 (2014-03-12) | ||
* started updating the changelog again :x | ||
* **BREAKING:** `seq` and `alt` now take varargs instead of a single list argument. | ||
- started updating the changelog again :x | ||
- **BREAKING:** `seq` and `alt` now take varargs instead of a single list | ||
argument. | ||
## version 0.1.0 (2014-01-09) | ||
* Uses less stack space with a non-cps implementation | ||
* Added `Parsimmon.index` and `Parser::mark()` | ||
* fantasyland compatibility | ||
- Uses less stack space with a non-cps implementation | ||
- Added `Parsimmon.index` and `Parser::mark()` | ||
- fantasyland compatibility | ||
## version 0.0.6 (2013-12-02) | ||
* Better error messages: use the message from the furthest backtrack. | ||
- Better error messages: use the message from the furthest backtrack. | ||
## version 0.0.5 (2013-04-10) | ||
* Fix a "build directory nonexistent" bug :\ | ||
- Fix a "build directory nonexistent" bug :\ | ||
## version 0.0.4 (2013-04-09) | ||
* Started a CHANGELOG | ||
* Specify pjs 3.x | ||
* added "use strict" | ||
* Stopped trying to subclass Error (was silencing all parse errors :\ ) | ||
- Started a CHANGELOG | ||
- Specify pjs 3.x | ||
- added "use strict" | ||
- Stopped trying to subclass Error (was silencing all parse errors :\ ) | ||
(Note: v0.0.3 is completely b0rken, and was unpublished from npm) |
{ | ||
"name": "parsimmon", | ||
"version": "1.8.0", | ||
"version": "1.9.0", | ||
"description": "A monadic LL(infinity) parser combinator library", | ||
@@ -28,3 +28,3 @@ "keywords": [ | ||
"nyc": "^11.0.3", | ||
"prettier": "1.7.4", | ||
"prettier": "1.13.4", | ||
"rimraf": "^2.5.4", | ||
@@ -37,3 +37,3 @@ "webpack": "^4.6.0", | ||
"preversion": "npm test", | ||
"postversion": "git push && git push --tags", | ||
"postversion": "git push && git push --tags && npm publish", | ||
"prebuild": "rimraf build && mkdirp build", | ||
@@ -40,0 +40,0 @@ "build": "webpack -p", |
@@ -53,4 +53,5 @@ <a href="https://badge.fury.io/js/parsimmon"><img src="https://badge.fury.io/js/parsimmon.svg" alt=""></a> | ||
```javascript | ||
Parsimmon.string('foo') | ||
.map(function(x) { return x + 'bar'; }) | ||
Parsimmon.string("foo").map(function(x) { | ||
return x + "bar"; | ||
}); | ||
``` | ||
@@ -61,4 +62,5 @@ | ||
```javascript | ||
Parsimmon.regexp(/[0-9]+/) | ||
.map(function(x) { return Number(x) * 2; }) | ||
Parsimmon.regexp(/[0-9]+/).map(function(x) { | ||
return Number(x) * 2; | ||
}); | ||
``` | ||
@@ -82,6 +84,6 @@ | ||
- [`.alt(p1, p2, ...pn)`](API.md#parsimmonaltp1-p2-pn) | ||
- [`.node(name)`](API.md#nodename) | ||
- [`.whitespace`](API.md#parsimmonwhitespace) | ||
- [`.index`](API.md#parsimmonindex) | ||
- [`parser.map(fn)`](API.md#parsermapfn) | ||
- [`parser.node(name)`](API.md#parsernodename) | ||
- [`parser.skip(otherParser)`](API.md#parserskipotherparser) | ||
@@ -95,3 +97,3 @@ | ||
Contributions are *not* just pull requests. | ||
Contributions are _not_ just pull requests. | ||
@@ -116,6 +118,4 @@ Issues clearly describing bugs or confusing parts of Parsimmon are welcome! Also, documentation enhancements and examples are very desirable. | ||
[@wavebeem]: https://github.com/wavebeem | ||
[api]: https://github.com/jneen/parsimmon/blob/master/API.md | ||
[examples]: https://github.com/jneen/parsimmon/tree/master/examples | ||
[unpkg homepage]: https://unpkg.com/#/ | ||
@@ -122,0 +122,0 @@ [unpkg version]: https://unpkg.com/parsimmon |
@@ -242,2 +242,5 @@ "use strict"; | ||
function makeFailure(index, expected) { | ||
if (!isArray(expected)) { | ||
expected = [expected]; | ||
} | ||
return { | ||
@@ -248,3 +251,3 @@ status: false, | ||
furthest: index, | ||
expected: [expected] | ||
expected: expected | ||
}; | ||
@@ -262,3 +265,3 @@ } | ||
result.furthest === last.furthest | ||
? unsafeUnion(result.expected, last.expected) | ||
? union(result.expected, last.expected) | ||
: last.expected; | ||
@@ -294,22 +297,9 @@ return { | ||
// 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) { | ||
return ys; | ||
} else if (yn === 0) { | ||
return xs; | ||
} | ||
// Two non-empty arrays: do the full algorithm | ||
// Returns the sorted set union of two arrays of strings | ||
function union(xs, ys) { | ||
var obj = {}; | ||
for (var i = 0; i < xn; i++) { | ||
for (var i = 0; i < xs.length; i++) { | ||
obj[xs[i]] = true; | ||
} | ||
for (var j = 0; j < yn; j++) { | ||
for (var j = 0; j < ys.length; j++) { | ||
obj[ys[j]] = true; | ||
@@ -319,3 +309,3 @@ } | ||
for (var k in obj) { | ||
if (obj.hasOwnProperty(k)) { | ||
if ({}.hasOwnProperty.call(obj, k)) { | ||
keys.push(k); | ||
@@ -783,2 +773,5 @@ } | ||
_.desc = function(expected) { | ||
if (!isArray(expected)) { | ||
expected = [expected]; | ||
} | ||
var self = this; | ||
@@ -788,3 +781,3 @@ return Parsimmon(function(input, i) { | ||
if (!reply.status) { | ||
reply.expected = [expected]; | ||
reply.expected = expected; | ||
} | ||
@@ -933,5 +926,9 @@ return reply; | ||
function oneOf(str) { | ||
var expected = str.split(""); | ||
for (var idx = 0; idx < expected.length; idx++) { | ||
expected[idx] = "'" + expected[idx] + "'"; | ||
} | ||
return test(function(ch) { | ||
return str.indexOf(ch) >= 0; | ||
}); | ||
}).desc(expected); | ||
} | ||
@@ -942,3 +939,3 @@ | ||
return str.indexOf(ch) < 0; | ||
}); | ||
}).desc("none of '" + str + "'"); | ||
} | ||
@@ -945,0 +942,0 @@ |
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
50631
971