Comparing version 1.3.0 to 1.3.1
87
index.js
@@ -9,4 +9,11 @@ "use strict"; | ||
var _data = require("data.either"); | ||
var _data = _interopRequireDefault(require("data.either")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
const { | ||
Left, | ||
Right | ||
} = _data.default; | ||
function Parser(p) { | ||
@@ -19,3 +26,3 @@ this.p = p; | ||
Parser.prototype.run = function Parser$run(targetString) { | ||
return this.p((0, _data.Right)([0, targetString, null])).map(result => { | ||
return this.p(Right([0, targetString, null])).map(result => { | ||
return result[2]; | ||
@@ -38,3 +45,3 @@ }); | ||
return that.p(state).chain(function Parser$chain$chain([i, s, v]) { | ||
return fn(v).p((0, _data.Right)([i, s, v])); | ||
return fn(v).p(Right([i, s, v])); | ||
}); | ||
@@ -134,3 +141,3 @@ }); | ||
return state.chain(function fail$state$chain([i]) { | ||
return (0, _data.Left)([i, errorMessage]); | ||
return Left([i, errorMessage]); | ||
}); | ||
@@ -161,3 +168,3 @@ }); | ||
while (true) { | ||
const out = parser.p((0, _data.Right)(nextState)); | ||
const out = parser.p(Right(nextState)); | ||
@@ -177,3 +184,3 @@ if (out.isLeft) { | ||
const [index, targetString] = nextState; | ||
return (0, _data.Right)([index, targetString, results]); | ||
return Right([index, targetString, results]); | ||
}); | ||
@@ -191,6 +198,6 @@ }); | ||
if (value.length === 0) { | ||
return (0, _data.Left)([index, `ParseError 'many1' (position ${index}): Expecting to match at least one value`]); | ||
return Left([index, `ParseError 'many1' (position ${index}): Expecting to match at least one value`]); | ||
} | ||
return (0, _data.Right)([index, targetString, value]); | ||
return Right([index, targetString, value]); | ||
}); | ||
@@ -232,9 +239,9 @@ }); | ||
if (targetString[index] === c) { | ||
return (0, _data.Right)([index + 1, targetString, c]); | ||
return Right([index + 1, targetString, c]); | ||
} else { | ||
return (0, _data.Left)([index, `ParseError (position ${index}): Expecting character '${c}', got '${targetString[index]}'`]); | ||
return Left([index, `ParseError (position ${index}): Expecting character '${c}', got '${targetString[index]}'`]); | ||
} | ||
} | ||
return (0, _data.Left)([index, `ParseError (position ${index}): Expecting character '${c}', but got end of input.`]); | ||
return Left([index, `ParseError (position ${index}): Expecting character '${c}', but got end of input.`]); | ||
}); | ||
@@ -258,9 +265,9 @@ }); | ||
if (rest.startsWith(s)) { | ||
return (0, _data.Right)([index + s.length, targetString, s]); | ||
return Right([index + s.length, targetString, s]); | ||
} else { | ||
return (0, _data.Left)([index, `ParseError (position ${index}): Expecting string '${s}', got '${rest.slice(0, s.length)}...'`]); | ||
return Left([index, `ParseError (position ${index}): Expecting string '${s}', got '${rest.slice(0, s.length)}...'`]); | ||
} | ||
} | ||
return (0, _data.Left)([index, `ParseError (position ${index}): Expecting string '${s}', but got end of input.`]); | ||
return Left([index, `ParseError (position ${index}): Expecting string '${s}', but got end of input.`]); | ||
}); | ||
@@ -292,9 +299,9 @@ }); | ||
if (match) { | ||
return (0, _data.Right)([index + match[0].length, targetString, match[0]]); | ||
return Right([index + match[0].length, targetString, match[0]]); | ||
} else { | ||
return (0, _data.Left)([index, `ParseError (position ${index}): Expecting string matching '${re}', got '${rest.slice(0, 5)}...'`]); | ||
return Left([index, `ParseError (position ${index}): Expecting string matching '${re}', got '${rest.slice(0, 5)}...'`]); | ||
} | ||
} | ||
return (0, _data.Left)([index, `ParseError (position ${index}): Expecting string matching '${re}', but got end of input.`]); | ||
return Left([index, `ParseError (position ${index}): Expecting string matching '${re}', but got end of input.`]); | ||
}); | ||
@@ -312,9 +319,9 @@ }); | ||
if (/[0-9]/.test(rest[0])) { | ||
return (0, _data.Right)([index + 1, targetString, rest[0]]); | ||
return Right([index + 1, targetString, rest[0]]); | ||
} else { | ||
return (0, _data.Left)([index, `ParseError (position ${index}): Expecting digit, got '${rest[0]}'`]); | ||
return Left([index, `ParseError (position ${index}): Expecting digit, got '${rest[0]}'`]); | ||
} | ||
} | ||
return (0, _data.Left)([index, `ParseError (position ${index}): Expecting digit, but got end of input.`]); | ||
return Left([index, `ParseError (position ${index}): Expecting digit, but got end of input.`]); | ||
}); | ||
@@ -333,9 +340,9 @@ }); // digits :: Parser String a String | ||
if (/[a-zA-Z]/.test(rest[0])) { | ||
return (0, _data.Right)([index + 1, targetString, rest[0]]); | ||
return Right([index + 1, targetString, rest[0]]); | ||
} else { | ||
return (0, _data.Left)([index, `ParseError (position ${index}): Expecting letter, got ${rest[0]}`]); | ||
return Left([index, `ParseError (position ${index}): Expecting letter, got ${rest[0]}`]); | ||
} | ||
} | ||
return (0, _data.Left)([index, `ParseError (position ${index}): Expecting letter, but got end of input.`]); | ||
return Left([index, `ParseError (position ${index}): Expecting letter, but got end of input.`]); | ||
}); | ||
@@ -356,9 +363,9 @@ }); // letters :: Parser String a String | ||
if (s.includes(rest[0])) { | ||
return (0, _data.Right)([index + 1, targetString, rest[0]]); | ||
return Right([index + 1, targetString, rest[0]]); | ||
} else { | ||
return (0, _data.Left)([index, `ParseError (position ${index}): Expecting any of the string "${s}", got ${rest[0]}`]); | ||
return Left([index, `ParseError (position ${index}): Expecting any of the string "${s}", got ${rest[0]}`]); | ||
} | ||
} | ||
return (0, _data.Left)([index, `ParseError (position ${index}): Expecting any of the string "${s}", but got end of input.`]); | ||
return Left([index, `ParseError (position ${index}): Expecting any of the string "${s}", but got end of input.`]); | ||
}); | ||
@@ -389,3 +396,3 @@ }); | ||
const [i, s] = nextState.value; | ||
return (0, _data.Right)([i, s, results]); | ||
return Right([i, s, results]); | ||
}); | ||
@@ -416,3 +423,3 @@ }); | ||
const [i, s] = nextState.value; | ||
return (0, _data.Right)([i, s, results]); | ||
return Right([i, s, results]); | ||
}); | ||
@@ -455,3 +462,3 @@ }); | ||
const [i, s] = state.value; | ||
return (0, _data.Right)([i, s, results]); | ||
return Right([i, s, results]); | ||
} | ||
@@ -463,3 +470,3 @@ | ||
const [i, s] = nextState.value; | ||
return (0, _data.Right)([i, s, results]); | ||
return Right([i, s, results]); | ||
}); | ||
@@ -478,6 +485,6 @@ }); | ||
if (value.length === 0) { | ||
return (0, _data.Left)([index, `ParseError 'sepBy1' (position ${index}): Expecting to match at least one separated value`]); | ||
return Left([index, `ParseError 'sepBy1' (position ${index}): Expecting to match at least one separated value`]); | ||
} | ||
return (0, _data.Right)([index, targetString, value]); | ||
return Right([index, targetString, value]); | ||
}); | ||
@@ -541,5 +548,5 @@ }); | ||
results.push(val); | ||
nextState = (0, _data.Right)([index + 1, targetString, val]); | ||
nextState = Right([index + 1, targetString, val]); | ||
} else { | ||
return (0, _data.Left)([nextState[0], `ParseError 'everythingUntil' (position ${nextState.value[0]}): Unexpected end of input.`]); | ||
return Left([nextState[0], `ParseError 'everythingUntil' (position ${nextState.value[0]}): Unexpected end of input.`]); | ||
} | ||
@@ -552,3 +559,3 @@ } else { | ||
const [i, s] = nextState.value; | ||
return (0, _data.Right)([i, s, results.join('')]); | ||
return Right([i, s, results.join('')]); | ||
}); | ||
@@ -567,6 +574,6 @@ }); | ||
if (out.isLeft) { | ||
return (0, _data.Right)([index + 1, targetString, targetString[index]]); | ||
return Right([index + 1, targetString, targetString[index]]); | ||
} | ||
return (0, _data.Left)([index, `ParseError 'anythingExcept' (position ${index}): Matched '${out.value[2]}' from the exception parser`]); | ||
return Left([index, `ParseError 'anythingExcept' (position ${index}): Matched '${out.value[2]}' from the exception parser`]); | ||
}); | ||
@@ -599,3 +606,3 @@ }); | ||
if (nextState.isLeft) { | ||
return (0, _data.Right)([index, targetString, null]); | ||
return Right([index, targetString, null]); | ||
} | ||
@@ -625,6 +632,6 @@ | ||
if (index !== targetString.length) { | ||
return (0, _data.Left)([index, `ParseError 'endOfInput' (position ${index}): Expected end of input but got '${targetString.slice(index, index + 1)}'`]); | ||
return Left([index, `ParseError 'endOfInput' (position ${index}): Expected end of input but got '${targetString.slice(index, index + 1)}'`]); | ||
} | ||
return (0, _data.Right)([index, targetString, null]); | ||
return Right([index, targetString, null]); | ||
}); | ||
@@ -631,0 +638,0 @@ }); // whitespace :: Parser e a String |
{ | ||
"name": "arcsecond", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index", |
110
Readme.md
@@ -5,57 +5,61 @@ # Arcsecond | ||
<a href="https://github.com/francisrstokes/arcsecond-binary">For parsing binary data, `arcsecond` can be used with `arcsecond-binary`.</a> | ||
--- | ||
- [1. Introduction](#introduction) | ||
- [1.1 A simple parser](#a-simple-parser) | ||
- [1.2 Improving the simple parser](#improving-the-simple-parser) | ||
- [1.3 Note on currying](#note-on-currying) | ||
- [1.4 Note on error handling](#note-on-error-handling) | ||
- [2. Installation](#installation) | ||
- [3. Usage](#usage) | ||
- [4. Running the examples](#running-the-examples) | ||
- [5. API](#api) | ||
- [5.1 parse](#parse) | ||
- [5.2 char](#char) | ||
- [5.3 str](#str) | ||
- [5.4 digit](#digit) | ||
- [5.5 digits](#digits) | ||
- [5.6 letter](#letter) | ||
- [5.7 letters](#letters) | ||
- [5.8 whitespace](#whitespace) | ||
- [5.9 anyOfString](#anyofstring) | ||
- [5.10 regex](#regex) | ||
- [5.11 sequenceOf](#sequenceof) | ||
- [5.12 namedSequenceOf](#namedsequenceof) | ||
- [5.13 choice](#choice) | ||
- [5.14 lookAhead](#lookahead) | ||
- [5.15 sepBy](#sepby) | ||
- [5.16 sepBy1](#sepby1) | ||
- [5.17 many](#many) | ||
- [5.18 many1](#many1) | ||
- [5.19 between](#between) | ||
- [5.20 everythingUntil](#everythinguntil) | ||
- [5.21 anythingExcept](#anythingexcept) | ||
- [5.22 possibly](#possibly) | ||
- [5.23 skip](#skip) | ||
- [5.24 pipeParsers](#pipeparsers) | ||
- [5.25 composeParsers](#composeparsers) | ||
- [5.26 takeRight](#takeright) | ||
- [5.27 takeLeft](#takeleft) | ||
- [5.28 recursiveParser](#recursiveparser) | ||
- [5.29 tapParser](#tapparser) | ||
- [5.30 decide](#decide) | ||
- [5.31 mapTo](#mapto) | ||
- [5.32 leftMapTo](#leftmapto) | ||
- [5.33 fail](#fail) | ||
- [5.34 succeedWith](#succeedwith) | ||
- [5.35 toPromise](#topromise) | ||
- [5.36 toValue](#tovalue) | ||
- [6. A note on recursive grammars](#a-note-on-recursive-grammars) | ||
- [7. Fantasy Land](#fantasy-land) | ||
- [7.1 Equivalent Operations](#equivalent-operations) | ||
- [7.1.1 of](#of) | ||
- [7.1.2 map](#map) | ||
- [7.1.3 chain](#chain) | ||
- [7.1.4 ap](#ap) | ||
- [8. Name](#name) | ||
- [Arcsecond](#arcsecond) | ||
- [Introduction](#introduction) | ||
- [A simple parser](#a-simple-parser) | ||
- [Improving the simple parser](#improving-the-simple-parser) | ||
- [Note on currying](#note-on-currying) | ||
- [Note on error handling](#note-on-error-handling) | ||
- [Installation](#installation) | ||
- [Usage](#usage) | ||
- [Running the examples](#running-the-examples) | ||
- [API](#api) | ||
- [parse](#parse) | ||
- [char](#char) | ||
- [str](#str) | ||
- [digit](#digit) | ||
- [digits](#digits) | ||
- [letter](#letter) | ||
- [letters](#letters) | ||
- [whitespace](#whitespace) | ||
- [anyOfString](#anyofstring) | ||
- [regex](#regex) | ||
- [sequenceOf](#sequenceof) | ||
- [namedSequenceOf](#namedsequenceof) | ||
- [choice](#choice) | ||
- [lookAhead](#lookahead) | ||
- [sepBy](#sepby) | ||
- [sepBy1](#sepby1) | ||
- [many](#many) | ||
- [many1](#many1) | ||
- [between](#between) | ||
- [everythingUntil](#everythinguntil) | ||
- [anythingExcept](#anythingexcept) | ||
- [possibly](#possibly) | ||
- [endOfInput](#endofinput) | ||
- [skip](#skip) | ||
- [pipeParsers](#pipeparsers) | ||
- [composeParsers](#composeparsers) | ||
- [takeRight](#takeright) | ||
- [takeLeft](#takeleft) | ||
- [recursiveParser](#recursiveparser) | ||
- [tapParser](#tapparser) | ||
- [decide](#decide) | ||
- [mapTo](#mapto) | ||
- [leftMapTo](#leftmapto) | ||
- [fail](#fail) | ||
- [succeedWith](#succeedwith) | ||
- [toPromise](#topromise) | ||
- [toValue](#tovalue) | ||
- [A note on recursive grammars](#a-note-on-recursive-grammars) | ||
- [Fantasy Land](#fantasy-land) | ||
- [Equivalent Operations](#equivalent-operations) | ||
- [of](#of) | ||
- [map](#map) | ||
- [chain](#chain) | ||
- [ap](#ap) | ||
- [Name](#name) | ||
@@ -62,0 +66,0 @@ |
Sorry, the diff of this file is not supported yet
1107
2
273358
24
2716