Comparing version 3.2.0 to 4.0.0-rc.0
153
index.d.ts
@@ -1,46 +0,117 @@ | ||
// Type definitions for construct-js | ||
// Project: https://github.com/francisrstokes/construct-js | ||
// Definitions by: | ||
// - Francis Stokes <https://github.com/francisrstokes/ | ||
declare const encoder: TextEncoder; | ||
declare const decoder: TextDecoder; | ||
declare const getString: (index: number, length: number, dataView: DataView) => string; | ||
declare const getNextCharWidth: (index: number, dataView: DataView) => 1 | 2 | 3 | 4; | ||
declare const getUtf8Char: (index: number, length: number, dataView: DataView) => string; | ||
declare const getCharacterLength: (str: string) => number; | ||
declare type ParserState<ErrorType, DataType, ResultType> = { | ||
dataView: DataView; | ||
inputType: 'string' | 'arrayBuffer' | 'typedArray' | 'dataView'; | ||
isError: boolean; | ||
error: ErrorType; | ||
result: ResultType; | ||
data: DataType; | ||
index: number; | ||
declare type TypedArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array; | ||
declare type InputType = string | ArrayBuffer | DataView | TypedArray; | ||
declare enum InputTypes { | ||
STRING = "string", | ||
ARRAY_BUFFER = "arrayBuffer", | ||
TYPED_ARRAY = "typedArray", | ||
DATA_VIEW = "dataView" | ||
} | ||
declare const updateError: <T, E, D, E2>(state: ParserState<T, E, D>, error: E2) => ParserState<T, E2, D>; | ||
declare const updateResult: <T, E, D, T2>(state: ParserState<T, E, D>, result: T2) => ParserState<T2, E, D>; | ||
declare const updateData: <T, E, D, D2>(state: ParserState<T, E, D>, data: D2) => ParserState<T, E, D2>; | ||
declare const updateParserState: <T, E, D, T2>(state: ParserState<T, E, D>, result: T2, index: number) => ParserState<T2, E, D>; | ||
declare type StateTransformerFunction<T, E = any, D = any> = (state: ParserState<any, any, any>) => ParserState<T, E, D>; | ||
declare type FnReturingParserIterator<T> = () => Iterator<Parser<any>, T>; | ||
declare type ParserState<T, E, D> = { | ||
dataView: DataView; | ||
inputType: InputType; | ||
} & InternalResultType<T, E, D>; | ||
declare type InternalResultType<T, E, D> = { | ||
isError: boolean; | ||
error: E; | ||
index: number; | ||
result: T; | ||
data: D; | ||
}; | ||
declare type StateTransformFunction< | ||
CurrentError, | ||
CurrentData, | ||
CurrentResult, | ||
NextError, | ||
NextData, | ||
NextResult, | ||
> = (state: ParserState<CurrentError, CurrentData, CurrentResult>) => ParserState<NextError, NextData, NextResult>; | ||
declare class Parser< | ||
NextError, | ||
NextData, | ||
NextResult, | ||
> { | ||
private p: StateTransformFunction<NextError, NextData, NextResult>; | ||
constructor(p: StateTransformFunction<NextError, NextData, NextResult>); | ||
declare type ResultType<T, E, D> = Err<E, D> | Ok<T, D>; | ||
declare type Err<E, D> = { | ||
isError: true; | ||
error: E; | ||
index: number; | ||
data: D; | ||
}; | ||
declare type Ok<T, D> = { | ||
isError: false; | ||
index: number; | ||
result: T; | ||
data: D; | ||
}; | ||
declare class Parser<T, E = string, D = any> { | ||
p: StateTransformerFunction<T, E, D>; | ||
constructor(p: StateTransformerFunction<T, E, D>); | ||
run(target: InputType): ResultType<T, E, D>; | ||
fork<F>(target: InputType, errorFn: (errorMsg: E, parsingState: ParserState<T, E, D>) => F, successFn: (result: T, parsingState: ParserState<T, E, D>) => F): F; | ||
map<T2>(fn: (x: T) => T2): Parser<T | T2, E, D>; | ||
chain<T2>(fn: (x?: T) => Parser<T2, E, D>): Parser<T | T2, E, D>; | ||
ap<T2>(parserOfFunction: Parser<(x: T) => T2, E, D>): Parser<T2, E, D>; | ||
errorMap<E2>(fn: (error: Err<E, D>) => E2): Parser<T, E | E2, D>; | ||
errorChain<T2>(fn: (error: Err<E, D>) => Parser<T2, E, D>): Parser<T | T2, E, D>; | ||
mapFromData<T2>(fn: (data: Ok<T, D>) => T2): Parser<T | T2, E, D>; | ||
chainFromData<T2>(fn: (data: { | ||
result: T; | ||
data: D; | ||
}) => Parser<T2, E, D>): Parser<T | T2, E, D>; | ||
mapData<D2>(fn: (data: D) => D2): Parser<T, E, D2>; | ||
static of<T, E = any, D = null>(x: T): Parser<T, E, D>; | ||
} | ||
declare type AnyParser = Parser<any, any, any>; | ||
declare type AnyState = ParserState<any, any, any>; | ||
declare const getData: Parser<any, any, any>; | ||
declare function setData<D2>(data: D2): Parser<any, any, D2>; | ||
declare function mapData<D2>(fn: (data: any) => D2): Parser<any, any, D2>; | ||
declare function withData<T, D>(parser: Parser<T, any, any>): (data: D) => Parser<T, any, D>; | ||
declare function pipeParsers(parsers: Parser<any>[]): Parser<any>; | ||
declare const composeParsers: (parsers: Parser<any>[]) => Parser<any>; | ||
declare const tapParser: (fn: (state: ParserState<any, any, any>) => void) => Parser<any>; | ||
declare function parse<T, E, D>(parser: Parser<T, E, D>): (target: InputType) => ResultType<T, E, D>; | ||
declare function decide<T>(fn: (state: ParserState<any, any, any>) => Parser<T>): Parser<T>; | ||
declare function fail<E>(errorMessage: E): Parser<any, E, any>; | ||
declare const succeedWith: typeof Parser.of; | ||
declare function either<T>(parser: Parser<T>): Parser<T>; | ||
declare function coroutine<T>(g: FnReturingParserIterator<T>): Parser<T>; | ||
declare function exactly<T>(n: number): (p: Parser<T>) => Parser<T[]>; | ||
declare const many: <T>(parser: Parser<T, string, any>) => Parser<T[], string, any>; | ||
declare const many1: <T>(parser: Parser<T, string, any>) => Parser<T[], string, any>; | ||
declare function mapTo<T>(fn: (x: any) => T): Parser<T>; | ||
declare function errorMapTo<E, D>(fn: (error: any, index: number, data: D) => E): Parser<any, E, D>; | ||
declare const char: (c: string) => Parser<string>; | ||
declare const anyChar: Parser<string>; | ||
declare const peek: Parser<number>; | ||
declare function str(s: string): Parser<string>; | ||
declare function regex(re: RegExp): Parser<string>; | ||
declare const digit: Parser<string>; | ||
declare const digits: Parser<string>; | ||
declare const letter: Parser<string>; | ||
declare const letters: Parser<string>; | ||
declare function anyOfString(s: string): Parser<string>; | ||
declare function namedSequenceOf(pairedParsers: Array<[string, Parser<any>]>): Parser<any[]>; | ||
declare function sequenceOf(parsers: Parser<any>[]): Parser<any[]>; | ||
declare function sepBy<S, T>(sepParser: Parser<S>): (valueParser: Parser<T>) => Parser<T[]>; | ||
declare const sepBy1: <S, T>(sepParser: Parser<S, string, any>) => (valueParser: Parser<T, string, any>) => Parser<T[], string, any>; | ||
declare const choice: (parsers: Parser<any>[]) => Parser<any>; | ||
declare function between<L, T, R>(leftParser: Parser<L>): (rightParser: Parser<R>) => (parser: Parser<T>) => Parser<T>; | ||
declare function everythingUntil(parser: Parser<any>): Parser<number[]>; | ||
declare const everyCharUntil: (parser: Parser<any>) => Parser<string | number[], string, any>; | ||
declare const anythingExcept: (parser: Parser<any>) => Parser<number>; | ||
declare const anyCharExcept: (parser: Parser<any>) => Parser<number>; | ||
declare function lookAhead<T>(parser: Parser<T>): Parser<T>; | ||
declare function possibly<T>(parser: Parser<T>): Parser<T | null>; | ||
declare function skip(parser: Parser<any>): Parser<null>; | ||
declare const startOfInput: Parser<null>; | ||
declare const endOfInput: Parser<null>; | ||
declare const whitespace: Parser<string>; | ||
declare const optionalWhitespace: Parser<string | null>; | ||
declare function recursiveParser<T>(parserThunk: () => Parser<T>): Parser<T>; | ||
declare function takeRight<L, R>(leftParser: Parser<L>): (rightParser: Parser<R>) => Parser<L | R, string, any>; | ||
declare const takeLeft: <L, R>(leftParser: Parser<L, string, any>) => (rightParser: Parser<R, string, any>) => Parser<L | R | undefined, string, any>; | ||
declare function toPromise<T, E, D>(result: ResultType<T, E, D>): Promise<T>; | ||
declare function toValue<T, E, D>(result: ResultType<T, E, D>): T; | ||
declare const getData: AnyParser; | ||
declare function setData<DataType>(data: DataType): Parser<any, DataType, any>; | ||
declare function mapData<FromDataType, ToDataType>(fn:(data: FromDataType) => ToDataType): Parser<any, ToDataType, any>; | ||
declare function withData<ErrorType, DataType, ResultType>(parser: Parser<ErrorType, any, ResultType>):(data: DataType) => Parser<ErrorType, DataType, ResultType>; | ||
declare function pipeParsers(parsers: AnyParser[]): AnyParser; | ||
declare function composeParsers(parsers: AnyParser[]): AnyParser; | ||
declare function tapParser(fn: (state:AnyState) => void): AnyParser; | ||
declare function decide(fn: (state:AnyState) => void): AnyParser; | ||
export { Err, FnReturingParserIterator, InputType, InputTypes, Ok, Parser, ParserState, ResultType, anyChar, anyCharExcept, anyOfString, anythingExcept, between, char, choice, composeParsers, coroutine, decide, decoder, digit, digits, either, encoder, endOfInput, errorMapTo, everyCharUntil, everythingUntil, exactly, fail, getCharacterLength, getData, getNextCharWidth, getString, getUtf8Char, letter, letters, lookAhead, many, many1, mapData, mapTo, namedSequenceOf, optionalWhitespace, parse, peek, pipeParsers, possibly, recursiveParser, regex, sepBy, sepBy1, sequenceOf, setData, skip, startOfInput, str, succeedWith, takeLeft, takeRight, tapParser, toPromise, toValue, updateData, updateError, updateParserState, updateResult, whitespace, withData }; |
1792
index.js
@@ -1,1021 +0,925 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.Parser = Parser; | ||
exports.toValue = exports.toPromise = exports.takeLeft = exports.takeRight = exports.recursiveParser = exports.optionalWhitespace = exports.whitespace = exports.endOfInput = exports.startOfInput = exports.skip = exports.possibly = exports.lookAhead = exports.anyCharExcept = exports.anythingExcept = exports.everyCharUntil = exports.everythingUntil = exports.between = exports.choice = exports.sepBy1 = exports.sepBy = exports.sequenceOf = exports.namedSequenceOf = exports.anyOfString = exports.letters = exports.letter = exports.digits = exports.digit = exports.regex = exports.str = exports.peek = exports.anyChar = exports.char = exports.errorMapTo = exports.mapTo = exports.many1 = exports.many = exports.exactly = exports.coroutine = exports.either = exports.succeedWith = exports.fail = exports.decide = exports.parse = exports.tapParser = exports.composeParsers = exports.pipeParsers = exports.withData = exports.mapData = exports.setData = exports.getData = void 0; | ||
const reDigit = /[0-9]/; | ||
const reDigits = /^[0-9]+/; | ||
const reLetter = /[a-zA-Z]/; | ||
const reLetters = /^[a-zA-Z]+/; | ||
const reWhitespaces = /^\s+/; | ||
const reErrorExpectation = /ParseError.+Expecting/; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
const isTypedArray = x => x instanceof Uint8Array || x instanceof Uint8ClampedArray || x instanceof Int8Array || x instanceof Uint16Array || x instanceof Int16Array || x instanceof Uint32Array || x instanceof Int32Array || x instanceof Float32Array || x instanceof Float64Array; | ||
const inputTypes = { | ||
STRING: 'string', | ||
ARRAY_BUFFER: 'arrayBuffer', | ||
TYPED_ARRAY: 'typedArray', | ||
DATA_VIEW: 'dataView' | ||
}; | ||
const text = {}; | ||
let text; | ||
if (typeof TextEncoder !== 'undefined') { | ||
text.Encoder = TextEncoder; | ||
text.Decoder = TextDecoder; | ||
} else { | ||
try { | ||
const util = require('util'); | ||
text.Encoder = util.TextEncoder; | ||
text.Decoder = util.TextDecoder; | ||
} catch (ex) { | ||
throw new Error('Arcsecond requires TextEncoder and TextDecoder to be polyfilled.'); | ||
} | ||
text = { Encoder: TextEncoder, Decoder: TextDecoder }; | ||
} | ||
else { | ||
try { | ||
const util = require('util'); | ||
text = { Encoder: util.TextEncoder, Decoder: util.TextDecoder }; | ||
} | ||
catch (ex) { | ||
throw new Error('Arcsecond requires TextEncoder and TextDecoder to be polyfilled.'); | ||
} | ||
} | ||
const encoder = new text.Encoder(); | ||
const decoder = new text.Decoder(); | ||
const getString = (index, length, dataView) => { | ||
const bytes = Uint8Array.from({ | ||
length | ||
}, (_, i) => dataView.getUint8(index + i)); | ||
const decodedString = decoder.decode(bytes); | ||
return decodedString; | ||
const bytes = Uint8Array.from({ length }, (_, i) => dataView.getUint8(index + i)); | ||
const decodedString = decoder.decode(bytes); | ||
return decodedString; | ||
}; | ||
const getNextCharWidth = (index, dataView) => { | ||
const byte = dataView.getUint8(index); | ||
if ((byte & 0x80) >> 7 === 0) return 1;else if ((byte & 0xe0) >> 5 === 0b110) return 2;else if ((byte & 0xf0) >> 4 === 0b1110) return 3;else if ((byte & 0xf0) >> 4 === 0b1111) return 4; | ||
return 1; | ||
const byte = dataView.getUint8(index); | ||
if ((byte & 0x80) >> 7 === 0) | ||
return 1; | ||
else if ((byte & 0xe0) >> 5 === 0b110) | ||
return 2; | ||
else if ((byte & 0xf0) >> 4 === 0b1110) | ||
return 3; | ||
else if ((byte & 0xf0) >> 4 === 0b1111) | ||
return 4; | ||
return 1; | ||
}; | ||
const getUtf8Char = (index, length, dataView) => { | ||
const bytes = Uint8Array.from({ | ||
length | ||
}, (_, i) => dataView.getUint8(index + i)); | ||
return decoder.decode(bytes); | ||
const bytes = Uint8Array.from({ length }, (_, i) => dataView.getUint8(index + i)); | ||
return decoder.decode(bytes); | ||
}; | ||
const getCharacterLength = str => { | ||
let cp; | ||
let total = 0; | ||
let i = 0; | ||
while (i < str.length) { | ||
cp = str.codePointAt(i); | ||
while (cp) { | ||
cp = cp >> 8; | ||
i++; | ||
const getCharacterLength = (str) => { | ||
let cp; | ||
let total = 0; | ||
let i = 0; | ||
while (i < str.length) { | ||
cp = str.codePointAt(i); | ||
while (cp) { | ||
cp = cp >> 8; | ||
i++; | ||
} | ||
total++; | ||
} | ||
return total; | ||
}; | ||
total++; | ||
} | ||
const isTypedArray = (x) => x instanceof Uint8Array || | ||
x instanceof Uint8ClampedArray || | ||
x instanceof Int8Array || | ||
x instanceof Uint16Array || | ||
x instanceof Int16Array || | ||
x instanceof Uint32Array || | ||
x instanceof Int32Array || | ||
x instanceof Float32Array || | ||
x instanceof Float64Array; | ||
exports.InputTypes = void 0; | ||
(function (InputTypes) { | ||
InputTypes["STRING"] = "string"; | ||
InputTypes["ARRAY_BUFFER"] = "arrayBuffer"; | ||
InputTypes["TYPED_ARRAY"] = "typedArray"; | ||
InputTypes["DATA_VIEW"] = "dataView"; | ||
})(exports.InputTypes || (exports.InputTypes = {})); | ||
return total; | ||
}; | ||
// createParserState :: x -> s -> ParserState e a s | ||
const createParserState = (target, data = null) => { | ||
let dataView; | ||
let inputType; | ||
if (typeof target === 'string') { | ||
const bytes = encoder.encode(target); | ||
dataView = new DataView(bytes.buffer); | ||
inputType = inputTypes.STRING; | ||
} else if (target instanceof ArrayBuffer) { | ||
dataView = new DataView(target); | ||
inputType = inputTypes.ARRAY_BUFFER; | ||
} else if (isTypedArray(target)) { | ||
dataView = new DataView(target.buffer); | ||
inputType = inputTypes.TYPED_ARRAY; | ||
} else if (target instanceof DataView) { | ||
dataView = target; | ||
inputType = inputTypes.DATA_VIEW; | ||
} else { | ||
throw new Error(`Cannot process input. Must be a string, ArrayBuffer, TypedArray, or DataView. but got ${typeof target}`); | ||
} | ||
return { | ||
dataView, | ||
inputType, | ||
isError: false, | ||
error: null, | ||
data, | ||
index: 0, | ||
result: null | ||
}; | ||
}; | ||
const updateError = (state, error) => ({ ...state, | ||
isError: true, | ||
error | ||
}); | ||
const updateResult = (state, result) => ({ ...state, | ||
result | ||
}); | ||
const updateData = (state, data) => ({ ...state, | ||
data | ||
}); | ||
const updateParserState = (state, result, index) => ({ ...state, | ||
result, | ||
index | ||
}); | ||
function Parser(p) { | ||
this.p = p; | ||
} | ||
Parser.prototype.run = function Parser$run(target) { | ||
const state = createParserState(target, null); | ||
const resultState = this.p(state); | ||
if (resultState.isError) { | ||
let dataView; | ||
let inputType; | ||
if (typeof target === 'string') { | ||
const bytes = encoder.encode(target); | ||
dataView = new DataView(bytes.buffer); | ||
inputType = exports.InputTypes.STRING; | ||
} | ||
else if (target instanceof ArrayBuffer) { | ||
dataView = new DataView(target); | ||
inputType = exports.InputTypes.ARRAY_BUFFER; | ||
} | ||
else if (isTypedArray(target)) { | ||
dataView = new DataView(target.buffer); | ||
inputType = exports.InputTypes.TYPED_ARRAY; | ||
} | ||
else if (target instanceof DataView) { | ||
dataView = target; | ||
inputType = exports.InputTypes.DATA_VIEW; | ||
} | ||
else { | ||
throw new Error(`Cannot process input. Must be a string, ArrayBuffer, TypedArray, or DataView. but got ${typeof target}`); | ||
} | ||
return { | ||
isError: true, | ||
error: resultState.error, | ||
index: resultState.index, | ||
data: resultState.data | ||
dataView, | ||
inputType, | ||
isError: false, | ||
error: null, | ||
result: null, | ||
data, | ||
index: 0, | ||
}; | ||
} | ||
return { | ||
isError: false, | ||
result: resultState.result, | ||
index: resultState.index, | ||
data: resultState.data | ||
}; | ||
}; | ||
Parser.prototype.fork = function Parser$fork(target, errorFn, successFn) { | ||
const state = createParserState(target); | ||
const newState = this.p(state); | ||
if (newState.isError) { | ||
return errorFn(newState.error, newState); | ||
} | ||
return successFn(newState.result, newState); | ||
}; | ||
Parser.prototype['fantasy-land/map'] = function Parser$map(fn) { | ||
const p = this.p; | ||
return new Parser(function Parser$map$state(state) { | ||
const newState = p(state); | ||
if (newState.isError) return newState; | ||
return updateResult(newState, fn(newState.result)); | ||
}); | ||
}; | ||
Parser.prototype['fantasy-land/chain'] = function Parser$chain(fn) { | ||
const p = this.p; | ||
return new Parser(function Parser$chain$state(state) { | ||
const newState = p(state); | ||
if (newState.isError) return newState; | ||
return fn(newState.result).p(newState); | ||
}); | ||
}; | ||
Parser.prototype['fantasy-land/ap'] = function Parser$ap(parserOfFunction) { | ||
const p = this.p; | ||
return new Parser(function Parser$ap$state(state) { | ||
if (state.isError) return state; | ||
const argumentState = p(state); | ||
if (argumentState.isError) return argumentState; | ||
const fnState = parserOfFunction.p(argumentState); | ||
if (fnState.isError) return fnState; | ||
return updateResult(fnState, fnState.result(argumentState.result)); | ||
}); | ||
}; | ||
Parser.prototype.errorMap = function Parser$errorMap(fn) { | ||
const p = this.p; | ||
return new Parser(function Parser$errorMap$state(state) { | ||
const nextState = p(state); | ||
if (!nextState.isError) return nextState; | ||
return updateError(nextState, fn({ | ||
error: nextState.error, | ||
index: nextState.index, | ||
data: nextState.data | ||
})); | ||
}); | ||
}; | ||
Parser.prototype.errorChain = function Parser$errorChain(fn) { | ||
const p = this.p; | ||
return new Parser(function Parser$errorChain$state(state) { | ||
const nextState = p(state); | ||
if (nextState.isError) { | ||
const { | ||
error, | ||
index, | ||
data | ||
} = nextState; | ||
const nextParser = fn({ | ||
error, | ||
index, | ||
data | ||
}); | ||
return nextParser.p({ ...nextState, | ||
isError: false | ||
}); | ||
// updateError :: (ParserState e a s, f) -> ParserState f a s | ||
const updateError = (state, error) => (Object.assign(Object.assign({}, state), { isError: true, error })); | ||
// updateResult :: (ParserState e a s, b) -> ParserState e b s | ||
const updateResult = (state, result) => (Object.assign(Object.assign({}, state), { result })); | ||
// updateData :: (ParserState e a s, t) -> ParserState e b t | ||
const updateData = (state, data) => (Object.assign(Object.assign({}, state), { data })); | ||
// updateResult :: (ParserState e a s, b, Integer) -> ParserState e b s | ||
const updateParserState = (state, result, index) => (Object.assign(Object.assign({}, state), { result, | ||
index })); | ||
class Parser { | ||
constructor(p) { | ||
this.p = p; | ||
} | ||
// run :: Parser e a s ~> x -> Either e a | ||
run(target) { | ||
const state = createParserState(target); | ||
const resultState = this.p(state); | ||
if (resultState.isError) { | ||
return { | ||
isError: true, | ||
error: resultState.error, | ||
index: resultState.index, | ||
data: resultState.data, | ||
}; | ||
} | ||
return { | ||
isError: false, | ||
result: resultState.result, | ||
index: resultState.index, | ||
data: resultState.data, | ||
}; | ||
} | ||
// fork :: Parser e a s ~> x -> (e -> ParserState e a s -> f) -> (a -> ParserState e a s -> b) | ||
fork(target, errorFn, successFn) { | ||
const state = createParserState(target); | ||
const newState = this.p(state); | ||
if (newState.isError) { | ||
return errorFn(newState.error, newState); | ||
} | ||
return successFn(newState.result, newState); | ||
} | ||
// map :: Parser e a s ~> (a -> b) -> Parser e b s | ||
map(fn) { | ||
const p = this.p; | ||
return new Parser(function Parser$map$state(state) { | ||
const newState = p(state); | ||
if (newState.isError) | ||
return newState; | ||
return updateResult(newState, fn(newState.result)); | ||
}); | ||
} | ||
// chain :: Parser e a s ~> (a -> Parser e b s) -> Parser e b s | ||
chain(fn) { | ||
const p = this.p; | ||
return new Parser(function Parser$chain$state(state) { | ||
const newState = p(state); | ||
if (newState.isError) | ||
return newState; | ||
return fn(newState.result).p(newState); | ||
}); | ||
} | ||
// ap :: Parser e a s ~> Parser e (a -> b) s -> Parser e b s | ||
ap(parserOfFunction) { | ||
const p = this.p; | ||
return new Parser(function Parser$ap$state(state) { | ||
if (state.isError) | ||
return state; | ||
const argumentState = p(state); | ||
if (argumentState.isError) | ||
return argumentState; | ||
const fnState = parserOfFunction.p(argumentState); | ||
if (fnState.isError) | ||
return fnState; | ||
return updateResult(fnState, fnState.result(argumentState.result)); | ||
}); | ||
} | ||
// errorMap :: Parser e a s ~> (e -> f) -> Parser f a s | ||
errorMap(fn) { | ||
const p = this.p; | ||
return new Parser(function Parser$errorMap$state(state) { | ||
const nextState = p(state); | ||
if (!nextState.isError) | ||
return nextState; | ||
return updateError(nextState, fn({ | ||
isError: true, | ||
error: nextState.error, | ||
index: nextState.index, | ||
data: nextState.data, | ||
})); | ||
}); | ||
} | ||
// errorChain :: Parser e a s ~> ((e, Integer, s) -> Parser f a s) -> Parser f a s | ||
errorChain(fn) { | ||
const p = this.p; | ||
return new Parser(function Parser$errorChain$state(state) { | ||
const nextState = p(state); | ||
if (nextState.isError) { | ||
const { error, index, data } = nextState; | ||
const nextParser = fn({ isError: true, error, index, data }); | ||
return nextParser.p(Object.assign(Object.assign({}, nextState), { isError: false })); | ||
} | ||
return nextState; | ||
}); | ||
} | ||
// mapFromData :: Parser e a s ~> (StateData a s -> b) -> Parser e b s | ||
mapFromData(fn) { | ||
const p = this.p; | ||
return new Parser((state) => { | ||
const newState = p(state); | ||
if (newState.isError && newState.error) | ||
return newState; | ||
return updateResult(newState, fn({ | ||
isError: false, | ||
result: newState.result, | ||
data: newState.data, | ||
index: newState.index, | ||
})); | ||
}); | ||
} | ||
// chainFromData :: Parser e a s ~> (StateData a s -> Parser f b t) -> Parser f b t | ||
chainFromData(fn) { | ||
const p = this.p; | ||
return new Parser(function Parser$chainFromData$state(state) { | ||
const newState = p(state); | ||
if (newState.isError && newState.error) | ||
return newState; | ||
return fn({ result: newState.result, data: newState.data }).p(newState); | ||
}); | ||
} | ||
// mapData :: Parser e a s ~> (s -> t) -> Parser e a t | ||
mapData(fn) { | ||
const p = this.p; | ||
return new Parser(function mapData$state(state) { | ||
const newState = p(state); | ||
return updateData(newState, fn(newState.data)); | ||
}); | ||
} | ||
// of :: a -> Parser e a s | ||
static of(x) { | ||
return new Parser(state => updateResult(state, x)); | ||
} | ||
} | ||
return nextState; | ||
}); | ||
}; | ||
Parser.prototype.mapFromData = function Parser$mapFromData(fn) { | ||
const p = this.p; | ||
return new Parser(function Parser$mapFromData$state(state) { | ||
const newState = p(state); | ||
if (newState.error) return newState; | ||
return updateResult(newState, fn({ | ||
result: newState.result, | ||
data: newState.data | ||
})); | ||
}); | ||
}; | ||
Parser.prototype.chainFromData = function Parser$chainFromData(fn) { | ||
const p = this.p; | ||
return new Parser(function Parser$chainFromData$state(state) { | ||
const newState = p(state); | ||
if (newState.error) return newState; | ||
return fn({ | ||
result: newState.result, | ||
data: newState.data | ||
}).p(newState); | ||
}); | ||
}; | ||
Parser.prototype.mapData = function Parser$mapData(fn) { | ||
const p = this.p; | ||
return new Parser(function mapData$state(state) { | ||
const newState = p(state); | ||
return updateData(newState, fn(newState.data)); | ||
}); | ||
}; | ||
Parser['fantasy-land/of'] = function Parser$of(x) { | ||
return new Parser(state => updateResult(state, x)); | ||
}; | ||
Parser.prototype.map = Parser.prototype['fantasy-land/map']; | ||
Parser.prototype.ap = Parser.prototype['fantasy-land/ap']; | ||
Parser.prototype.chain = Parser.prototype['fantasy-land/chain']; | ||
Parser.of = Parser['fantasy-land/of']; | ||
// Caching compiled regexs for better performance | ||
const reDigit = /[0-9]/; | ||
const reDigits = /^[0-9]+/; | ||
const reLetter = /[a-zA-Z]/; | ||
const reLetters = /^[a-zA-Z]+/; | ||
const reWhitespaces = /^\s+/; | ||
const reErrorExpectation = /ParseError.+Expecting/; | ||
// getData :: Parser e a s | ||
const getData = new Parser(function getData$state(state) { | ||
if (state.isError) return state; | ||
return updateResult(state, state.data); | ||
if (state.isError) | ||
return state; | ||
return updateResult(state, state.data); | ||
}); | ||
exports.getData = getData; | ||
const setData = function setData(x) { | ||
return new Parser(function setData$state(state) { | ||
if (state.isError) return state; | ||
return updateData(state, x); | ||
}); | ||
}; | ||
exports.setData = setData; | ||
const mapData = function mapData(fn) { | ||
return new Parser(function mapData$state(state) { | ||
if (state.isError) return state; | ||
return updateData(state, fn(state.data)); | ||
}); | ||
}; | ||
exports.mapData = mapData; | ||
const withData = function withData(parser) { | ||
return function withData$stateData(stateData) { | ||
return setData(stateData).chain(() => parser); | ||
}; | ||
}; | ||
exports.withData = withData; | ||
const pipeParsers = function pipeParsers(parsers) { | ||
return new Parser(function pipeParsers$state(state) { | ||
let nextState = state; | ||
for (const parser of parsers) { | ||
nextState = parser.p(nextState); | ||
} | ||
return nextState; | ||
}); | ||
}; | ||
exports.pipeParsers = pipeParsers; | ||
// setData :: t -> Parser e a t | ||
function setData(data) { | ||
return new Parser(function setData$state(state) { | ||
if (state.isError) | ||
return state; | ||
return updateData(state, data); | ||
}); | ||
} | ||
// mapData :: (s -> t) -> Parser e a t | ||
function mapData(fn) { | ||
return new Parser(function mapData$state(state) { | ||
if (state.isError) | ||
return state; | ||
return updateData(state, fn(state.data)); | ||
}); | ||
} | ||
// withData :: Parser e a x -> s -> Parser e a s | ||
function withData(parser) { | ||
return function withData$stateData(stateData) { | ||
return setData(stateData).chain(() => parser); | ||
}; | ||
} | ||
// pipeParsers :: [Parser * * *] -> Parser * * * | ||
function pipeParsers(parsers) { | ||
return new Parser(function pipeParsers$state(state) { | ||
let nextState = state; | ||
for (const parser of parsers) { | ||
nextState = parser.p(nextState); | ||
} | ||
return nextState; | ||
}); | ||
} | ||
// composeParsers :: [Parser * * *] -> Parser * * * | ||
const composeParsers = function composeParsers(parsers) { | ||
return new Parser(function composeParsers$state(state) { | ||
return pipeParsers([...parsers].reverse()).p(state); | ||
}); | ||
return new Parser(function composeParsers$state(state) { | ||
return pipeParsers([...parsers].reverse()).p(state); | ||
}); | ||
}; | ||
exports.composeParsers = composeParsers; | ||
// tapParser :: (a => ()) -> Parser e a s | ||
const tapParser = function tapParser(fn) { | ||
return new Parser(function tapParser$state(state) { | ||
fn(state); | ||
return state; | ||
}); | ||
return new Parser(function tapParser$state(state) { | ||
fn(state); | ||
return state; | ||
}); | ||
}; | ||
exports.tapParser = tapParser; | ||
const parse = function parse(parser) { | ||
return function parse$targetString(target) { | ||
return parser.run(target); | ||
}; | ||
}; | ||
exports.parse = parse; | ||
const decide = function decide(fn) { | ||
return new Parser(function decide$state(state) { | ||
if (state.isError) return state; | ||
const parser = fn(state.result); | ||
return parser.p(state); | ||
}); | ||
}; | ||
exports.decide = decide; | ||
const fail = function fail(errorMessage) { | ||
return new Parser(function fail$state(state) { | ||
if (state.isError) return state; | ||
return updateError(state, errorMessage); | ||
}); | ||
}; | ||
exports.fail = fail; | ||
// parse :: Parser e a s -> String -> Either e a | ||
function parse(parser) { | ||
return function parse$targetString(target) { | ||
return parser.run(target); | ||
}; | ||
} | ||
// decide :: (a -> Parser e b s) -> Parser e b s | ||
function decide(fn) { | ||
return new Parser(function decide$state(state) { | ||
if (state.isError) | ||
return state; | ||
const parser = fn(state.result); | ||
return parser.p(state); | ||
}); | ||
} | ||
// fail :: e -> Parser e a s | ||
function fail(errorMessage) { | ||
return new Parser(function fail$state(state) { | ||
if (state.isError) | ||
return state; | ||
return updateError(state, errorMessage); | ||
}); | ||
} | ||
// succeedWith :: a -> Parser e a s | ||
const succeedWith = Parser.of; | ||
exports.succeedWith = succeedWith; | ||
const either = function either(parser) { | ||
return new Parser(function either$state(state) { | ||
if (state.isError) return state; | ||
const nextState = parser.p(state); | ||
return updateResult({ ...nextState, | ||
isError: false | ||
}, { | ||
isError: nextState.isError, | ||
value: nextState.isError ? nextState.error : nextState.result | ||
// either :: Parser e a s -> Parser e (Either e a) s | ||
function either(parser) { | ||
return new Parser(function either$state(state) { | ||
if (state.isError) | ||
return state; | ||
const nextState = parser.p(state); | ||
return updateResult(Object.assign(Object.assign({}, nextState), { isError: false }), { | ||
isError: nextState.isError, | ||
value: nextState.isError ? nextState.error : nextState.result, | ||
}); | ||
}); | ||
}); | ||
}; | ||
exports.either = either; | ||
const coroutine = function coroutine(g) { | ||
return new Parser(function coroutine$state(state) { | ||
const generator = g(); | ||
let nextValue = undefined; | ||
let nextState = state; | ||
while (true) { | ||
const result = generator.next(nextValue); | ||
const value = result.value; | ||
const done = result.done; | ||
if (!done && !(value && value instanceof Parser)) { | ||
throw new Error(`[coroutine] yielded values must be Parsers, got ${result.value}.`); | ||
} | ||
if (done) { | ||
return updateResult(nextState, value); | ||
} | ||
nextState = value.p(nextState); | ||
if (nextState.isError) { | ||
return nextState; | ||
} | ||
nextValue = nextState.result; | ||
} | ||
// coroutine :: (() -> Iterator (Parser e a s)) -> Parser e a s | ||
function coroutine(g) { | ||
return new Parser(function coroutine$state(state) { | ||
const generator = g(); | ||
let nextValue = undefined; | ||
let nextState = state; | ||
while (true) { | ||
const result = generator.next(nextValue); | ||
const value = result.value; | ||
const done = result.done; | ||
if (done) { | ||
return updateResult(nextState, value); | ||
} | ||
if (!(value && value instanceof Parser)) { | ||
throw new Error(`[coroutine] yielded values must be Parsers, got ${result.value}.`); | ||
} | ||
nextState = value.p(nextState); | ||
if (nextState.isError) { | ||
return nextState; | ||
} | ||
nextValue = nextState.result; | ||
} | ||
}); | ||
} | ||
// exactly :: (Integer) -> (Parser e s a) -> Parser e s [a] | ||
function exactly(n) { | ||
if (typeof n !== 'number' || n <= 0) { | ||
throw new TypeError(`exactly must be called with a number > 0, but got ${n}`); | ||
} | ||
}); | ||
}; | ||
exports.coroutine = coroutine; | ||
const exactly = function exactly(n) { | ||
if (typeof n !== 'number' || n <= 0) { | ||
throw new TypeError(`exactly must be called with a number > 0, but got ${n}`); | ||
} | ||
return function exactly$factory(parser) { | ||
return new Parser(function exactly$factory$state(state) { | ||
if (state.isError) return state; | ||
const results = []; | ||
let nextState = state; | ||
for (let i = 0; i < n; i++) { | ||
const out = parser.p(nextState); | ||
if (out.isError) { | ||
return out; | ||
} else { | ||
nextState = out; | ||
results.push(nextState.result); | ||
} | ||
} | ||
return updateResult(nextState, results); | ||
}).errorMap(({ | ||
index, | ||
error | ||
}) => `ParseError (position ${index}): Expecting ${n}${error.replace(reErrorExpectation, '')}`); | ||
}; | ||
}; | ||
exports.exactly = exactly; | ||
return function exactly$factory(parser) { | ||
return new Parser(function exactly$factory$state(state) { | ||
if (state.isError) | ||
return state; | ||
const results = []; | ||
let nextState = state; | ||
for (let i = 0; i < n; i++) { | ||
const out = parser.p(nextState); | ||
if (out.isError) { | ||
return out; | ||
} | ||
else { | ||
nextState = out; | ||
results.push(nextState.result); | ||
} | ||
} | ||
return updateResult(nextState, results); | ||
}).errorMap(({ index, error }) => `ParseError (position ${index}): Expecting ${n}${error.replace(reErrorExpectation, '')}`); | ||
}; | ||
} | ||
// many :: Parser e s a -> Parser e s [a] | ||
const many = function many(parser) { | ||
return new Parser(function many$state(state) { | ||
if (state.isError) return state; | ||
const results = []; | ||
let nextState = state; | ||
while (true) { | ||
const out = parser.p(nextState); | ||
if (out.isError) { | ||
break; | ||
} else { | ||
nextState = out; | ||
results.push(nextState.result); | ||
if (nextState.index >= nextState.dataView.byteLength) { | ||
break; | ||
return new Parser(function many$state(state) { | ||
if (state.isError) | ||
return state; | ||
const results = []; | ||
let nextState = state; | ||
while (true) { | ||
const out = parser.p(nextState); | ||
if (out.isError) { | ||
break; | ||
} | ||
else { | ||
nextState = out; | ||
results.push(nextState.result); | ||
if (nextState.index >= nextState.dataView.byteLength) { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return updateResult(nextState, results); | ||
}); | ||
return updateResult(nextState, results); | ||
}); | ||
}; | ||
exports.many = many; | ||
// many1 :: Parser e s a -> Parser e s [a] | ||
const many1 = function many1(parser) { | ||
return new Parser(function many1$state(state) { | ||
if (state.isError) return state; | ||
const resState = many(parser).p(state); | ||
if (resState.result.length) return resState; | ||
return updateError(state, `ParseError 'many1' (position ${state.index}): Expecting to match at least one value`); | ||
}); | ||
return new Parser(function many1$state(state) { | ||
if (state.isError) | ||
return state; | ||
const resState = many(parser).p(state); | ||
if (resState.result.length) | ||
return resState; | ||
return updateError(state, `ParseError 'many1' (position ${state.index}): Expecting to match at least one value`); | ||
}); | ||
}; | ||
exports.many1 = many1; | ||
const mapTo = function mapTo(fn) { | ||
return new Parser(function mapTo$state(state) { | ||
if (state.isError) return state; | ||
return updateResult(state, fn(state.result)); | ||
}); | ||
}; | ||
exports.mapTo = mapTo; | ||
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)); | ||
}); | ||
}; | ||
exports.errorMapTo = errorMapTo; | ||
// mapTo :: (a -> b) -> Parser e b s | ||
function mapTo(fn) { | ||
return new Parser(function mapTo$state(state) { | ||
if (state.isError) | ||
return state; | ||
return updateResult(state, fn(state.result)); | ||
}); | ||
} | ||
// errorMapTo :: (ParserState e a s -> f) -> Parser f a s | ||
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 | ||
const char = function char(c) { | ||
if (!c || getCharacterLength(c) !== 1) { | ||
throw new TypeError(`char must be called with a single character, but got ${c}`); | ||
} | ||
return new Parser(function char$state(state) { | ||
if (state.isError) return state; | ||
const { | ||
index, | ||
dataView | ||
} = state; | ||
if (index < dataView.byteLength) { | ||
const charWidth = getNextCharWidth(index, dataView); | ||
if (index + charWidth <= dataView.byteLength) { | ||
const char = getUtf8Char(index, charWidth, dataView); | ||
return char === c ? updateParserState(state, c, index + charWidth) : updateError(state, `ParseError (position ${index}): Expecting character '${c}', got '${char}'`); | ||
} | ||
if (!c || getCharacterLength(c) !== 1) { | ||
throw new TypeError(`char must be called with a single character, but got ${c}`); | ||
} | ||
return updateError(state, `ParseError (position ${index}): Expecting character '${c}', but got end of input.`); | ||
}); | ||
return new Parser(function char$state(state) { | ||
if (state.isError) | ||
return state; | ||
const { index, dataView } = state; | ||
if (index < dataView.byteLength) { | ||
const charWidth = getNextCharWidth(index, dataView); | ||
if (index + charWidth <= dataView.byteLength) { | ||
const char = getUtf8Char(index, charWidth, dataView); | ||
return char === c | ||
? updateParserState(state, c, index + charWidth) | ||
: updateError(state, `ParseError (position ${index}): Expecting character '${c}', got '${char}'`); | ||
} | ||
} | ||
return updateError(state, `ParseError (position ${index}): Expecting character '${c}', but got end of input.`); | ||
}); | ||
}; | ||
exports.char = char; | ||
// anyChar :: Parser e Char s | ||
const anyChar = new Parser(function anyChar$state(state) { | ||
if (state.isError) return state; | ||
const { | ||
index, | ||
dataView | ||
} = state; | ||
if (index < dataView.byteLength) { | ||
const charWidth = getNextCharWidth(index, dataView); | ||
if (index + charWidth <= dataView.byteLength) { | ||
const char = getUtf8Char(index, charWidth, dataView); | ||
return updateParserState(state, char, index + charWidth); | ||
if (state.isError) | ||
return state; | ||
const { index, dataView } = state; | ||
if (index < dataView.byteLength) { | ||
const charWidth = getNextCharWidth(index, dataView); | ||
if (index + charWidth <= dataView.byteLength) { | ||
const char = getUtf8Char(index, charWidth, dataView); | ||
return updateParserState(state, char, index + charWidth); | ||
} | ||
} | ||
} | ||
return updateError(state, `ParseError (position ${index}): Expecting a character, but got end of input.`); | ||
return updateError(state, `ParseError (position ${index}): Expecting a character, but got end of input.`); | ||
}); | ||
exports.anyChar = anyChar; | ||
// peek :: Parser e Char s | ||
const peek = new Parser(function peek$state(state) { | ||
if (state.isError) return state; | ||
const { | ||
index, | ||
dataView | ||
} = state; | ||
if (index < dataView.byteLength) { | ||
return updateParserState(state, dataView.getUint8(index), index); | ||
} | ||
return updateError(state, `ParseError (position ${index}): Unexpected end of input.`); | ||
if (state.isError) | ||
return state; | ||
const { index, dataView } = state; | ||
if (index < dataView.byteLength) { | ||
return updateParserState(state, dataView.getUint8(index), index); | ||
} | ||
return updateError(state, `ParseError (position ${index}): Unexpected end of input.`); | ||
}); | ||
exports.peek = peek; | ||
const str = function str(s) { | ||
if (!s || getCharacterLength(s) < 1) { | ||
throw new TypeError(`str must be called with a string with length > 1, but got ${s}`); | ||
} | ||
const encodedStr = encoder.encode(s); | ||
return new Parser(function str$state(state) { | ||
const { | ||
index, | ||
dataView | ||
} = state; | ||
const remainingBytes = dataView.byteLength - index; | ||
if (remainingBytes < encodedStr.byteLength) { | ||
return updateError(state, `ParseError (position ${index}): Expecting string '${s}', but got end of input.`); | ||
// str :: String -> Parser e String s | ||
function str(s) { | ||
if (!s || getCharacterLength(s) < 1) { | ||
throw new TypeError(`str must be called with a string with length > 1, but got ${s}`); | ||
} | ||
const stringAtIndex = getString(index, encodedStr.byteLength, dataView); | ||
return s === stringAtIndex ? updateParserState(state, s, index + encoder.encode(s).byteLength) : updateError(state, `ParseError (position ${index}): Expecting string '${s}', got '${stringAtIndex}...'`); | ||
}); | ||
}; | ||
exports.str = str; | ||
const regex = function regex(re) { | ||
const typeofre = Object.prototype.toString.call(re); | ||
if (typeofre !== '[object RegExp]') { | ||
throw new TypeError(`regex must be called with a Regular Expression, but got ${typeofre}`); | ||
} | ||
if (re.toString()[1] !== '^') { | ||
throw new Error(`regex parsers must contain '^' start assertion.`); | ||
} | ||
return new Parser(function regex$state(state) { | ||
if (state.isError) return state; | ||
const { | ||
dataView, | ||
index | ||
} = state; | ||
const rest = getString(index, dataView.byteLength - index, dataView); | ||
if (rest.length >= 1) { | ||
const match = rest.match(re); | ||
return match ? updateParserState(state, match[0], index + encoder.encode(match[0]).byteLength) : updateError(state, `ParseError (position ${index}): Expecting string matching '${re}', got '${rest.slice(0, 5)}...'`); | ||
const encodedStr = encoder.encode(s); | ||
return new Parser(function str$state(state) { | ||
const { index, dataView } = state; | ||
const remainingBytes = dataView.byteLength - index; | ||
if (remainingBytes < encodedStr.byteLength) { | ||
return updateError(state, `ParseError (position ${index}): Expecting string '${s}', but got end of input.`); | ||
} | ||
const stringAtIndex = getString(index, encodedStr.byteLength, dataView); | ||
return s === stringAtIndex | ||
? updateParserState(state, s, index + encoder.encode(s).byteLength) | ||
: updateError(state, `ParseError (position ${index}): Expecting string '${s}', got '${stringAtIndex}...'`); | ||
}); | ||
} | ||
// regex :: RegExp -> Parser e String s | ||
function regex(re) { | ||
const typeofre = Object.prototype.toString.call(re); | ||
if (typeofre !== '[object RegExp]') { | ||
throw new TypeError(`regex must be called with a Regular Expression, but got ${typeofre}`); | ||
} | ||
return updateError(state, `ParseError (position ${index}): Expecting string matching '${re}', but got end of input.`); | ||
}); | ||
}; | ||
exports.regex = regex; | ||
if (re.toString()[1] !== '^') { | ||
throw new Error(`regex parsers must contain '^' start assertion.`); | ||
} | ||
return new Parser(function regex$state(state) { | ||
if (state.isError) | ||
return state; | ||
const { dataView, index } = state; | ||
const rest = getString(index, dataView.byteLength - index, dataView); | ||
if (rest.length >= 1) { | ||
const match = rest.match(re); | ||
return match | ||
? updateParserState(state, match[0], index + encoder.encode(match[0]).byteLength) | ||
: updateError(state, `ParseError (position ${index}): Expecting string matching '${re}', got '${rest.slice(0, 5)}...'`); | ||
} | ||
return updateError(state, `ParseError (position ${index}): Expecting string matching '${re}', but got end of input.`); | ||
}); | ||
} | ||
// digit :: Parser e String s | ||
const digit = new Parser(function digit$state(state) { | ||
if (state.isError) return state; | ||
const { | ||
dataView, | ||
index | ||
} = state; | ||
if (dataView.byteLength > index) { | ||
const charWidth = getNextCharWidth(index, dataView); | ||
if (index + charWidth <= dataView.byteLength) { | ||
const char = getUtf8Char(index, charWidth, dataView); | ||
return dataView.byteLength && char && reDigit.test(char) ? updateParserState(state, char, index + charWidth) : updateError(state, `ParseError (position ${index}): Expecting digit, got '${char}'`); | ||
if (state.isError) | ||
return state; | ||
const { dataView, index } = state; | ||
if (dataView.byteLength > index) { | ||
const charWidth = getNextCharWidth(index, dataView); | ||
if (index + charWidth <= dataView.byteLength) { | ||
const char = getUtf8Char(index, charWidth, dataView); | ||
return dataView.byteLength && char && reDigit.test(char) | ||
? updateParserState(state, char, index + charWidth) | ||
: updateError(state, `ParseError (position ${index}): Expecting digit, got '${char}'`); | ||
} | ||
} | ||
} | ||
return updateError(state, `ParseError (position ${index}): Expecting digit, but got end of input.`); | ||
return updateError(state, `ParseError (position ${index}): Expecting digit, but got end of input.`); | ||
}); | ||
exports.digit = digit; | ||
const digits = regex(reDigits).errorMap(({ | ||
index | ||
}) => `ParseError (position ${index}): Expecting digits`); | ||
exports.digits = digits; | ||
// digits :: Parser e String s | ||
const digits = regex(reDigits).errorMap(({ index }) => `ParseError (position ${index}): Expecting digits`); | ||
// letter :: Parser e Char s | ||
const letter = new Parser(function letter$state(state) { | ||
if (state.isError) return state; | ||
const { | ||
index, | ||
dataView | ||
} = state; | ||
if (dataView.byteLength > index) { | ||
const charWidth = getNextCharWidth(index, dataView); | ||
if (index + charWidth <= dataView.byteLength) { | ||
const char = getUtf8Char(index, charWidth, dataView); | ||
return dataView.byteLength && char && reLetter.test(char) ? updateParserState(state, char, index + charWidth) : updateError(state, `ParseError (position ${index}): Expecting letter, got '${char}'`); | ||
if (state.isError) | ||
return state; | ||
const { index, dataView } = state; | ||
if (dataView.byteLength > index) { | ||
const charWidth = getNextCharWidth(index, dataView); | ||
if (index + charWidth <= dataView.byteLength) { | ||
const char = getUtf8Char(index, charWidth, dataView); | ||
return dataView.byteLength && char && reLetter.test(char) | ||
? updateParserState(state, char, index + charWidth) | ||
: updateError(state, `ParseError (position ${index}): Expecting letter, got '${char}'`); | ||
} | ||
} | ||
} | ||
return updateError(state, `ParseError (position ${index}): Expecting letter, but got end of input.`); | ||
return updateError(state, `ParseError (position ${index}): Expecting letter, but got end of input.`); | ||
}); | ||
exports.letter = letter; | ||
const letters = regex(reLetters).errorMap(({ | ||
index | ||
}) => `ParseError (position ${index}): Expecting letters`); | ||
exports.letters = letters; | ||
const anyOfString = function anyOfString(s) { | ||
return new Parser(function anyOfString$state(state) { | ||
if (state.isError) return state; | ||
const { | ||
dataView, | ||
index | ||
} = state; | ||
if (dataView.byteLength > index) { | ||
const charWidth = getNextCharWidth(index, dataView); | ||
if (index + charWidth <= dataView.byteLength) { | ||
const char = getUtf8Char(index, charWidth, dataView); | ||
return s.includes(char) ? updateParserState(state, char, index + charWidth) : updateError(state, `ParseError (position ${index}): Expecting any of the string "${s}", got ${char}`); | ||
} | ||
} | ||
return updateError(state, `ParseError (position ${index}): Expecting any of the string "${s}", but got end of input.`); | ||
}); | ||
}; | ||
exports.anyOfString = anyOfString; | ||
const namedSequenceOf = function namedSequenceOf(pairedParsers) { | ||
return new Parser(function namedSequenceOf$state(state) { | ||
if (state.isError) return state; | ||
const results = {}; | ||
let nextState = state; | ||
for (const [key, parser] of pairedParsers) { | ||
const out = parser.p(nextState); | ||
if (out.isError) { | ||
return out; | ||
} else { | ||
nextState = out; | ||
results[key] = out.result; | ||
} | ||
} | ||
return updateResult(nextState, results); | ||
}); | ||
}; | ||
exports.namedSequenceOf = namedSequenceOf; | ||
const sequenceOf = function sequenceOf(parsers) { | ||
return new Parser(function sequenceOf$state(state) { | ||
if (state.isError) return state; | ||
const length = parsers.length; | ||
const results = new Array(length); | ||
let nextState = state; | ||
for (let i = 0; i < length; i++) { | ||
const out = parsers[i].p(nextState); | ||
if (out.isError) { | ||
return out; | ||
} else { | ||
nextState = out; | ||
results[i] = out.result; | ||
} | ||
} | ||
return updateResult(nextState, results); | ||
}); | ||
}; | ||
exports.sequenceOf = sequenceOf; | ||
const sepBy = function sepBy(sepParser) { | ||
return function sepBy$valParser(valParser) { | ||
return new Parser(function sepBy$valParser$state(state) { | ||
if (state.isError) return state; | ||
let nextState = state; | ||
let error = null; | ||
const results = []; | ||
while (true) { | ||
const valState = valParser.p(nextState); | ||
const sepState = sepParser.p(valState); | ||
if (valState.isError) { | ||
error = valState; | ||
break; | ||
} else { | ||
results.push(valState.result); | ||
// letters :: Parser e String s | ||
const letters = regex(reLetters).errorMap(({ index }) => `ParseError (position ${index}): Expecting letters`); | ||
// anyOfString :: String -> Parser e Char s | ||
function anyOfString(s) { | ||
return new Parser(function anyOfString$state(state) { | ||
if (state.isError) | ||
return state; | ||
const { dataView, index } = state; | ||
if (dataView.byteLength > index) { | ||
const charWidth = getNextCharWidth(index, dataView); | ||
if (index + charWidth <= dataView.byteLength) { | ||
const char = getUtf8Char(index, charWidth, dataView); | ||
return s.includes(char) | ||
? updateParserState(state, char, index + charWidth) | ||
: updateError(state, `ParseError (position ${index}): Expecting any of the string "${s}", got ${char}`); | ||
} | ||
} | ||
if (sepState.isError) { | ||
nextState = valState; | ||
break; | ||
return updateError(state, `ParseError (position ${index}): Expecting any of the string "${s}", but got end of input.`); | ||
}); | ||
} | ||
// namedSequenceOf :: [(String, Parser * * *)] -> Parser e (StrMap *) s | ||
function namedSequenceOf(pairedParsers) { | ||
return new Parser(function namedSequenceOf$state(state) { | ||
if (state.isError) | ||
return state; | ||
const results = {}; | ||
let nextState = state; | ||
for (const [key, parser] of pairedParsers) { | ||
const out = parser.p(nextState); | ||
if (out.isError) { | ||
return out; | ||
} | ||
else { | ||
nextState = out; | ||
results[key] = out.result; | ||
} | ||
} | ||
nextState = sepState; | ||
} | ||
if (error) { | ||
if (results.length === 0) { | ||
return updateResult(state, results); | ||
return updateResult(nextState, results); | ||
}); | ||
} | ||
// sequenceOf :: [Parser * * *] -> Parser * [*] * | ||
function sequenceOf(parsers) { | ||
return new Parser(function sequenceOf$state(state) { | ||
if (state.isError) | ||
return state; | ||
const length = parsers.length; | ||
const results = new Array(length); | ||
let nextState = state; | ||
for (let i = 0; i < length; i++) { | ||
const out = parsers[i].p(nextState); | ||
if (out.isError) { | ||
return out; | ||
} | ||
else { | ||
nextState = out; | ||
results[i] = out.result; | ||
} | ||
} | ||
return error; | ||
} | ||
return updateResult(nextState, results); | ||
return updateResult(nextState, results); | ||
}); | ||
}; | ||
}; | ||
exports.sepBy = sepBy; | ||
} | ||
// sepBy :: Parser e a s -> Parser e b s -> Parser e [b] s | ||
function sepBy(sepParser) { | ||
return function sepBy$valParser(valueParser) { | ||
return new Parser(function sepBy$valParser$state(state) { | ||
if (state.isError) | ||
return state; | ||
let nextState = state; | ||
let error = null; | ||
const results = []; | ||
while (true) { | ||
const valState = valueParser.p(nextState); | ||
const sepState = sepParser.p(valState); | ||
if (valState.isError) { | ||
error = valState; | ||
break; | ||
} | ||
else { | ||
results.push(valState.result); | ||
} | ||
if (sepState.isError) { | ||
nextState = valState; | ||
break; | ||
} | ||
nextState = sepState; | ||
} | ||
if (error) { | ||
if (results.length === 0) { | ||
return updateResult(state, results); | ||
} | ||
return error; | ||
} | ||
return updateResult(nextState, results); | ||
}); | ||
}; | ||
} | ||
// sepBy1 :: Parser e a s -> Parser e b s -> Parser e [b] s | ||
const sepBy1 = function sepBy1(sepParser) { | ||
return function sepBy1$valParser(valParser) { | ||
return new Parser(function sepBy1$valParser$state(state) { | ||
if (state.isError) return state; | ||
const out = sepBy(sepParser)(valParser).p(state); | ||
if (out.isError) return out; | ||
if (out.result.length === 0) { | ||
return updateError(state, `ParseError 'sepBy1' (position ${state.index}): Expecting to match at least one separated value`); | ||
} | ||
return out; | ||
}); | ||
}; | ||
return function sepBy1$valParser(valueParser) { | ||
return new Parser(function sepBy1$valParser$state(state) { | ||
if (state.isError) | ||
return state; | ||
const out = sepBy(sepParser)(valueParser).p(state); | ||
if (out.isError) | ||
return out; | ||
if (out.result.length === 0) { | ||
return updateError(state, `ParseError 'sepBy1' (position ${state.index}): Expecting to match at least one separated value`); | ||
} | ||
return out; | ||
}); | ||
}; | ||
}; | ||
exports.sepBy1 = sepBy1; | ||
// choice :: [Parser * * *] -> Parser * * * | ||
const choice = function choice(parsers) { | ||
return new Parser(function choice$state(state) { | ||
if (state.isError) return state; | ||
let error = null; | ||
for (const parser of parsers) { | ||
const out = parser.p(state); | ||
if (!out.isError) return out; | ||
if (!error || error && out.index > error.index) { | ||
error = out; | ||
} | ||
} | ||
return error; | ||
}); | ||
if (parsers.length === 0) | ||
throw new Error(`List of parsers can't be empty.`); | ||
return new Parser(function choice$state(state) { | ||
if (state.isError) | ||
return state; | ||
let error = null; | ||
for (const parser of parsers) { | ||
const out = parser.p(state); | ||
if (!out.isError) | ||
return out; | ||
if (error === null || (error && out.index > error.index)) { | ||
error = out; | ||
} | ||
} | ||
return error; | ||
}); | ||
}; | ||
exports.choice = choice; | ||
const between = function between(leftParser) { | ||
return function between$rightParser(rightParser) { | ||
return function between$parser(parser) { | ||
return sequenceOf([leftParser, parser, rightParser]).map(([_, x]) => x); | ||
// between :: Parser e a s -> Parser e b s -> Parser e c s -> Parser e b s | ||
function between(leftParser) { | ||
return function between$rightParser(rightParser) { | ||
return function between$parser(parser) { | ||
return sequenceOf([leftParser, parser, rightParser]).map(([_, x]) => x); | ||
}; | ||
}; | ||
}; | ||
}; | ||
exports.between = between; | ||
const everythingUntil = function everythingUntil(parser) { | ||
return new Parser(state => { | ||
if (state.isError) return state; | ||
const results = []; | ||
let nextState = state; | ||
while (true) { | ||
const out = parser.p(nextState); | ||
if (out.isError) { | ||
const { | ||
index, | ||
dataView | ||
} = nextState; | ||
if (dataView.byteLength <= index) { | ||
return updateError(nextState, `ParseError 'everythingUntil' (position ${nextState.index}): Unexpected end of input.`); | ||
} | ||
// everythingUntil :: Parser e a s -> Parser e String s | ||
function everythingUntil(parser) { | ||
return new Parser(state => { | ||
if (state.isError) | ||
return state; | ||
const results = []; | ||
let nextState = state; | ||
while (true) { | ||
const out = parser.p(nextState); | ||
if (out.isError) { | ||
const { index, dataView } = nextState; | ||
if (dataView.byteLength <= index) { | ||
return updateError(nextState, `ParseError 'everythingUntil' (position ${nextState.index}): Unexpected end of input.`); | ||
} | ||
const val = dataView.getUint8(index); | ||
if (val) { | ||
results.push(val); | ||
nextState = updateParserState(nextState, val, index + 1); | ||
} | ||
} | ||
else { | ||
break; | ||
} | ||
} | ||
const val = dataView.getUint8(index); | ||
if (val) { | ||
results.push(val); | ||
nextState = updateParserState(nextState, val, index + 1); | ||
return updateResult(nextState, results); | ||
}); | ||
} | ||
// everyCharUntil :: Parser e a s -> Parser e String s | ||
const everyCharUntil = (parser) => everythingUntil(parser) | ||
.map(results => decoder.decode(Uint8Array.from(results))); | ||
// anythingExcept :: Parser e a s -> Parser e Char s | ||
const anythingExcept = function anythingExcept(parser) { | ||
return new Parser(function anythingExcept$state(state) { | ||
if (state.isError) | ||
return state; | ||
const { dataView, index } = state; | ||
const out = parser.p(state); | ||
if (out.isError) { | ||
return updateParserState(state, dataView.getUint8(index), index + 1); | ||
} | ||
} else { | ||
break; | ||
} | ||
} | ||
return updateResult(nextState, results); | ||
}); | ||
return updateError(state, `ParseError 'anythingExcept' (position ${index}): Matched '${out.result}' from the exception parser`); | ||
}); | ||
}; | ||
exports.everythingUntil = everythingUntil; | ||
const everyCharUntil = parser => everythingUntil(parser).map(results => decoder.decode(Uint8Array.from(results))); | ||
exports.everyCharUntil = everyCharUntil; | ||
const anythingExcept = function anythingExcept(parser) { | ||
return new Parser(function anythingExcept$state(state) { | ||
if (state.isError) return state; | ||
const { | ||
dataView, | ||
index | ||
} = state; | ||
const out = parser.p(state); | ||
if (out.isError) { | ||
return updateParserState(state, dataView.getUint8(index), index + 1); | ||
} | ||
return updateError(state, `ParseError 'anythingExcept' (position ${index}): Matched '${out.result}' from the exception parser`); | ||
}); | ||
}; | ||
exports.anythingExcept = anythingExcept; | ||
// anyCharExcept :: Parser e a s -> Parser e Char s | ||
const anyCharExcept = function anyCharExcept(parser) { | ||
return new Parser(function anyCharExcept$state(state) { | ||
if (state.isError) return state; | ||
const { | ||
dataView, | ||
index | ||
} = state; | ||
const out = parser.p(state); | ||
if (out.isError) { | ||
if (index < dataView.byteLength) { | ||
const charWidth = getNextCharWidth(index, dataView); | ||
if (index + charWidth <= dataView.byteLength) { | ||
const char = getUtf8Char(index, charWidth, dataView); | ||
return updateParserState(state, char, index + charWidth); | ||
return new Parser(function anyCharExcept$state(state) { | ||
if (state.isError) | ||
return state; | ||
const { dataView, index } = state; | ||
const out = parser.p(state); | ||
if (out.isError) { | ||
if (index < dataView.byteLength) { | ||
const charWidth = getNextCharWidth(index, dataView); | ||
if (index + charWidth <= dataView.byteLength) { | ||
const char = getUtf8Char(index, charWidth, dataView); | ||
return updateParserState(state, char, index + charWidth); | ||
} | ||
} | ||
return updateError(state, `ParseError 'anyCharExcept' (position ${index}): Unexpected end of input`); | ||
} | ||
} | ||
return updateError(state, `ParseError 'anyCharExcept' (position ${index}): Unexpected end of input`); | ||
} | ||
return updateError(state, `ParseError 'anyCharExcept' (position ${index}): Matched '${out.result}' from the exception parser`); | ||
}); | ||
return updateError(state, `ParseError 'anyCharExcept' (position ${index}): Matched '${out.result}' from the exception parser`); | ||
}); | ||
}; | ||
exports.anyCharExcept = anyCharExcept; | ||
const lookAhead = function lookAhead(parser) { | ||
return new Parser(function lookAhead$state(state) { | ||
if (state.isError) return state; | ||
const nextState = parser.p(state); | ||
return nextState.isError ? updateError(state, nextState.error) : updateResult(state, nextState.result); | ||
}); | ||
}; | ||
exports.lookAhead = lookAhead; | ||
const possibly = function possibly(parser) { | ||
return new Parser(function possibly$state(state) { | ||
if (state.isError) return state; | ||
const nextState = parser.p(state); | ||
return nextState.isError ? updateResult(state, null) : nextState; | ||
}); | ||
}; | ||
exports.possibly = possibly; | ||
const skip = function skip(parser) { | ||
return new Parser(function skip$state(state) { | ||
if (state.isError) return state; | ||
const nextState = parser.p(state); | ||
if (nextState.isError) return nextState; | ||
return updateResult(nextState, state.result); | ||
}); | ||
}; | ||
exports.skip = skip; | ||
// lookAhead :: Parser e a s -> Parser e a s | ||
function lookAhead(parser) { | ||
return new Parser(function lookAhead$state(state) { | ||
if (state.isError) | ||
return state; | ||
const nextState = parser.p(state); | ||
return nextState.isError | ||
? updateError(state, nextState.error) | ||
: updateResult(state, nextState.result); | ||
}); | ||
} | ||
// possibly :: Parser e a s -> Parser e (a | Null) s | ||
function possibly(parser) { | ||
return new Parser(function possibly$state(state) { | ||
if (state.isError) | ||
return state; | ||
const nextState = parser.p(state); | ||
return nextState.isError ? updateResult(state, null) : nextState; | ||
}); | ||
} | ||
// skip :: Parser e a s -> Parser e a s | ||
function skip(parser) { | ||
return new Parser(function skip$state(state) { | ||
if (state.isError) | ||
return state; | ||
const nextState = parser.p(state); | ||
if (nextState.isError) | ||
return nextState; | ||
return updateResult(nextState, state.result); | ||
}); | ||
} | ||
// startOfInput :: Parser e String s | ||
const startOfInput = new Parser(function startOfInput$state(state) { | ||
if (state.isError) return state; | ||
const { | ||
index | ||
} = state; | ||
if (index > 0) { | ||
return updateError(state, `ParseError 'startOfInput' (position ${index}): Expected start of input'`); | ||
} | ||
return state; | ||
if (state.isError) | ||
return state; | ||
const { index } = state; | ||
if (index > 0) { | ||
return updateError(state, `ParseError 'startOfInput' (position ${index}): Expected start of input'`); | ||
} | ||
return state; | ||
}); | ||
exports.startOfInput = startOfInput; | ||
// endOfInput :: Parser e Null s | ||
const endOfInput = new Parser(function endOfInput$state(state) { | ||
if (state.isError) return state; | ||
const { | ||
dataView, | ||
index, | ||
inputType | ||
} = state; | ||
if (index !== dataView.byteLength) { | ||
const errorByte = inputType === inputTypes.STRING ? String.fromCharCode(dataView.getUint8(index)) : `0x${dataView.getUint8(index).toString(16).padStart(2, '0')}`; | ||
return updateError(state, `ParseError 'endOfInput' (position ${index}): Expected end of input but got '${errorByte}'`); | ||
} | ||
return updateResult(state, null); | ||
if (state.isError) | ||
return state; | ||
const { dataView, index, inputType } = state; | ||
if (index !== dataView.byteLength) { | ||
const errorByte = inputType === exports.InputTypes.STRING | ||
? String.fromCharCode(dataView.getUint8(index)) | ||
: `0x${dataView.getUint8(index).toString(16).padStart(2, '0')}`; | ||
return updateError(state, `ParseError 'endOfInput' (position ${index}): Expected end of input but got '${errorByte}'`); | ||
} | ||
return updateResult(state, null); | ||
}); | ||
exports.endOfInput = endOfInput; | ||
const whitespace = regex(reWhitespaces).errorMap(({ | ||
index | ||
}) => `ParseError 'many1' (position ${index}): Expecting to match at least one value`); | ||
exports.whitespace = whitespace; | ||
// whitespace :: Parser e String s | ||
const whitespace = regex(reWhitespaces) | ||
// Keeping this error even though the implementation no longer uses many1. Will change it to something more appropriate in the next major release. | ||
.errorMap(({ index }) => `ParseError 'many1' (position ${index}): Expecting to match at least one value`); | ||
// optionalWhitespace :: Parser e String s | ||
const optionalWhitespace = possibly(whitespace).map(x => x || ''); | ||
exports.optionalWhitespace = optionalWhitespace; | ||
const recursiveParser = function recursiveParser(parserThunk) { | ||
return new Parser(function recursiveParser$state(state) { | ||
return parserThunk().p(state); | ||
}); | ||
// recursiveParser :: (() => Parser e a s) -> Parser e a s | ||
function recursiveParser(parserThunk) { | ||
return new Parser(function recursiveParser$state(state) { | ||
return parserThunk().p(state); | ||
}); | ||
} | ||
// takeRight :: Parser e a s -> Parser f b t -> Parser f b t | ||
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 | ||
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 | ||
function toPromise(result) { | ||
return result.isError === true | ||
? Promise.reject({ | ||
error: result.error, | ||
index: result.index, | ||
data: result.data, | ||
}) | ||
: Promise.resolve(result.result); | ||
} | ||
// toValue :: ParserResult e a s -> a | ||
function toValue(result) { | ||
if (result.isError === true) { | ||
const e = new Error(String(result.error) || 'null'); | ||
e.parseIndex = result.index; | ||
e.data = result.data; | ||
throw e; | ||
} | ||
return result.result; | ||
} | ||
exports.Parser = Parser; | ||
exports.anyChar = anyChar; | ||
exports.anyCharExcept = anyCharExcept; | ||
exports.anyOfString = anyOfString; | ||
exports.anythingExcept = anythingExcept; | ||
exports.between = between; | ||
exports.char = char; | ||
exports.choice = choice; | ||
exports.composeParsers = composeParsers; | ||
exports.coroutine = coroutine; | ||
exports.decide = decide; | ||
exports.decoder = decoder; | ||
exports.digit = digit; | ||
exports.digits = digits; | ||
exports.either = either; | ||
exports.encoder = encoder; | ||
exports.endOfInput = endOfInput; | ||
exports.errorMapTo = errorMapTo; | ||
exports.everyCharUntil = everyCharUntil; | ||
exports.everythingUntil = everythingUntil; | ||
exports.exactly = exactly; | ||
exports.fail = fail; | ||
exports.getCharacterLength = getCharacterLength; | ||
exports.getData = getData; | ||
exports.getNextCharWidth = getNextCharWidth; | ||
exports.getString = getString; | ||
exports.getUtf8Char = getUtf8Char; | ||
exports.letter = letter; | ||
exports.letters = letters; | ||
exports.lookAhead = lookAhead; | ||
exports.many = many; | ||
exports.many1 = many1; | ||
exports.mapData = mapData; | ||
exports.mapTo = mapTo; | ||
exports.namedSequenceOf = namedSequenceOf; | ||
exports.optionalWhitespace = optionalWhitespace; | ||
exports.parse = parse; | ||
exports.peek = peek; | ||
exports.pipeParsers = pipeParsers; | ||
exports.possibly = possibly; | ||
exports.recursiveParser = recursiveParser; | ||
const takeRight = function takeRight(leftParser) { | ||
return function takeRight$rightParser(rightParser) { | ||
return leftParser.chain(() => rightParser); | ||
}; | ||
}; | ||
exports.regex = regex; | ||
exports.sepBy = sepBy; | ||
exports.sepBy1 = sepBy1; | ||
exports.sequenceOf = sequenceOf; | ||
exports.setData = setData; | ||
exports.skip = skip; | ||
exports.startOfInput = startOfInput; | ||
exports.str = str; | ||
exports.succeedWith = succeedWith; | ||
exports.takeLeft = takeLeft; | ||
exports.takeRight = takeRight; | ||
const takeLeft = function takeLeft(leftParser) { | ||
return function takeLeft$rightParser(rightParser) { | ||
return leftParser.chain(x => rightParser.map(() => x)); | ||
}; | ||
}; | ||
exports.takeLeft = takeLeft; | ||
const toPromise = function toPromise(result) { | ||
return result.isError ? Promise.reject({ | ||
error: result.error, | ||
index: result.index, | ||
data: result.data | ||
}) : Promise.resolve(result.result); | ||
}; | ||
exports.tapParser = tapParser; | ||
exports.toPromise = toPromise; | ||
const toValue = function toValue(result) { | ||
if (result.isError) { | ||
const e = new Error(result.error); | ||
e.parseIndex = result.index; | ||
e.data = result.data; | ||
throw e; | ||
} | ||
return result.result; | ||
}; | ||
exports.toValue = toValue; | ||
exports.updateData = updateData; | ||
exports.updateError = updateError; | ||
exports.updateParserState = updateParserState; | ||
exports.updateResult = updateResult; | ||
exports.whitespace = whitespace; | ||
exports.withData = withData; |
{ | ||
"name": "arcsecond", | ||
"version": "3.2.0", | ||
"version": "4.0.0-rc.0", | ||
"description": "", | ||
@@ -11,3 +11,3 @@ "main": "index", | ||
"repl": "node -r esm", | ||
"build": "babel index.mjs -o index.js" | ||
"build": "rimraf index.* && rollup -c rollup.config.js" | ||
}, | ||
@@ -19,8 +19,5 @@ "jest": { | ||
"license": "MIT", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.2.3", | ||
"@babel/core": "^7.2.2", | ||
"@babel/plugin-transform-modules-commonjs": "^7.2.0", | ||
"@babel/preset-env": "^7.2.3", | ||
"@rollup/plugin-typescript": "^8.2.1", | ||
"@types/node": "^15.12.5", | ||
"eslint": "^6.8.0", | ||
@@ -32,4 +29,8 @@ "eslint-config-prettier": "^6.10.0", | ||
"prettier": "^1.19.1", | ||
"standard": "^14.3.1" | ||
"rimraf": "^2.6.3", | ||
"rollup": "^2.52.7", | ||
"rollup-plugin-dts": "^3.0.2", | ||
"standard": "^14.3.1", | ||
"typescript": "^4.3.4" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
179967
20
2056
13
2
1