Comparing version 2.0.4 to 2.0.5
@@ -8,2 +8,3 @@ { | ||
"name": "Debug File", | ||
"runtimeVersion": "14.8.0", | ||
"program": "${file}" | ||
@@ -10,0 +11,0 @@ }, |
65
index.js
@@ -53,5 +53,4 @@ "use strict"; | ||
this.p = p; | ||
} | ||
} // run :: Parser e a s ~> x -> Either e a | ||
; // run :: Parser e a s ~> x -> Either e a | ||
@@ -80,3 +79,3 @@ Parser.prototype.run = function Parser$run(targetString) { | ||
Parser.prototype.fork = function Parser$run(targetString, errorFn, successFn) { | ||
Parser.prototype.fork = function Parser$fork(targetString, errorFn, successFn) { | ||
const state = createParserState(targetString); | ||
@@ -136,5 +135,5 @@ const newState = this.p(state); | ||
Parser.prototype.errorChain = function Parser$errorMap(fn) { | ||
Parser.prototype.errorChain = function Parser$errorChain(fn) { | ||
const p = this.p; | ||
return new Parser(function Parser$errorMap$state(state) { | ||
return new Parser(function Parser$errorChain$state(state) { | ||
const nextState = p(state); | ||
@@ -189,3 +188,3 @@ | ||
Parser.prototype.mapData = function mapData(fn) { | ||
Parser.prototype.mapData = function Parser$mapData(fn) { | ||
const p = this.p; | ||
@@ -199,3 +198,3 @@ return new Parser(function mapData$state(state) { | ||
Parser['fantasy-land/of'] = function (x) { | ||
Parser['fantasy-land/of'] = function Parser$of(x) { | ||
return new Parser(state => updateResult(state, x)); | ||
@@ -237,3 +236,3 @@ }; | ||
const withData = function withData(parser) { | ||
return function withData$parser(stateData) { | ||
return function withData$stateData(stateData) { | ||
return setData(stateData).chain(() => parser); | ||
@@ -330,6 +329,8 @@ }; | ||
const coroutine = function coroutine(g) { | ||
return Parser.of().chain(_ => { | ||
return new Parser(function coroutine$state(state) { | ||
const generator = g(); | ||
let nextValue = undefined; | ||
let nextState = state; | ||
const step = nextValue => { | ||
while (true) { | ||
const result = generator.next(nextValue); | ||
@@ -339,10 +340,18 @@ const value = result.value; | ||
if (!done && (!value || typeof value.chain !== 'function')) { | ||
if (!done && !(value && value instanceof Parser)) { | ||
throw new Error(`[coroutine] yielded values must be Parsers, got ${result.value}.`); | ||
} | ||
return done ? Parser.of(value) : value.chain(step); | ||
}; | ||
if (done) { | ||
return updateResult(nextState, value); | ||
} | ||
return step(); | ||
nextState = value.p(nextState); | ||
if (nextState.isError) { | ||
return nextState; | ||
} | ||
nextValue = nextState.result; | ||
} | ||
}); | ||
@@ -404,6 +413,8 @@ }; // many :: Parser e s a -> Parser e s [a] | ||
const errorMapTo = fn => new Parser(state => { | ||
if (!state.isError) return state; | ||
return updateError(state, fn(state.error, state.index, state.data)); | ||
}); // char :: Char -> Parser e Char s | ||
const errorMapTo = function errorMapTo(fn) { | ||
return new Parser(function errorMapTo$state(state) { | ||
if (!state.isError) return state; | ||
return updateError(state, fn(state.error, state.index, state.data)); | ||
}); | ||
}; // char :: Char -> Parser e Char s | ||
@@ -679,3 +690,3 @@ | ||
return function between$rightParser(rightParser) { | ||
return function between$rightParser(parser) { | ||
return function between$parser(parser) { | ||
return sequenceOf([leftParser, parser, rightParser]).map(([_, x]) => x); | ||
@@ -808,3 +819,7 @@ }; | ||
const takeRight = lParser => rParser => lParser.chain(() => rParser); // takeLeft :: Parser e a s -> Parser f b t -> Parser e a s | ||
const takeRight = function takeRight(leftParser) { | ||
return function takeRight$rightParser(rightParser) { | ||
return leftParser.chain(() => rightParser); | ||
}; | ||
}; // takeLeft :: Parser e a s -> Parser f b t -> Parser e a s | ||
@@ -814,3 +829,7 @@ | ||
const takeLeft = lParser => rParser => lParser.chain(x => rParser.map(() => x)); // toPromise :: ParserResult e a s -> Promise (e, Integer, s) a | ||
const takeLeft = function takeLeft(leftParser) { | ||
return function takeLeft$rightParser(rightParser) { | ||
return leftParser.chain(x => rightParser.map(() => x)); | ||
}; | ||
}; // toPromise :: ParserResult e a s -> Promise (e, Integer, s) a | ||
@@ -820,3 +839,3 @@ | ||
const toPromise = result => { | ||
const toPromise = function toPromise(result) { | ||
return result.isError ? Promise.reject({ | ||
@@ -832,3 +851,3 @@ error: result.error, | ||
const toValue = result => { | ||
const toValue = function toValue(result) { | ||
if (result.isError) { | ||
@@ -835,0 +854,0 @@ const e = new Error(result.error); |
{ | ||
"name": "arcsecond", | ||
"version": "2.0.4", | ||
"version": "2.0.5", | ||
"description": "", | ||
@@ -11,3 +11,4 @@ "main": "index", | ||
"repl": "node -r esm", | ||
"build": "babel index.mjs -o index.js" | ||
"build": "babel index.mjs -o index.js", | ||
"pre-commit": "lint-staged" | ||
}, | ||
@@ -21,3 +22,2 @@ "jest": { | ||
"devDependencies": { | ||
"jest": "^24.8.0", | ||
"@babel/cli": "^7.2.3", | ||
@@ -28,4 +28,12 @@ "@babel/core": "^7.2.2", | ||
"daggy": "^1.3.0", | ||
"esm": "^3.2.25" | ||
"eslint": "^6.8.0", | ||
"eslint-config-prettier": "^6.10.0", | ||
"eslint-plugin-prettier": "^3.1.2", | ||
"esm": "^3.2.25", | ||
"husky": "^4.2.3", | ||
"jest": "^24.8.0", | ||
"lint-staged": "^10.0.8", | ||
"prettier": "^1.19.1", | ||
"standard": "^14.3.1" | ||
} | ||
} |
@@ -1,5 +0,9 @@ | ||
# Arcsecond 2.0.x | ||
# Arcsecond | ||
<img src="./logo.png"> | ||
Arcsecond is a zero-dependency, Fantasy Land compliant JavaScript [Parser Combinator](https://en.wikipedia.org/wiki/Parser_combinator) library largely inspired by Haskell's Parsec. | ||
A fairly extensive peer-library called [arcsecond-binary](https://github.com/francisrstokes/arcsecond-binary) exists for parsing binary data usiing the same functional parser combinator approach. | ||
--- | ||
@@ -6,0 +10,0 @@ |
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
1703
1
145086
14
14
1356