@futpib/parser 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/apk.d.ts +29 -3
- package/build/apkParser.d.ts +15 -2
- package/build/apkParser.js +70 -41
- package/build/apkParser.test.js +2 -2
- package/build/apkUnparser.d.ts +4 -0
- package/build/apkUnparser.js +90 -0
- package/build/apkUnparser.test.d.ts +1 -0
- package/build/apkUnparser.test.js +26 -0
- package/build/arbitraryFileSystemEntry.js +1 -1
- package/build/arbitraryZip.d.ts +1 -1
- package/build/arbitraryZip.js +13 -19
- package/build/arbitraryZipPermissions.d.ts +1 -8
- package/build/arbitraryZipPermissions.js +1 -16
- package/build/arbitraryZipStream.d.ts +1 -1
- package/build/arbitraryZipStream.js +3 -3
- package/build/arrayParser.d.ts +1 -1
- package/build/arrayParser.js +2 -2
- package/build/arrayParser.test.js +2 -2
- package/build/arrayUnparser.d.ts +2 -0
- package/build/arrayUnparser.js +8 -0
- package/build/bsonParser.test.js +2 -2
- package/build/customInvariant.d.ts +4 -0
- package/build/customInvariant.js +11 -0
- package/build/debugLogParser.d.ts +1 -1
- package/build/debugLogParser.js +1 -1
- package/build/elementParser.d.ts +2 -2
- package/build/elementParser.js +1 -1
- package/build/endOfInputParser.d.ts +2 -2
- package/build/exactElementParser.d.ts +1 -1
- package/build/exactSequenceParser.js +1 -1
- package/build/index.d.ts +5 -2
- package/build/index.js +3 -0
- package/build/inputReader.d.ts +3 -3
- package/build/inputReader.js +6 -6
- package/build/inputReader.test.js +7 -7
- package/build/javaKeyStore.d.ts +1 -0
- package/build/javaKeyStore.js +1 -0
- package/build/javaKeyStoreParser.d.ts +2 -0
- package/build/javaKeyStoreParser.js +67 -0
- package/build/javaKeyStoreParser.test.d.ts +1 -0
- package/build/javaKeyStoreParser.test.js +16 -0
- package/build/javaKeystoreParser.d.ts +2 -0
- package/build/javaKeystoreParser.js +7 -0
- package/build/jsonParser.js +3 -2
- package/build/jsonParser.test.js +2 -2
- package/build/listParser.d.ts +1 -1
- package/build/listParser.js +5 -5
- package/build/negativeLookahead.d.ts +1 -1
- package/build/negativeLookahead.js +16 -18
- package/build/negativeLookaheadParser.d.ts +2 -0
- package/build/negativeLookaheadParser.js +18 -0
- package/build/optionalParser.d.ts +1 -1
- package/build/optionalParser.js +2 -2
- package/build/parser.d.ts +3 -3
- package/build/parser.js +3 -3
- package/build/parser.test.js +16 -16
- package/build/parserAccessorParser.d.ts +1 -1
- package/build/parserConsumedSequenceParser.d.ts +2 -0
- package/build/parserConsumedSequenceParser.js +17 -0
- package/build/parserContext.d.ts +6 -6
- package/build/parserContext.js +15 -14
- package/build/parserContext.test.js +7 -7
- package/build/parserCreatorCompose.d.ts +3 -3
- package/build/parserCreatorCompose.js +2 -2
- package/build/parserImplementationInvariant.d.ts +1 -1
- package/build/parserImplementationInvariant.js +2 -2
- package/build/parserInputCompanion.d.ts +20 -0
- package/build/parserInputCompanion.js +30 -0
- package/build/parserInvariant.d.ts +1 -1
- package/build/parserInvariant.js +1 -1
- package/build/quantifierParser.d.ts +2 -0
- package/build/quantifierParser.js +17 -0
- package/build/sequenceBuffer.d.ts +3 -3
- package/build/sequenceBuffer.js +6 -6
- package/build/sequenceBuffer.test.js +2 -2
- package/build/sequenceUnparser.d.ts +2 -0
- package/build/sequenceUnparser.js +6 -0
- package/build/sliceBoundedParser.d.ts +1 -1
- package/build/sliceBoundedParser.js +1 -1
- package/build/sliceBoundedParser.test.js +2 -2
- package/build/terminatedArrayParser.d.ts +1 -1
- package/build/terminatedArrayParser.js +3 -3
- package/build/uint8Array.d.ts +1 -0
- package/build/uint8Array.js +7 -0
- package/build/unparser.d.ts +8 -0
- package/build/unparser.js +104 -0
- package/build/unparser.test.d.ts +1 -0
- package/build/unparser.test.js +150 -0
- package/build/unparserContext.d.ts +31 -0
- package/build/unparserContext.js +74 -0
- package/build/unparserError.d.ts +9 -0
- package/build/unparserError.js +9 -0
- package/build/unparserImplementationInvariant.d.ts +2 -0
- package/build/unparserImplementationInvariant.js +5 -0
- package/build/unparserInputCompanion.d.ts +15 -0
- package/build/unparserInputCompanion.js +13 -0
- package/build/unparserOutputCompanion.d.ts +15 -0
- package/build/unparserOutputCompanion.js +13 -0
- package/build/zip.d.ts +9 -17
- package/build/zipParser.d.ts +13 -10
- package/build/zipParser.js +48 -60
- package/build/zipParser.test.js +2 -7
- package/build/zipUnparser.d.ts +5 -0
- package/build/zipUnparser.js +171 -0
- package/build/zipUnparser.test.d.ts +1 -0
- package/build/zipUnparser.test.js +80 -0
- package/package.json +4 -2
- package/src/apk.ts +35 -3
- package/src/apkParser.test.ts +2 -2
- package/src/apkParser.test.ts.md +114 -111
- package/src/apkParser.test.ts.snap +0 -0
- package/src/apkParser.ts +150 -85
- package/src/apkUnparser.test.ts +37 -0
- package/src/apkUnparser.ts +120 -0
- package/src/arbitraryFileSystemEntry.ts +2 -4
- package/src/arbitraryZip.ts +20 -27
- package/src/arbitraryZipPermissions.ts +0 -25
- package/src/arbitraryZipStream.ts +4 -4
- package/src/arrayParser.test.ts +3 -3
- package/src/arrayParser.ts +3 -2
- package/src/arrayUnparser.ts +13 -0
- package/src/bsonParser.test.ts +2 -2
- package/src/bsonParser.ts +3 -3
- package/src/{parserInvariant.ts → customInvariant.ts} +1 -1
- package/src/debugLogParser.ts +1 -1
- package/src/elementParser.ts +3 -3
- package/src/endOfInputParser.ts +4 -4
- package/src/exactElementParser.ts +1 -1
- package/src/exactSequenceParser.ts +2 -2
- package/src/index.ts +15 -2
- package/src/inputReader.test.ts +7 -7
- package/src/inputReader.ts +5 -5
- package/src/javaKeyStore.ts +0 -0
- package/src/javaKeyStoreParser.test.ts +23 -0
- package/src/javaKeyStoreParser.test.ts.md +103 -0
- package/src/javaKeyStoreParser.test.ts.snap +0 -0
- package/src/javaKeyStoreParser.ts +136 -0
- package/src/jsonParser.test.ts +2 -2
- package/src/jsonParser.ts +13 -12
- package/src/listParser.ts +6 -6
- package/src/negativeLookaheadParser.ts +24 -0
- package/src/optionalParser.ts +3 -3
- package/src/parser.test.ts +19 -17
- package/src/parser.ts +7 -7
- package/src/parserAccessorParser.ts +1 -1
- package/src/parserConsumedSequenceParser.ts +20 -0
- package/src/parserContext.test.ts +7 -7
- package/src/parserContext.ts +18 -14
- package/src/parserCreatorCompose.ts +6 -6
- package/src/parserImplementationInvariant.ts +2 -2
- package/src/{inputCompanion.ts → parserInputCompanion.ts} +10 -6
- package/src/quantifierParser.ts +25 -0
- package/src/sequenceBuffer.test.ts +2 -2
- package/src/sequenceBuffer.ts +5 -5
- package/src/sequenceUnparser.ts +9 -0
- package/src/sliceBoundedParser.test.ts +2 -2
- package/src/sliceBoundedParser.ts +2 -2
- package/src/terminatedArrayParser.ts +3 -3
- package/src/uint8Array.ts +10 -0
- package/src/unparser.test.ts +221 -0
- package/src/unparser.ts +209 -0
- package/src/unparserContext.ts +127 -0
- package/src/unparserError.ts +12 -0
- package/src/unparserImplementationInvariant.ts +6 -0
- package/src/unparserOutputCompanion.ts +24 -0
- package/src/zip.ts +10 -22
- package/src/zipParser.test.ts +2 -8
- package/src/zipParser.ts +147 -129
- package/src/zipUnparser.test.ts +119 -0
- package/src/zipUnparser.ts +239 -0
- package/src/negativeLookahead.ts +0 -26
package/src/arrayParser.test.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import test from 'ava';
|
|
2
2
|
import { createArrayParser } from './arrayParser.js';
|
|
3
|
-
import { Parser, runParser } from './parser.js';
|
|
4
|
-
import {
|
|
3
|
+
import { type Parser, runParser } from './parser.js';
|
|
4
|
+
import { stringParserInputCompanion } from './parserInputCompanion.js';
|
|
5
5
|
|
|
6
6
|
test('does not loop forever with a child parser that does not consume anything', async t => {
|
|
7
7
|
const parser: Parser<undefined[], string> = createArrayParser(async () => undefined);
|
|
8
|
-
const result = await runParser(parser, 'foo',
|
|
8
|
+
const result = await runParser(parser, 'foo', stringParserInputCompanion);
|
|
9
9
|
|
|
10
10
|
t.deepEqual(result, []);
|
|
11
11
|
});
|
package/src/arrayParser.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getParserName, Parser, setParserName } from
|
|
2
|
-
import { ParserParsingFailedError } from
|
|
1
|
+
import { getParserName, type Parser, setParserName } from './parser.js';
|
|
2
|
+
import { ParserParsingFailedError } from './parserError.js';
|
|
3
3
|
|
|
4
4
|
export const createArrayParser = <ElementOutput, Sequence>(
|
|
5
5
|
elementParser: Parser<ElementOutput, Sequence>,
|
|
@@ -15,6 +15,7 @@ export const createArrayParser = <ElementOutput, Sequence>(
|
|
|
15
15
|
if (elementParserContext.position === initialPosition) {
|
|
16
16
|
return elements;
|
|
17
17
|
}
|
|
18
|
+
|
|
18
19
|
elements.push(element);
|
|
19
20
|
elementParserContext.unlookahead();
|
|
20
21
|
} catch (error) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Unparser } from "./unparser.js";
|
|
2
|
+
|
|
3
|
+
export const createArrayUnparser = <ElementInput, Sequence>(
|
|
4
|
+
elementUnparser: Unparser<ElementInput, Sequence>,
|
|
5
|
+
): Unparser<ElementInput[], Sequence> => {
|
|
6
|
+
const arrayUnparser: Unparser<ElementInput[], Sequence> = async function * (input, unparserContext) {
|
|
7
|
+
for (const element of input) {
|
|
8
|
+
yield * elementUnparser(element, unparserContext);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
return arrayUnparser;
|
|
13
|
+
}
|
package/src/bsonParser.test.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { BSON } from 'bson';
|
|
|
3
3
|
import { bsonDocumentParser } from './bsonParser.js';
|
|
4
4
|
import { arbitrarilySlicedAsyncIterator } from './arbitrarilySlicedAsyncInterator.js';
|
|
5
5
|
import { runParser } from './parser.js';
|
|
6
|
-
import {
|
|
6
|
+
import { uint8ArrayParserInputCompanion } from './parserInputCompanion.js';
|
|
7
7
|
|
|
8
8
|
testProp(
|
|
9
9
|
'bson',
|
|
@@ -27,7 +27,7 @@ testProp(
|
|
|
27
27
|
async (t, [ bsonUint8Array, bsonUint8ArrayChunkIterator ]) => {
|
|
28
28
|
const expected = BSON.deserialize(bsonUint8Array);
|
|
29
29
|
|
|
30
|
-
const actual = await runParser(bsonDocumentParser, bsonUint8ArrayChunkIterator,
|
|
30
|
+
const actual = await runParser(bsonDocumentParser, bsonUint8ArrayChunkIterator, uint8ArrayParserInputCompanion);
|
|
31
31
|
|
|
32
32
|
t.deepEqual(actual, expected);
|
|
33
33
|
},
|
package/src/bsonParser.ts
CHANGED
|
@@ -30,7 +30,7 @@ const cstringParser: Parser<string, Uint8Array> = promiseCompose(
|
|
|
30
30
|
)(),
|
|
31
31
|
nullByteParser,
|
|
32
32
|
),
|
|
33
|
-
([sequence]) => Buffer.from(sequence).toString('utf8'),
|
|
33
|
+
([ sequence ]) => Buffer.from(sequence).toString('utf8'),
|
|
34
34
|
);
|
|
35
35
|
|
|
36
36
|
const doubleParser: Parser<number, Uint8Array> = promiseCompose(buffer8Parser, buffer => buffer.readDoubleLE(0));
|
|
@@ -47,7 +47,7 @@ const createFixedLengthNullTerminatedStringParser = (lengthWihoutNullTerminator:
|
|
|
47
47
|
createFixedLengthStringParser(lengthWihoutNullTerminator),
|
|
48
48
|
nullByteParser,
|
|
49
49
|
]),
|
|
50
|
-
([string]) => string,
|
|
50
|
+
([ string ]) => string,
|
|
51
51
|
);
|
|
52
52
|
|
|
53
53
|
const bsonStringParser: Parser<string, Uint8Array> = async parserContext => {
|
|
@@ -119,7 +119,7 @@ const bsonElementListParser: Parser<Array<[ string, JsonValue ]>, Uint8Array> =
|
|
|
119
119
|
bsonElementParser,
|
|
120
120
|
nullByteParser,
|
|
121
121
|
),
|
|
122
|
-
([elements]) => elements,
|
|
122
|
+
([ elements ]) => elements,
|
|
123
123
|
);
|
|
124
124
|
|
|
125
125
|
export const bsonDocumentParser: Parser<JsonObject, Uint8Array> = promiseCompose(
|
|
@@ -4,7 +4,7 @@ export type Falsy = '' | 0 | false | undefined;
|
|
|
4
4
|
|
|
5
5
|
export type ValueOrAccessor<T> = T | (() => T);
|
|
6
6
|
|
|
7
|
-
export function
|
|
7
|
+
export function customInvariant<T>(
|
|
8
8
|
ErrorConstructor: Constructor<Error, [message: string]> | ((message: string) => Error),
|
|
9
9
|
value: T,
|
|
10
10
|
formatOrFormatLines: ValueOrAccessor<string | string[]>,
|
package/src/debugLogParser.ts
CHANGED
package/src/elementParser.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Parser } from
|
|
2
|
-
import { DeriveSequenceElement } from
|
|
1
|
+
import { type Parser } from './parser.js';
|
|
2
|
+
import { type DeriveSequenceElement } from './sequence.js';
|
|
3
3
|
|
|
4
|
-
export const createElementParser = <Sequence, Element = DeriveSequenceElement<Sequence>>(): Parser<Element, Sequence, Element> => parserContext => parserContext.read(0);
|
|
4
|
+
export const createElementParser = <Sequence, Element = DeriveSequenceElement<Sequence>>(): Parser<Element, Sequence, Element> => async parserContext => parserContext.read(0);
|
package/src/endOfInputParser.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Parser } from
|
|
2
|
-
import { DeriveSequenceElement } from
|
|
1
|
+
import { type Parser } from './parser.js';
|
|
2
|
+
import { type DeriveSequenceElement } from './sequence.js';
|
|
3
3
|
|
|
4
4
|
export const createEndOfInputParser = <Sequence, Element = DeriveSequenceElement<Sequence>>(): Parser<void, Sequence, Element> => async parserContext => {
|
|
5
5
|
parserContext.invariant(
|
|
6
6
|
await parserContext.peek(0) === undefined,
|
|
7
|
-
'Expected end of input.'
|
|
7
|
+
'Expected end of input.',
|
|
8
8
|
);
|
|
9
|
-
}
|
|
9
|
+
};
|
|
10
10
|
|
|
11
11
|
export const endOfInputParser = createEndOfInputParser<any, any>();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { inspect } from 'util';
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
2
|
import { setParserName, type Parser } from './parser.js';
|
|
3
3
|
|
|
4
4
|
export const createExactSequenceParser = <Sequence>(sequence: Sequence) => {
|
|
@@ -24,4 +24,4 @@ export const createExactSequenceParser = <Sequence>(sequence: Sequence) => {
|
|
|
24
24
|
setParserName(exactSequenceParser, inspect(sequence));
|
|
25
25
|
|
|
26
26
|
return exactSequenceParser;
|
|
27
|
-
}
|
|
27
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
|
|
2
2
|
export {
|
|
3
|
-
Parser,
|
|
3
|
+
type Parser,
|
|
4
4
|
runParser,
|
|
5
5
|
|
|
6
6
|
setParserName,
|
|
7
7
|
getParserName,
|
|
8
8
|
} from './parser.js';
|
|
9
9
|
|
|
10
|
-
export {
|
|
10
|
+
export type {
|
|
11
11
|
ParserContext,
|
|
12
12
|
} from './parserContext.js';
|
|
13
13
|
|
|
@@ -74,3 +74,16 @@ export {
|
|
|
74
74
|
export {
|
|
75
75
|
createDebugLogParser,
|
|
76
76
|
} from './debugLogParser.js';
|
|
77
|
+
|
|
78
|
+
export {
|
|
79
|
+
type Unparser,
|
|
80
|
+
runUnparser,
|
|
81
|
+
} from './unparser.js';
|
|
82
|
+
|
|
83
|
+
export {
|
|
84
|
+
createArrayUnparser,
|
|
85
|
+
} from './arrayUnparser.js';
|
|
86
|
+
|
|
87
|
+
export {
|
|
88
|
+
createSequenceUnparser,
|
|
89
|
+
} from './sequenceUnparser.js';
|
package/src/inputReader.test.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import test from 'ava';
|
|
2
2
|
import { InputReaderImplementation } from './inputReader.js';
|
|
3
|
-
import {
|
|
3
|
+
import { stringParserInputCompanion } from './parserInputCompanion.js';
|
|
4
4
|
import { ParserImplementationError } from './parserError.js';
|
|
5
5
|
|
|
6
6
|
test('inputReader', async t => {
|
|
7
|
-
const inputReader = new InputReaderImplementation(
|
|
7
|
+
const inputReader = new InputReaderImplementation(stringParserInputCompanion, (async function * () {
|
|
8
8
|
yield '';
|
|
9
9
|
yield 'abc';
|
|
10
10
|
yield 'def';
|
|
@@ -47,7 +47,7 @@ test('inputReader', async t => {
|
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
test('inputReader.peek concurrent', async t => {
|
|
50
|
-
const inputReader = new InputReaderImplementation(
|
|
50
|
+
const inputReader = new InputReaderImplementation(stringParserInputCompanion, (async function * () {
|
|
51
51
|
yield * 'abcdefgh';
|
|
52
52
|
})());
|
|
53
53
|
|
|
@@ -69,7 +69,7 @@ test('inputReader.peek concurrent', async t => {
|
|
|
69
69
|
});
|
|
70
70
|
|
|
71
71
|
test('inputReader skip while peeking', async t => {
|
|
72
|
-
const inputReader = new InputReaderImplementation(
|
|
72
|
+
const inputReader = new InputReaderImplementation(stringParserInputCompanion, (async function * () {
|
|
73
73
|
yield * 'abcdefgh';
|
|
74
74
|
})());
|
|
75
75
|
|
|
@@ -84,7 +84,7 @@ test('inputReader skip while peeking', async t => {
|
|
|
84
84
|
test('inputReader.lookahead', async t => {
|
|
85
85
|
let read = 0;
|
|
86
86
|
|
|
87
|
-
const inputReader = new InputReaderImplementation(
|
|
87
|
+
const inputReader = new InputReaderImplementation(stringParserInputCompanion, (async function * () {
|
|
88
88
|
for (const character of 'abcdefgh') {
|
|
89
89
|
read++;
|
|
90
90
|
yield character;
|
|
@@ -180,7 +180,7 @@ test('inputReader.lookahead', async t => {
|
|
|
180
180
|
test('inputReader.lookahead concurrent', async t => {
|
|
181
181
|
let read = 0;
|
|
182
182
|
|
|
183
|
-
const inputReader = new InputReaderImplementation(
|
|
183
|
+
const inputReader = new InputReaderImplementation(stringParserInputCompanion, (async function * () {
|
|
184
184
|
for (const character of 'abcdefgh') {
|
|
185
185
|
read++;
|
|
186
186
|
yield character;
|
|
@@ -211,7 +211,7 @@ test('inputReader.lookahead concurrent', async t => {
|
|
|
211
211
|
test('inputReader.lookahead skip position', async t => {
|
|
212
212
|
let read = 0;
|
|
213
213
|
|
|
214
|
-
const inputReader = new InputReaderImplementation(
|
|
214
|
+
const inputReader = new InputReaderImplementation(stringParserInputCompanion, (async function * () {
|
|
215
215
|
for (const character of 'abcdefgh') {
|
|
216
216
|
read++;
|
|
217
217
|
yield character;
|
package/src/inputReader.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import PromiseMutex from 'p-mutex';
|
|
2
2
|
import invariant from 'invariant';
|
|
3
3
|
import { type SequenceBuffer, SequenceBufferImplementation } from './sequenceBuffer.js';
|
|
4
|
-
import { type
|
|
4
|
+
import { type ParserInputCompanion } from './parserInputCompanion.js';
|
|
5
5
|
import { parserImplementationInvariant } from './parserImplementationInvariant.js';
|
|
6
6
|
|
|
7
7
|
export type InputReader<Sequence, Element> = {
|
|
@@ -26,10 +26,10 @@ export class InputReaderImplementation<Sequence, Element> implements InputReader
|
|
|
26
26
|
private readonly _sequenceBuffer: SequenceBuffer<Sequence, Element>;
|
|
27
27
|
|
|
28
28
|
constructor(
|
|
29
|
-
private readonly
|
|
29
|
+
private readonly _parserInputCompanion: ParserInputCompanion<Sequence, Element>,
|
|
30
30
|
private readonly _inputAsyncIterator: AsyncIterator<Sequence>,
|
|
31
31
|
) {
|
|
32
|
-
this._sequenceBuffer = new SequenceBufferImplementation<Sequence, Element>(this.
|
|
32
|
+
this._sequenceBuffer = new SequenceBufferImplementation<Sequence, Element>(this._parserInputCompanion);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
get [Symbol.toStringTag]() {
|
|
@@ -70,14 +70,14 @@ export class InputReaderImplementation<Sequence, Element> implements InputReader
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
parserImplementationInvariant(
|
|
73
|
-
this.
|
|
73
|
+
this._parserInputCompanion.is(inputIteratorResult.value),
|
|
74
74
|
[
|
|
75
75
|
'Input iterator result value (%s) is of unexpected type.',
|
|
76
76
|
'Expected a sequence (a chunk of input) recognized by the input companion (%s).',
|
|
77
77
|
'You may have provided a wrong input companion for the input.',
|
|
78
78
|
],
|
|
79
79
|
inputIteratorResult.value,
|
|
80
|
-
this.
|
|
80
|
+
this._parserInputCompanion.constructor.name,
|
|
81
81
|
);
|
|
82
82
|
|
|
83
83
|
this._sequenceBuffer.push(inputIteratorResult.value);
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import { uint8ArrayParserInputCompanion } from './parserInputCompanion.js';
|
|
3
|
+
import { runParser } from './parser.js';
|
|
4
|
+
import { javaKeyStoreParser } from './javaKeyStoreParser.js';
|
|
5
|
+
|
|
6
|
+
for (const javaKeyStoreCid of [
|
|
7
|
+
'bafkreig6k53b6p7bdvfjxc5mcb4qv3mffqls5ymqerxkqd6ih2xy5cs3n4',
|
|
8
|
+
]) {
|
|
9
|
+
test(
|
|
10
|
+
'javaKeyStore ' + javaKeyStoreCid,
|
|
11
|
+
async t => {
|
|
12
|
+
const javaKeyStoreResponse = await fetch('https://ipfs.io/ipfs/' + javaKeyStoreCid);
|
|
13
|
+
|
|
14
|
+
const javaKeyStoreStream = javaKeyStoreResponse.body!;
|
|
15
|
+
|
|
16
|
+
const actual = await runParser(javaKeyStoreParser, javaKeyStoreStream, uint8ArrayParserInputCompanion, {
|
|
17
|
+
errorJoinMode: 'all',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
t.snapshot(actual);
|
|
21
|
+
},
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Snapshot report for `src/javaKeyStoreParser.test.ts`
|
|
2
|
+
|
|
3
|
+
The actual snapshot is saved in `javaKeyStoreParser.test.ts.snap`.
|
|
4
|
+
|
|
5
|
+
Generated by [AVA](https://avajs.dev).
|
|
6
|
+
|
|
7
|
+
## javaKeyStore bafkreig6k53b6p7bdvfjxc5mcb4qv3mffqls5ymqerxkqd6ih2xy5cs3n4
|
|
8
|
+
|
|
9
|
+
> Snapshot 1
|
|
10
|
+
|
|
11
|
+
{
|
|
12
|
+
entries: [
|
|
13
|
+
{
|
|
14
|
+
alias: 'alias_name',
|
|
15
|
+
certificateChain: [
|
|
16
|
+
{
|
|
17
|
+
certificate: Uint8Array [
|
|
18
|
+
3082037d 30820265 a0030201 02020862 1867f6fc b0aab430 0d06092a 864886f7
|
|
19
|
+
0d01010b 0500306c 3110300e 06035504 06130755 6e6b6e6f 776e3110 300e0603
|
|
20
|
+
55040813 07556e6b 6e6f776e 3110300e 06035504 07130755 6e6b6e6f 776e3110
|
|
21
|
+
300e0603 55040a13 07556e6b 6e6f776e 3110300e 06035504 0b130755 6e6b6e6f
|
|
22
|
+
776e3110 300e0603 55040313 07556e6b 6e6f776e 3020170d 32343132 30383133
|
|
23
|
+
33343232 5a180f32 30353230 34323531 33333432 325a306c 3110300e 06035504
|
|
24
|
+
06130755 6e6b6e6f 776e3110 300e0603 55040813 07556e6b 6e6f776e 3110300e
|
|
25
|
+
06035504 07130755 6e6b6e6f 776e3110 300e0603 55040a13 07556e6b 6e6f776e
|
|
26
|
+
3110300e 06035504 0b130755 6e6b6e6f 776e3110 300e0603 55040313 07556e6b
|
|
27
|
+
6e6f776e 30820122 300d0609 2a864886 f70d0101 01050003 82010f00 3082010a
|
|
28
|
+
02820101 00c4d6d9 6e38ae16 54e1f3a6 d7b68d49 23a01024 ded06818 5e88835e
|
|
29
|
+
2edf5cdc 1839f148 864f20fc 355655a5 f1023e4f 6fced37e 0a55d77c d206c4f4
|
|
30
|
+
e6a7041e d16a439a 38bd824e 29e4d407 16a4a154 3e952838 79b5c1e6 1e376927
|
|
31
|
+
9ed92d62 c94bfd06 261b3034 1c5420c7 ca6d7925 8deafdb3 252ada5f 2a571b11
|
|
32
|
+
fb265869 d2c9335b ca9d2c06 5ce9586c 006b371b c555c122 d734be38 e57486b5
|
|
33
|
+
ccad06c2 b532dd4f 1a025e04 2bdea06a 1056367c 92b2db6e 9c8f6353 1d4d28fd
|
|
34
|
+
d6d78a45 9fcb5ada 16a9988b 032d6c69 6d63f739 9d5664b8 c0adf5a2 f748e177
|
|
35
|
+
e019a4a3 23a7fd10 dcd2be1b 6b8cbdcf eb7e76cd f35698a1 2c77b508 0d1a7884
|
|
36
|
+
ce8f1980 2f020301 0001a321 301f301d 0603551d 0e041604 14fdef9a ebf342b2
|
|
37
|
+
3bb007b1 6de4e2a8 0e953421 d4300d06 092a8648 86f70d01 010b0500 03820101
|
|
38
|
+
00c12e4e 03282b2f 36ee57a6 144d1774 55e08149 ce8e5b46 5f340757 7b301880
|
|
39
|
+
f3e7c4bd 564c5aa6 5202100e b819ae3a fb8c4adf c9e13cdc 82fdab8d c3cab7d7
|
|
40
|
+
68f01c41 18f67b0b 534eeb5c ab7ebeec af4cadd2 df3efe7c c4ec9311 9c3ec17e
|
|
41
|
+
3152746f 39d99717 042557f9 eb8aa2fa e87eb332 833c75db 1d373e50 2ea3b3ef
|
|
42
|
+
9bb847c0 8190fda7 318a0cac 374b507c 5db948e4 65c9ae38 4b304b8d d5c62014
|
|
43
|
+
ad01857b 5548dec0 b4c5b61f 0b21597a ede13707 e701dc44 933bb097 832e5158
|
|
44
|
+
2d19c606 a2b540ec bb501ffc 5d772e08 44e57a7f eb026278 c69e6160 8cddc2df
|
|
45
|
+
b56418b6 1cea3698 f86fa91d c7bd9e4b 83e80666 d343b087 7a0117a2 f8773fcc
|
|
46
|
+
31
|
|
47
|
+
],
|
|
48
|
+
type: 'X.509',
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
creationDate: Date 2024-12-08 13:34:25 771ms UTC {},
|
|
52
|
+
privateKey: Uint8Array [
|
|
53
|
+
308204fd 300e060a 2b060104 012a0211 01010500 048204e9 6bafd40a 4a5b9ba7
|
|
54
|
+
d71d60e8 3f9d1d2b e8f1a677 d30c00f9 8c27a431 cf19c6cf 01527d3c 23490657
|
|
55
|
+
9d30ee44 6f2a1c3d 8785c9e9 20cb403c 9c06bb6a 83eafd69 8a3e2a43 4a2340b1
|
|
56
|
+
873bf5d7 766a4003 935463f8 5894dd90 79c940b8 d7b908e9 5dc7b7e8 e01a9f55
|
|
57
|
+
7c31b465 cdf2b4e5 322f547c 74e28695 e49aff82 96144608 4e139e96 915022da
|
|
58
|
+
106a61b2 cda01a71 dd195aa2 d3db85e0 8d5e52b6 649e358e 38cc2b63 a95496e7
|
|
59
|
+
f13b35da a3812622 b6a8ca99 e25baf66 70cf30b6 3097794a 14385807 7f2ffd85
|
|
60
|
+
cd6c8ef9 4c87cd48 46cca8c1 9dc4c73e a62d6f0a 7fc8054f 1408c9b6 f7dd750b
|
|
61
|
+
595b6c60 2766bd8c db986cda 16829b4f a06f274f 5d540aac 814e5a50 9127bed4
|
|
62
|
+
a48dd702 f613b823 9218a9d0 344ba799 99e2caf2 8f9c976a 9db0fc39 d0d1c0a4
|
|
63
|
+
0338e5c2 03632ffb 5e58200a 3921a5bd 1516e598 f6e912aa 0f08129a f082088f
|
|
64
|
+
17165118 39fabef3 b6c93d25 1c35c8a5 b533546a 72e3dcb8 827b77b3 01b0bd60
|
|
65
|
+
a54ecae6 e37ab488 97ca7f26 014fe9f5 8b35c81e 5e201f05 43226ff7 fa41e019
|
|
66
|
+
3ed3f47a 92167c6c a691814d 4883471e 4ffdd7e5 66e32235 dfcbe212 99ef4559
|
|
67
|
+
d2b6fc5c 26e23964 e4c0ccf2 9ef4a0c1 9078ef4f 04ec1a8c 91916f0b 85bd18eb
|
|
68
|
+
1abe756c 9a90da9d 1293f95a db7edbc9 eb0aecd1 85ee554f 832dbb01 21dfacbf
|
|
69
|
+
12be629e 5b33e3b5 f3ebdcd1 69bc40b5 67607be4 d38e6a22 f8b520ab 6d498d23
|
|
70
|
+
a7af72f0 9a57690d c11113f8 744b77e2 b45b52a5 19e5cffe 3e19e106 ae2454d7
|
|
71
|
+
9741d01b 8cfbc4c0 16efaf4e d8ab96b3 bf04b7e1 81099b5f dcac9158 0636a33a
|
|
72
|
+
2ce348ba ddaeef30 0bb27d8a d762f9b1 0a87c57c 0787667f e7542cbb 4077ade1
|
|
73
|
+
c2784b03 fa590107 deaea210 59920506 472a5983 fdc7706e e99ec034 55b17fe8
|
|
74
|
+
8f8ed3a1 d43bde6e a392bbdd bdb81ff5 b6ad03de 8a46a97f 278f697a b0669db4
|
|
75
|
+
967ef9b8 7bca57f4 8507d655 5f77bce4 901010bc cf69106a 407481b0 efe8f5df
|
|
76
|
+
137aea5c cc6e1777 364809dd f39e2c80 437e11d4 692488ee 9760f10a 4b3078be
|
|
77
|
+
3f6b363d 25ccd315 4caee2d7 f29e44c9 3bb899fe 141e4233 b44a4dd8 6a7a3ab3
|
|
78
|
+
2ab7ecae 4c91bab1 a7223e88 d831ee3a 24fbca73 712dcd8c 22a22ea6 f74d52ff
|
|
79
|
+
52df9e06 c42e57cb 6e615094 52a6489a c985d992 38ed1861 f9c668d6 bedfa6b7
|
|
80
|
+
83f8f03f 66425389 fea1fd10 0cd78635 999194c9 54ea2233 99c8a384 7e034fe2
|
|
81
|
+
6be1e2b1 652ccb10 59c23b48 a34a4732 47b61a90 baa39965 db02b59d e5258a5e
|
|
82
|
+
6bd44e7b 46023f60 417c9a26 98d9435d cfed43cc c3235627 c4bc7589 bbbf520f
|
|
83
|
+
16480c66 8a355d3f aa4693db 499051be b85350d4 c45eb43f 7f09461c 882a4168
|
|
84
|
+
69135d31 db14dd3d bd49b28f 810f6cfc 70759172 66b79b43 951e020d 69bdb933
|
|
85
|
+
01f722f2 d77be629 8d0027be 96373dc2 e862792c 20894f6b ed8ec5ca 2b99fea5
|
|
86
|
+
4d37e8ca 01422458 025833bc 9bb4a8c8 491dee69 c8bb6b42 9eaa6bca 770b5a4d
|
|
87
|
+
95e9931e 12cffaa0 54566c76 7c323b6f f6f60e97 1e5c54fe eefa57f7 e6f6b352
|
|
88
|
+
d8f0f43e dc9b224a c7678d6b 35532593 6c1aac3b 4ae05907 4c70bb40 07373e8c
|
|
89
|
+
97126047 b3b23ae5 41e15db1 d251d5c5 e9a2dc51 6863ec2b ed2ad0b9 54d4ecc1
|
|
90
|
+
f184cba3 7e588d99 6be6caf1 72ba9771 650d92a7 3402ed51 4972e38e fb20b53e
|
|
91
|
+
1442e461 49054fc6 f6899e65 b02c968f 97884dd1 1e5b1bd6 d394ff8d a5155836
|
|
92
|
+
53d72788 e5de5454 5bbebefb 71b35c5d d63f9a1e 938210a8 d8f7e536 12494c5b
|
|
93
|
+
e5
|
|
94
|
+
],
|
|
95
|
+
type: 'privateKey',
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
hash: Uint8Array [
|
|
99
|
+
9bbf5a41 f2b3fcd4 a9ac77fe 0820317e 6a8f05e9
|
|
100
|
+
],
|
|
101
|
+
implementation: 'JKS',
|
|
102
|
+
version: 2,
|
|
103
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { createExactSequenceParser } from './exactSequenceParser.js';
|
|
2
|
+
import { createFixedLengthSequenceParser } from './fixedLengthSequenceParser.js';
|
|
3
|
+
import { type Parser, setParserName } from './parser.js';
|
|
4
|
+
import { parserCreatorCompose } from './parserCreatorCompose.js';
|
|
5
|
+
import { promiseCompose } from './promiseCompose.js';
|
|
6
|
+
import { createQuantifierParser } from './quantifierParser.js';
|
|
7
|
+
import { createTupleParser } from './tupleParser.js';
|
|
8
|
+
import { createUnionParser } from './unionParser.js';
|
|
9
|
+
|
|
10
|
+
// https://github.com/openjdk/jdk/blob/c517ffba7d9388e75b5d7bba77e565e71c0a7d76/src/java.base/share/classes/com/sun/crypto/provider/JceKeyStore.java#L512-L553
|
|
11
|
+
|
|
12
|
+
const uint64BEParser: Parser<bigint, Uint8Array> = promiseCompose(
|
|
13
|
+
createFixedLengthSequenceParser(8),
|
|
14
|
+
array => Buffer.from(array).readBigUInt64BE(),
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
setParserName(uint64BEParser, 'uint64BEParser');
|
|
18
|
+
|
|
19
|
+
const uint32BEParser: Parser<number, Uint8Array> = promiseCompose(
|
|
20
|
+
createFixedLengthSequenceParser(4),
|
|
21
|
+
array => Buffer.from(array).readUInt32BE(),
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
setParserName(uint32BEParser, 'uint32BEParser');
|
|
25
|
+
|
|
26
|
+
const uint16BEParser: Parser<number, Uint8Array> = promiseCompose(
|
|
27
|
+
createFixedLengthSequenceParser(2),
|
|
28
|
+
array => Buffer.from(array).readUInt16BE(),
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
setParserName(uint16BEParser, 'uint16BEParser');
|
|
32
|
+
|
|
33
|
+
const createUint32BECountPrefixedParser = <T>(elementParser: Parser<T, Uint8Array>): Parser<T[], Uint8Array> => parserCreatorCompose(
|
|
34
|
+
() => uint32BEParser,
|
|
35
|
+
count => createQuantifierParser(elementParser, count),
|
|
36
|
+
)();
|
|
37
|
+
|
|
38
|
+
const javaModifiedUTF8StringParser: Parser<string, Uint8Array> = promiseCompose(
|
|
39
|
+
parserCreatorCompose(
|
|
40
|
+
() => uint16BEParser,
|
|
41
|
+
length => createFixedLengthSequenceParser(length),
|
|
42
|
+
)(),
|
|
43
|
+
uint8Array => Buffer.from(uint8Array).toString('utf8'), // TODO?: Java Modified UTF-8 decoding
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const uint32LengthPrefixedUint8ArrayParser = parserCreatorCompose(
|
|
47
|
+
() => uint32BEParser,
|
|
48
|
+
length => createFixedLengthSequenceParser(length),
|
|
49
|
+
)();
|
|
50
|
+
|
|
51
|
+
const javaKeyStoreImplementationParser: Parser<'JKS' | 'JCEKS', Uint8Array> = promiseCompose(
|
|
52
|
+
createUnionParser<Uint8Array, Uint8Array>([
|
|
53
|
+
createExactSequenceParser<Uint8Array>(Buffer.from('feedfeed', 'hex')),
|
|
54
|
+
createExactSequenceParser<Uint8Array>(Buffer.from('cececece', 'hex')),
|
|
55
|
+
]),
|
|
56
|
+
uint8Array => uint8Array[0] === 0xFE ? 'JKS' : 'JCEKS',
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const javaKeyStorePrivateKeyEntryPrivateKeyParser = uint32LengthPrefixedUint8ArrayParser;
|
|
60
|
+
|
|
61
|
+
const javaKeyStorePrivateKeyEntryCertificateParser = promiseCompose(
|
|
62
|
+
createTupleParser([
|
|
63
|
+
javaModifiedUTF8StringParser,
|
|
64
|
+
uint32LengthPrefixedUint8ArrayParser,
|
|
65
|
+
]),
|
|
66
|
+
([ type, certificate ]) => ({ type, certificate }),
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const javaKeyStorePrivateKeyEntryCertificateChainParser = createUint32BECountPrefixedParser(
|
|
70
|
+
javaKeyStorePrivateKeyEntryCertificateParser,
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const javaKeyStorePrivateKeyEntryParser = promiseCompose(
|
|
74
|
+
createTupleParser([
|
|
75
|
+
createExactSequenceParser<Uint8Array>(Buffer.from('00000001', 'hex')),
|
|
76
|
+
javaModifiedUTF8StringParser,
|
|
77
|
+
uint64BEParser,
|
|
78
|
+
javaKeyStorePrivateKeyEntryPrivateKeyParser,
|
|
79
|
+
javaKeyStorePrivateKeyEntryCertificateChainParser,
|
|
80
|
+
]),
|
|
81
|
+
([
|
|
82
|
+
_tag,
|
|
83
|
+
alias,
|
|
84
|
+
creationDate,
|
|
85
|
+
privateKey,
|
|
86
|
+
certificateChain,
|
|
87
|
+
]) => ({
|
|
88
|
+
type: 'privateKey',
|
|
89
|
+
alias,
|
|
90
|
+
creationDate: new Date(Number(creationDate)),
|
|
91
|
+
privateKey,
|
|
92
|
+
certificateChain,
|
|
93
|
+
}),
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const javaKeyStoreTrustedCertEntryParser = createTupleParser([
|
|
97
|
+
createExactSequenceParser<Uint8Array>(Buffer.from('00000002', 'hex')),
|
|
98
|
+
async parserContext => parserContext.invariant(false, 'Not implemented'),
|
|
99
|
+
]);
|
|
100
|
+
|
|
101
|
+
const javaKeyStoreSecretKeyEntryParser = createTupleParser([
|
|
102
|
+
createExactSequenceParser<Uint8Array>(Buffer.from('00000003', 'hex')),
|
|
103
|
+
async parserContext => parserContext.invariant(false, 'Not implemented'),
|
|
104
|
+
]);
|
|
105
|
+
|
|
106
|
+
const javaKeyStoreEntryParser = createUnionParser([
|
|
107
|
+
javaKeyStorePrivateKeyEntryParser,
|
|
108
|
+
javaKeyStoreTrustedCertEntryParser,
|
|
109
|
+
javaKeyStoreSecretKeyEntryParser,
|
|
110
|
+
]);
|
|
111
|
+
|
|
112
|
+
const javaKeyStoreEntriesParser = createUint32BECountPrefixedParser(
|
|
113
|
+
javaKeyStoreEntryParser,
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const javaKeyStoreParser_ = createTupleParser([
|
|
117
|
+
javaKeyStoreImplementationParser,
|
|
118
|
+
uint32BEParser,
|
|
119
|
+
javaKeyStoreEntriesParser,
|
|
120
|
+
createFixedLengthSequenceParser(20),
|
|
121
|
+
]);
|
|
122
|
+
|
|
123
|
+
export const javaKeyStoreParser: Parser<unknown, Uint8Array> = promiseCompose(
|
|
124
|
+
javaKeyStoreParser_,
|
|
125
|
+
([
|
|
126
|
+
implementation,
|
|
127
|
+
version,
|
|
128
|
+
entries,
|
|
129
|
+
hash,
|
|
130
|
+
]) => ({
|
|
131
|
+
implementation,
|
|
132
|
+
version,
|
|
133
|
+
entries,
|
|
134
|
+
hash,
|
|
135
|
+
}),
|
|
136
|
+
);
|
package/src/jsonParser.test.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { testProp, fc } from '@fast-check/ava';
|
|
|
2
2
|
import { jsonValueParser } from './jsonParser.js';
|
|
3
3
|
import { runParser } from './parser.js';
|
|
4
4
|
import { arbitrarilySlicedAsyncIterator } from './arbitrarilySlicedAsyncInterator.js';
|
|
5
|
-
import {
|
|
5
|
+
import { stringParserInputCompanion } from './parserInputCompanion.js';
|
|
6
6
|
|
|
7
7
|
testProp(
|
|
8
8
|
'json',
|
|
@@ -13,7 +13,7 @@ testProp(
|
|
|
13
13
|
),
|
|
14
14
|
],
|
|
15
15
|
async (t, [ jsonString, jsonStringChunkIterator ]) => {
|
|
16
|
-
const actual = await runParser(jsonValueParser, jsonStringChunkIterator,
|
|
16
|
+
const actual = await runParser(jsonValueParser, jsonStringChunkIterator, stringParserInputCompanion, {
|
|
17
17
|
errorJoinMode: 'none',
|
|
18
18
|
});
|
|
19
19
|
const expected = JSON.parse(jsonString);
|
package/src/jsonParser.ts
CHANGED
|
@@ -83,7 +83,7 @@ const jsonNumberParser: Parser<number, string> = parserCreatorCompose(
|
|
|
83
83
|
() => createArrayParser(
|
|
84
84
|
parserCreatorCompose(
|
|
85
85
|
() => elementParser,
|
|
86
|
-
|
|
86
|
+
character => async parserContext => {
|
|
87
87
|
parserContext.invariant(
|
|
88
88
|
(
|
|
89
89
|
character === '-'
|
|
@@ -101,7 +101,7 @@ const jsonNumberParser: Parser<number, string> = parserCreatorCompose(
|
|
|
101
101
|
},
|
|
102
102
|
)(),
|
|
103
103
|
),
|
|
104
|
-
|
|
104
|
+
characters => async parserContext => {
|
|
105
105
|
parserContext.invariant(characters.length > 0, 'Expected at least one character');
|
|
106
106
|
|
|
107
107
|
return Number(characters.join(''));
|
|
@@ -116,6 +116,7 @@ const jsonFalseParser: Parser<false, string> = promiseCompose(createExactSequenc
|
|
|
116
116
|
|
|
117
117
|
setParserName(jsonFalseParser, 'jsonFalseParser');
|
|
118
118
|
|
|
119
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
119
120
|
const jsonNullParser: Parser<null, string> = promiseCompose(createExactSequenceParser('null'), () => null);
|
|
120
121
|
|
|
121
122
|
setParserName(jsonNullParser, 'jsonNullParser');
|
|
@@ -138,7 +139,7 @@ const jsonObjectEntryParser: Parser<[string, JsonValue], string> = promiseCompos
|
|
|
138
139
|
whitespaceParser,
|
|
139
140
|
createParserAccessorParser(() => jsonValueParser),
|
|
140
141
|
]),
|
|
141
|
-
([key, _whitespace1, _colon, _whitespace2, value]) => [key, value],
|
|
142
|
+
([ key, _whitespace1, _colon, _whitespace2, value ]) => [ key, value ],
|
|
142
143
|
);
|
|
143
144
|
|
|
144
145
|
const jsonObjectParser: Parser<JsonObject, string> = promiseCompose(
|
|
@@ -155,25 +156,25 @@ const jsonObjectParser: Parser<JsonObject, string> = promiseCompose(
|
|
|
155
156
|
createExactSequenceParser(','),
|
|
156
157
|
whitespaceParser,
|
|
157
158
|
]),
|
|
158
|
-
([entry]) => entry,
|
|
159
|
+
([ entry ]) => entry,
|
|
159
160
|
),
|
|
160
161
|
promiseCompose(
|
|
161
162
|
createTupleParser([
|
|
162
163
|
createParserAccessorParser(() => jsonObjectEntryParser),
|
|
163
164
|
whitespaceParser,
|
|
164
165
|
]),
|
|
165
|
-
([value]) => value,
|
|
166
|
+
([ value ]) => value,
|
|
166
167
|
),
|
|
167
168
|
]),
|
|
168
169
|
createExactSequenceParser('}'),
|
|
169
170
|
),
|
|
170
|
-
([entries]) => entries,
|
|
171
|
+
([ entries ]) => entries,
|
|
171
172
|
),
|
|
172
173
|
]),
|
|
173
|
-
([ _brace, _whitespace, entries]) => {
|
|
174
|
+
([ _brace, _whitespace, entries ]) => {
|
|
174
175
|
const object: Writable<JsonObject> = {};
|
|
175
176
|
|
|
176
|
-
for (const [key, value] of entries) {
|
|
177
|
+
for (const [ key, value ] of entries) {
|
|
177
178
|
Object.defineProperty(object, key, {
|
|
178
179
|
value,
|
|
179
180
|
enumerable: true,
|
|
@@ -198,22 +199,22 @@ const jsonArrayParser: Parser<JsonArray, string> = promiseCompose(
|
|
|
198
199
|
createExactSequenceParser(','),
|
|
199
200
|
whitespaceParser,
|
|
200
201
|
]),
|
|
201
|
-
([value]) => value,
|
|
202
|
+
([ value ]) => value,
|
|
202
203
|
),
|
|
203
204
|
promiseCompose(
|
|
204
205
|
createTupleParser([
|
|
205
206
|
createParserAccessorParser(() => jsonValueParser),
|
|
206
207
|
whitespaceParser,
|
|
207
208
|
]),
|
|
208
|
-
([value]) => value,
|
|
209
|
+
([ value ]) => value,
|
|
209
210
|
),
|
|
210
211
|
]),
|
|
211
212
|
createExactSequenceParser(']'),
|
|
212
213
|
),
|
|
213
|
-
([values]) => values,
|
|
214
|
+
([ values ]) => values,
|
|
214
215
|
),
|
|
215
216
|
]),
|
|
216
|
-
([_bracket, _whitespace, values]) => values,
|
|
217
|
+
([ _bracket, _whitespace, values ]) => values,
|
|
217
218
|
);
|
|
218
219
|
|
|
219
220
|
export const jsonValueParser: Parser<JsonValue, string> = createUnionParser([
|