@appliedblockchain/parser-combinators
Advanced tools
Comparing version 2.0.0 to 3.0.0
@@ -1,2 +0,2 @@ | ||
// @flow | ||
// @flow strict | ||
@@ -3,0 +3,0 @@ const Invalid = require('./invalid') |
@@ -1,2 +0,2 @@ | ||
// @flow | ||
// @flow strict | ||
@@ -3,0 +3,0 @@ const Invalid = require('./invalid') |
@@ -1,2 +0,2 @@ | ||
// @flow | ||
// @flow strict | ||
@@ -3,0 +3,0 @@ const exhaustive = require('./exhaustive') |
@@ -1,2 +0,2 @@ | ||
// @flow | ||
// @flow strict | ||
@@ -3,0 +3,0 @@ const Invalid = require('./invalid') |
54
index.js
@@ -1,1 +0,53 @@ | ||
// @flow | ||
// @flow strict | ||
const either = require('./either') | ||
const exhaustive = require('./exhaustive') | ||
const exhaustiveResult = require('./exhaustive-result') | ||
const exhaustiveUnion = require('./exhaustive-union') | ||
const Invalid = require('./invalid') | ||
const left = require('./left') | ||
const literal = require('./literal') | ||
const map = require('./map') | ||
const maybe = require('./maybe') | ||
const pair = require('./pair') | ||
const plus = require('./plus') | ||
const predicate = require('./predicate') | ||
const range = require('./range') | ||
const regex = require('./regex') | ||
const right = require('./right') | ||
const separated = require('./separated') | ||
const sequence = require('./sequence') | ||
const star = require('./star') | ||
const then = require('./then') | ||
const times = require('./times') | ||
const union = require('./union') | ||
const whileChar = require('./while-char') | ||
const ws0 = require('./ws0') | ||
const ws1 = require('./ws1') | ||
module.exports = { | ||
either, | ||
exhaustive, | ||
exhaustiveResult, | ||
exhaustiveUnion, | ||
Invalid, | ||
left, | ||
literal, | ||
map, | ||
maybe, | ||
pair, | ||
plus, | ||
predicate, | ||
range, | ||
regex, | ||
right, | ||
sequence, | ||
separated, | ||
star, | ||
then, | ||
times, | ||
union, | ||
whileChar, | ||
ws0, | ||
ws1 | ||
} |
@@ -1,2 +0,2 @@ | ||
// @flow | ||
// @flow strict | ||
@@ -3,0 +3,0 @@ class Invalid extends Error {} |
@@ -1,2 +0,2 @@ | ||
// @flow | ||
// @flow strict | ||
@@ -3,0 +3,0 @@ const pair = require('./pair') |
@@ -1,2 +0,2 @@ | ||
// @flow | ||
// @flow strict | ||
@@ -3,0 +3,0 @@ const Invalid = require('./invalid') |
@@ -1,2 +0,2 @@ | ||
// @flow | ||
// @flow strict | ||
@@ -3,0 +3,0 @@ /*:: import type { Parser as P } from './types/parser' */ |
@@ -1,2 +0,2 @@ | ||
// @flow | ||
// @flow strict | ||
@@ -3,0 +3,0 @@ const Invalid = require('./invalid') |
{ | ||
"name": "@appliedblockchain/parser-combinators", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "Monadic parser combinators.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "eslint . && flow check && jest" | ||
"test": "eslint . && flow check && jest", | ||
"update": "npm-check --update --save-exact" | ||
}, | ||
@@ -19,5 +20,6 @@ "keywords": [ | ||
"@appliedblockchain/eslint-config": "2.6.0", | ||
"eslint": "6.8.0", | ||
"flow-bin": "0.122.0", | ||
"jest": "25.2.7" | ||
"eslint": "7.0.0", | ||
"flow-bin": "0.125.1", | ||
"jest": "26.0.1", | ||
"npm-check": "5.9.2" | ||
}, | ||
@@ -24,0 +26,0 @@ "eslintConfig": { |
@@ -1,2 +0,2 @@ | ||
// @flow | ||
// @flow strict | ||
@@ -3,0 +3,0 @@ /*:: import type { Parser as P } from './types/parser' */ |
@@ -1,2 +0,2 @@ | ||
// @flow | ||
// @flow strict | ||
@@ -3,0 +3,0 @@ const star = require('./star') |
@@ -1,2 +0,2 @@ | ||
// @flow | ||
// @flow strict | ||
@@ -3,0 +3,0 @@ const Invalid = require('./invalid') |
@@ -1,2 +0,2 @@ | ||
// @flow | ||
// @flow strict | ||
@@ -3,0 +3,0 @@ const map = require('./map') |
@@ -1,2 +0,2 @@ | ||
// @flow | ||
// @flow strict | ||
@@ -3,0 +3,0 @@ const Invalid = require('./invalid') |
@@ -1,2 +0,2 @@ | ||
// @flow | ||
// @flow strict | ||
@@ -3,0 +3,0 @@ const pair = require('./pair') |
@@ -1,2 +0,2 @@ | ||
// @flow | ||
// @flow strict | ||
@@ -3,0 +3,0 @@ /*:: |
@@ -1,2 +0,2 @@ | ||
// @flow | ||
// @flow strict | ||
@@ -3,0 +3,0 @@ const Invalid = require('./invalid') |
// @flow | ||
const exhaustiveUnion = require('../exhaustive-union') | ||
const literal = require('../literal') | ||
const $ = require('../') | ||
const a = literal('a') | ||
const b = literal('b') | ||
const a = $.literal('a') | ||
const b = $.literal('b') | ||
test('union', () => { | ||
expect(exhaustiveUnion(a, b)('a')).toEqual([ '', 'a' ]) | ||
expect(exhaustiveUnion(a, b)('b')).toEqual([ '', 'b' ]) | ||
expect(() => exhaustiveUnion(a, b)('c')).toThrowError('c') | ||
expect(() => exhaustiveUnion(a, b)('a ')).toThrowError('a ') | ||
expect(() => exhaustiveUnion(a, b)('b ')).toThrowError('b ') | ||
expect($.exhaustiveUnion(a, b)('a')).toEqual([ '', 'a' ]) | ||
expect($.exhaustiveUnion(a, b)('b')).toEqual([ '', 'b' ]) | ||
expect(() => $.exhaustiveUnion(a, b)('c')).toThrowError('c') | ||
expect(() => $.exhaustiveUnion(a, b)('a ')).toThrowError('a ') | ||
expect(() => $.exhaustiveUnion(a, b)('b ')).toThrowError('b ') | ||
}) |
// @flow | ||
const exhaustive = require('../exhaustive') | ||
const literal = require('../literal') | ||
const $ = require('../') | ||
const a = literal('a') | ||
const a = $.literal('a') | ||
test('exhaustive', () => { | ||
expect(exhaustive(a)('a')).toEqual([ '', 'a' ]) | ||
expect(() => exhaustive(a)('ab')).toThrowError('a') | ||
expect($.exhaustive(a)('a')).toEqual([ '', 'a' ]) | ||
expect(() => $.exhaustive(a)('ab')).toThrowError('a') | ||
}) |
// @flow | ||
const either = require('../either') | ||
const Invalid = require('../Invalid') | ||
const literal = require('../literal') | ||
const map = require('../map') | ||
const pair = require('../pair') | ||
const predicate = require('../predicate') | ||
const regex = require('../regex') | ||
const sequence = require('../sequence') | ||
const star = require('../star') | ||
const $ = require('../') | ||
@@ -30,44 +22,44 @@ /*:: | ||
const ws0 = | ||
map(regex(/^[ \t\r\n]*/), _ => _.join('')) | ||
$.map($.regex(/^[ \t\r\n]*/), _ => _.join('')) | ||
const ws1 = | ||
map(regex(/^[ \t\r\n]+/), _ => _.join('')) | ||
$.map($.regex(/^[ \t\r\n]+/), _ => _.join('')) | ||
const id0 /*: Parser<Id> */ = | ||
map(pair(regex(/^[a-z_]/i), regex(/^[a-z0-9_-]*/i)), _ => nodeOf('Id', { value: _.join(''), ns: null })) | ||
$.map($.pair($.regex(/^[a-z_]/i), $.regex(/^[a-z0-9_-]*/i)), _ => nodeOf('Id', { value: _.join(''), ns: null })) | ||
const id1 /*: Parser<Id> */ = | ||
map(sequence(id0, literal(':'), id0), _ => nodeOf('Id', { value: _[2].value, ns: _[0].value })) | ||
$.map($.sequence(id0, $.literal(':'), id0), _ => nodeOf('Id', { value: _[2].value, ns: _[0].value })) | ||
const id /*: Parser<Id> */ = | ||
either(id1, id0) | ||
$.either(id1, id0) | ||
const text0 /*: Parser<string> */ = | ||
map(regex(/^[^<>]*/), _ => _.join('')) | ||
$.map($.regex(/^[^<>]*/), _ => _.join('')) | ||
const string /*: Parser<string> */ = | ||
either( | ||
map(sequence(literal('\''), regex(/^[^']*/), literal('\'')), ([ , _ ]) => _.join('')), | ||
map(sequence(literal('"'), regex(/^[^"]*/), literal('"')), ([ , _ ]) => _.join('')) | ||
$.either( | ||
$.map($.sequence($.literal('\''), $.regex(/^[^']*/), $.literal('\'')), ([ , _ ]) => _.join('')), | ||
$.map($.sequence($.literal('"'), $.regex(/^[^"]*/), $.literal('"')), ([ , _ ]) => _.join('')) | ||
) | ||
const attribute /*: Parser<Attribute> */= | ||
map(sequence(ws1, id, literal('='), string), ([ , name, , value ]) => ({ type: 'Attribute', name, value })) | ||
$.map($.sequence(ws1, id, $.literal('='), string), ([ , name, , value ]) => ({ type: 'Attribute', name, value })) | ||
const element1 /*: Parser<Element> */ = | ||
map(sequence(ws0, literal('<'), id, star(attribute), ws0, literal('/>')), ([ , , name, attributes ]) => ({ type: 'Element', name, attributes, children: [], text: undefined })) | ||
$.map($.sequence(ws0, $.literal('<'), id, $.star(attribute), ws0, $.literal('/>')), ([ , , name, attributes ]) => ({ type: 'Element', name, attributes, children: [], text: undefined })) | ||
const elementL /*: Parser<Element> */ = | ||
map(sequence(ws0, literal('<'), id, star(attribute), ws0, literal('>'), text0), ([ , , name, attributes, , , text_ ]) => ({ type: 'Element', name, attributes, children: [], text: text_.trim() === '' ? undefined : text_.trim() })) | ||
$.map($.sequence(ws0, $.literal('<'), id, $.star(attribute), ws0, $.literal('>'), text0), ([ , , name, attributes, , , text_ ]) => ({ type: 'Element', name, attributes, children: [], text: text_.trim() === '' ? undefined : text_.trim() })) | ||
const elementR /*: Parser<Id> */ = | ||
map(sequence(ws0, literal('</'), id, ws0, literal('>')), ([ , , name ]) => name) | ||
$.map($.sequence(ws0, $.literal('</'), id, ws0, $.literal('>')), ([ , , name ]) => name) | ||
const element /*: Parser<Element> */ = | ||
input => | ||
either( | ||
$.either( | ||
element1, | ||
map( | ||
predicate( | ||
sequence(elementL, star(element), elementR), | ||
$.map( | ||
$.predicate( | ||
$.sequence(elementL, $.star(element), elementR), | ||
([ _, , __ ]) => _.name.value === __.value && _.name.ns === __.ns | ||
@@ -107,3 +99,3 @@ ), | ||
if (s.trim() !== '') { | ||
throw new Invalid(s) | ||
throw new $.Invalid(s) | ||
} | ||
@@ -110,0 +102,0 @@ return jsonOfAst(r) |
// @flow | ||
const union = require('../union') | ||
const literal = require('../literal') | ||
const $ = require('../') | ||
const a = literal('a') | ||
const b = literal('b') | ||
const a = $.literal('a') | ||
const b = $.literal('b') | ||
test('union', () => { | ||
expect(union(a, b)('a')).toEqual([ '', 'a' ]) | ||
expect(union(a, b)('b')).toEqual([ '', 'b' ]) | ||
expect(() => union(a, b)('c')).toThrowError('c') | ||
expect($.union(a, b)('a')).toEqual([ '', 'a' ]) | ||
expect($.union(a, b)('b')).toEqual([ '', 'b' ]) | ||
expect(() => $.union(a, b)('c')).toThrowError('c') | ||
}) |
// @flow | ||
const whileChar = require('../while-char') | ||
const exhaustiveResult = require('../exhaustive-result') | ||
const $ = require('../') | ||
const ws0 = | ||
exhaustiveResult(whileChar(' ')) | ||
$.exhaustiveResult($.whileChar(' ')) | ||
const ws1 = | ||
exhaustiveResult(whileChar(' ', 1)) | ||
$.exhaustiveResult($.whileChar(' ', 1)) | ||
@@ -12,0 +11,0 @@ test('whileChar', () => { |
@@ -1,2 +0,2 @@ | ||
// @flow | ||
// @flow strict | ||
@@ -3,0 +3,0 @@ /*:: import type { Parser as P } from './types/parser' */ |
@@ -1,2 +0,2 @@ | ||
// @flow | ||
// @flow strict | ||
@@ -3,0 +3,0 @@ /*:: import type { Parser as P } from './types/parser' */ |
@@ -1,2 +0,2 @@ | ||
// @flow | ||
// @flow strict | ||
@@ -3,0 +3,0 @@ const Invalid = require('./invalid') |
@@ -1,2 +0,2 @@ | ||
// @flow | ||
// @flow strict | ||
@@ -6,5 +6,5 @@ const { inspect } = require('util') | ||
/*:: import type { Parser } from './types/parser' */ | ||
/*:: import type { Parser as P } from './types/parser' */ | ||
const whileChar /*: (string, min?: number) => Parser<string> */ = | ||
const whileChar /*: (string, min?: number) => P<string> */ = | ||
(chars, min = 0) => | ||
@@ -11,0 +11,0 @@ input => { |
@@ -1,2 +0,2 @@ | ||
// @flow | ||
// @flow strict | ||
@@ -3,0 +3,0 @@ const whileChar = require('./while-char') |
@@ -1,2 +0,2 @@ | ||
// @flow | ||
// @flow strict | ||
@@ -3,0 +3,0 @@ const whileChar = require('./while-char') |
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
75933
1981
5