Comparing version 1.2.0 to 1.3.0
@@ -431,2 +431,7 @@ /* global module, define */ | ||
}; | ||
_.notFollowedBy = function(x) { | ||
return this.skip(notFollowedBy(x)); | ||
}; | ||
_.desc = function(expected) { | ||
@@ -521,2 +526,13 @@ var self = this; | ||
function notFollowedBy(parser) { | ||
assertParser(parser); | ||
return Parsimmon(function(input, i) { | ||
var result = parser._(input, i); | ||
var text = input.slice(i, result.index); | ||
return result.status | ||
? makeFailure(i, 'not "' + text + '"') | ||
: makeSuccess(i, null); | ||
}); | ||
} | ||
var any = Parsimmon(function(input, i) { | ||
@@ -671,2 +687,3 @@ if (i >= input.length) { | ||
Parsimmon.lookahead = lookahead; | ||
Parsimmon.notFollowedBy = notFollowedBy; | ||
Parsimmon.makeFailure = makeFailure; | ||
@@ -673,0 +690,0 @@ Parsimmon.makeSuccess = makeSuccess; |
@@ -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(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}); | ||
(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(q)._(n,0);return t.status?{status:true,value:t.value}:{status:false,index:L(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(S,this,S,function(n,t,r){return{start:n,value:t,end:r}})};r.lookahead=function(n){return this.skip(A(n))};r.notFollowedBy=function(n){return this.skip(z(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)}function z(t){o(t);return n(function(n,r){var a=t._(n,r);var i=n.slice(r,a.index);return a.status?u(r,'not "'+i+'"'):e(r,null)})}var B=n(function(n,t){if(t>=n.length){return u(t,"any character")}return e(t+1,n.charAt(t))});var F=n(function(n,t){return e(n.length,n.slice(t))});var q=n(function(n,t){if(t<n.length){return u(t,"EOF")}return e(t,null)});function M(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 R(n){return M(function(t){return n.indexOf(t)>=0})}function j(n){return M(function(t){return n.indexOf(t)<0})}function W(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 I(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 L(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 S=n(function(n,t){return e(t,L(n,t))});function C(){return P("fantasy-land/empty")}r.concat=r.or;r["fantasy-land/concat"]=r.concat;r.empty=C;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 D=O(/[0-9]/).desc("a digit");var G=O(/[0-9]*/).desc("optional digits");var H=O(/[a-z]/i).desc("a letter");var J=O(/[a-z]*/i).desc("optional letters");var K=O(/\s*/).desc("optional whitespace");var N=O(/\s+/).desc("whitespace");n.all=F;n.alt=x;n.any=B;n.custom=m;n.digit=D;n.digits=G;n.eof=q;n.fail=P;n.formatError=p;n.index=S;n.isParser=t;n.lazy=I;n.letter=H;n.letters=J;n.lookahead=A;n.notFollowedBy=z;n.makeFailure=u;n.makeSuccess=e;n.noneOf=j;n.oneOf=R;n.optWhitespace=K;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=W;n.test=M;n.whitespace=N;n.empty=C;n["fantasy-land/empty"]=C;n.of=b;n["fantasy-land/of"]=b;return n}); |
@@ -0,1 +1,6 @@ | ||
## version 1.3.0 (2017-05-28) | ||
* Adds `Parsimmon.notFollowedBy(parser)` | ||
* Adds `parser.notFollowedBy(anotherParser)` | ||
## version 1.2.0 (2016-12-22) | ||
@@ -2,0 +7,0 @@ |
{ | ||
"name": "parsimmon", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "A monadic LL(infinity) parser combinator library", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -21,3 +21,3 @@ <a href="https://travis-ci.org/jneen/parsimmon"><img alt="Build Status" src="https://api.travis-ci.org/jneen/parsimmon.svg"></a> | ||
See the [examples][] directory for annotated examples of parsing JSON, Lisp, and math. | ||
See the [examples][] directory for annotated examples of parsing JSON, Lisp, a Python-ish language, and math. | ||
@@ -48,2 +48,17 @@ ## Basics | ||
Note: If you prefer throwing an error when the parse failed, call [`.tryParse(string)`](API.md#parsertryparseinput) instead. The returned value will be the parsing result itself when succeeded. | ||
## Common Functions | ||
- [`.string(string)`](API.md#parsimmonstringstring) | ||
- [`.regexp(regexp)`](API.md#parsimmonregexpregexp) | ||
- [`.seq(p1, p2, ...pn)`](API.md#parsimmonseqp1-p2-pn) | ||
- [`.sepBy(content, separator)`](API.md#parsimmonsepbycontent) | ||
- [`.alt(p1, p2, ...pn)`](API.md#parsimmonaltp1-p2-pn) | ||
- [`.lazy(fn)`](API.md#parsimmonlazyfn) | ||
- [`.whitespace`](API.md#parsimmonwhitespace) | ||
- [`.index`](API.md#parsimmonindex) | ||
- [`parser.map(fn)`](API.md#parsermapfn) | ||
- [`parser.skip(otherParser)`](API.md#parserskipotherparser) | ||
## Questions | ||
@@ -55,4 +70,8 @@ | ||
Contributions are *not* just pull requests. Issues clearly describing bugs or confusing parts of Parsimmon are welcome! Also, documentation enhancements and examples are very desirable. Feeling overwhelmed about contributing? Open an issue about what you want to contribute and I'm happy to help you through to completion! | ||
Contributions are *not* just pull requests. | ||
Issues clearly describing bugs or confusing parts of Parsimmon are welcome! Also, documentation enhancements and examples are very desirable. | ||
Feeling overwhelmed about contributing? Open an issue about what you want to contribute and I'm happy to help you through to completion! | ||
## Performance | ||
@@ -59,0 +78,0 @@ |
@@ -431,2 +431,7 @@ /* global module, define */ | ||
}; | ||
_.notFollowedBy = function(x) { | ||
return this.skip(notFollowedBy(x)); | ||
}; | ||
_.desc = function(expected) { | ||
@@ -521,2 +526,13 @@ var self = this; | ||
function notFollowedBy(parser) { | ||
assertParser(parser); | ||
return Parsimmon(function(input, i) { | ||
var result = parser._(input, i); | ||
var text = input.slice(i, result.index); | ||
return result.status | ||
? makeFailure(i, 'not "' + text + '"') | ||
: makeSuccess(i, null); | ||
}); | ||
} | ||
var any = Parsimmon(function(input, i) { | ||
@@ -671,2 +687,3 @@ if (i >= input.length) { | ||
Parsimmon.lookahead = lookahead; | ||
Parsimmon.notFollowedBy = notFollowedBy; | ||
Parsimmon.makeFailure = makeFailure; | ||
@@ -673,0 +690,0 @@ Parsimmon.makeSuccess = makeSuccess; |
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
55158
1307
100