@futpib/parser 1.0.0 → 1.0.2
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/allSettledStream.js +32 -14
- package/build/allSettledStream.test.js +32 -0
- package/build/androidPackage.d.ts +39 -0
- package/build/androidPackageParser.d.ts +17 -0
- package/build/androidPackageParser.js +183 -0
- package/build/{apkParser.test.js → androidPackageParser.test.js} +7 -7
- package/build/androidPackageUnparser.d.ts +4 -0
- package/build/androidPackageUnparser.js +90 -0
- package/build/androidPackageUnparser.test.js +26 -0
- package/build/arbitrarilySlicedAsyncInterable.d.ts +3 -1
- package/build/arbitrarilySlicedAsyncInterable.js +3 -3
- 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 +4 -4
- package/build/arrayUnparser.d.ts +2 -0
- package/build/arrayUnparser.js +8 -0
- package/build/backsmali.d.ts +1 -0
- package/build/backsmali.js +22 -0
- package/build/bsonParser.js +6 -2
- package/build/bsonParser.test.js +2 -2
- package/build/{parserInvariant.d.ts → customInvariant.d.ts} +1 -1
- package/build/{parserInvariant.js → customInvariant.js} +1 -1
- package/build/dalvikBytecodeParser/formatParsers.d.ts +97 -0
- package/build/dalvikBytecodeParser/formatParsers.js +169 -0
- package/build/dalvikBytecodeParser.d.ts +107 -0
- package/build/dalvikBytecodeParser.js +836 -0
- package/build/dalvikExecutable.d.ts +158 -0
- package/build/dalvikExecutable.js +20 -0
- package/build/dalvikExecutableParser/stringSyntaxParser.d.ts +4 -0
- package/build/dalvikExecutableParser/stringSyntaxParser.js +76 -0
- package/build/dalvikExecutableParser/typeParsers.d.ts +10 -0
- package/build/dalvikExecutableParser/typeParsers.js +34 -0
- package/build/dalvikExecutableParser/typedNumbers.d.ts +90 -0
- package/build/dalvikExecutableParser/typedNumbers.js +19 -0
- package/build/dalvikExecutableParser.d.ts +5 -0
- package/build/dalvikExecutableParser.js +1439 -0
- package/build/dalvikExecutableParser.test.js +70 -0
- package/build/dalvikExecutableParserAgainstSmaliParser.test.js +298 -0
- package/build/debugLogInputParser.d.ts +4 -0
- package/build/debugLogInputParser.js +16 -0
- package/build/debugLogParser.d.ts +1 -1
- package/build/debugLogParser.js +15 -4
- package/build/disjunctionParser.d.ts +2 -1
- package/build/disjunctionParser.js +4 -2
- package/build/elementParser.d.ts +2 -2
- package/build/elementParser.js +1 -1
- package/build/elementTerminatedArrayParser.d.ts +3 -0
- package/build/elementTerminatedArrayParser.js +18 -0
- package/build/elementTerminatedArrayParser.test.js +52 -0
- package/build/elementTerminatedSequenceArrayParser.d.ts +3 -0
- package/build/elementTerminatedSequenceArrayParser.js +32 -0
- package/build/elementTerminatedSequenceArrayParser.test.js +34 -0
- package/build/elementTerminatedSequenceParser.d.ts +3 -0
- package/build/elementTerminatedSequenceParser.js +27 -0
- package/build/elementTerminatedSequenceParser.test.js +34 -0
- package/build/endOfInputParser.d.ts +2 -2
- package/build/exactElementParser.d.ts +1 -1
- package/build/exactElementParser.js +10 -5
- package/build/exactSequenceParser.d.ts +2 -1
- package/build/exactSequenceParser.js +12 -2
- package/build/fetchCid.d.ts +1 -0
- package/build/fetchCid.js +107 -0
- package/build/fixedLengthSequenceParser.d.ts +1 -0
- package/build/fixedLengthSequenceParser.js +18 -1
- package/build/fixedLengthSequenceParser.test.js +41 -0
- package/build/hasExecutable.d.ts +1 -0
- package/build/hasExecutable.js +8 -0
- package/build/highResolutionTimer.d.ts +16 -0
- package/build/highResolutionTimer.js +42 -0
- package/build/index.d.ts +5 -2
- package/build/index.js +3 -0
- package/build/inputReader.d.ts +14 -3
- package/build/inputReader.js +43 -6
- package/build/inputReader.test.js +172 -7
- package/build/inputReaderState.d.ts +10 -0
- package/build/inputReaderState.js +16 -0
- package/build/inspect.d.ts +1 -0
- package/build/inspect.js +7 -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/jsonParser.d.ts +2 -0
- package/build/jsonParser.js +13 -15
- package/build/jsonParser.test.js +2 -2
- package/build/leb128Parser.d.ts +7 -0
- package/build/leb128Parser.js +82 -0
- package/build/leb128Parser.test.d.ts +1 -0
- package/build/leb128Parser.test.js +107 -0
- package/build/listParser.d.ts +1 -1
- package/build/listParser.js +5 -5
- package/build/lookaheadParser.d.ts +2 -0
- package/build/lookaheadParser.js +14 -0
- package/build/{negativeLookahead.d.ts → negativeLookaheadParser.d.ts} +1 -1
- package/build/negativeLookaheadParser.js +24 -0
- package/build/negativeLookaheadParser.test.d.ts +1 -0
- package/build/negativeLookaheadParser.test.js +30 -0
- package/build/nonEmptyArrayParser.d.ts +2 -0
- package/build/nonEmptyArrayParser.js +32 -0
- package/build/nonEmptyArrayParser.test.d.ts +1 -0
- package/build/nonEmptyArrayParser.test.js +16 -0
- package/build/optionalParser.d.ts +1 -1
- package/build/optionalParser.js +2 -2
- package/build/parser.d.ts +13 -4
- package/build/parser.js +67 -32
- package/build/parser.test.js +94 -27
- package/build/parserAccessorParser.d.ts +1 -1
- package/build/parserAccessorParser.js +9 -1
- package/build/parserConsumedSequenceParser.d.ts +2 -0
- package/build/parserConsumedSequenceParser.js +22 -0
- package/build/parserContext.d.ts +20 -6
- package/build/parserContext.js +70 -40
- package/build/parserContext.test.js +34 -7
- package/build/parserCreatorCompose.d.ts +4 -3
- package/build/parserCreatorCompose.js +9 -3
- package/build/parserError.d.ts +6 -0
- package/build/parserError.js +6 -6
- package/build/parserImplementationInvariant.d.ts +1 -1
- package/build/parserImplementationInvariant.js +2 -2
- package/build/parserInputCompanion.d.ts +35 -0
- package/build/parserInputCompanion.js +68 -0
- package/build/promiseCompose.d.ts +1 -1
- package/build/promiseCompose.js +12 -1
- package/build/promiseSettled.d.ts +1 -0
- package/build/promiseSettled.js +4 -0
- package/build/quantifierParser.d.ts +2 -0
- package/build/quantifierParser.js +17 -0
- package/build/separatedArrayParser.d.ts +2 -0
- package/build/separatedArrayParser.js +39 -0
- package/build/separatedArrayParser.test.d.ts +1 -0
- package/build/separatedArrayParser.test.js +21 -0
- package/build/sequenceBuffer.d.ts +13 -3
- package/build/sequenceBuffer.js +60 -8
- package/build/sequenceBuffer.test.js +59 -2
- package/build/sequenceTerminatedSequenceParser.d.ts +5 -0
- package/build/sequenceTerminatedSequenceParser.js +32 -0
- package/build/sequenceTerminatedSequenceParser.test.d.ts +1 -0
- package/build/sequenceTerminatedSequenceParser.test.js +37 -0
- package/build/sequenceUnparser.d.ts +2 -0
- package/build/sequenceUnparser.js +6 -0
- package/build/skipParser.d.ts +1 -1
- package/build/skipParser.js +4 -2
- package/build/skipToParser.d.ts +2 -0
- package/build/skipToParser.js +11 -0
- package/build/sliceBoundedParser.d.ts +2 -2
- package/build/sliceBoundedParser.js +8 -3
- package/build/sliceBoundedParser.test.js +37 -3
- package/build/smali.d.ts +1 -0
- package/build/smali.js +17 -0
- package/build/smaliParser.d.ts +12 -0
- package/build/smaliParser.js +656 -0
- package/build/smaliParser.test.d.ts +1 -0
- package/build/smaliParser.test.js +115 -0
- package/build/terminatedArrayParser.d.ts +4 -2
- package/build/terminatedArrayParser.js +82 -5
- package/build/terminatedArrayParser.test.d.ts +1 -0
- package/build/terminatedArrayParser.test.js +131 -0
- package/build/toAsyncIterable.d.ts +1 -0
- package/build/toAsyncIterable.js +7 -0
- package/build/toAsyncIterator.d.ts +1 -0
- package/build/toAsyncIterator.js +33 -0
- package/build/tupleParser.d.ts +4 -0
- package/build/tupleParser.js +1 -5
- package/build/uint8Array.d.ts +1 -0
- package/build/uint8Array.js +7 -0
- package/build/unionParser.d.ts +2 -1
- package/build/unionParser.js +27 -12
- package/build/unionParser.test.d.ts +1 -0
- package/build/unionParser.test.js +60 -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/unparserOutputCompanion.d.ts +15 -0
- package/build/unparserOutputCompanion.js +13 -0
- package/build/zip.d.ts +9 -17
- package/build/zipParser.d.ts +20 -12
- package/build/zipParser.js +83 -71
- package/build/zipParser.test.js +2 -7
- package/build/zipUnparser.d.ts +8 -0
- package/build/zipUnparser.js +200 -0
- package/build/zipUnparser.test.d.ts +1 -0
- package/build/zipUnparser.test.js +80 -0
- package/package.json +26 -8
- package/src/allSettledStream.test.ts +40 -0
- package/src/allSettledStream.ts +47 -15
- package/src/androidPackage.ts +48 -0
- package/src/{apkParser.test.ts → androidPackageParser.test.ts} +7 -8
- package/src/androidPackageParser.test.ts.md +271 -0
- package/src/androidPackageParser.test.ts.snap +0 -0
- package/src/androidPackageParser.ts +440 -0
- package/src/androidPackageUnparser.test.ts +36 -0
- package/src/androidPackageUnparser.ts +120 -0
- package/src/arbitrarilySlicedAsyncInterable.ts +7 -2
- 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 +4 -4
- package/src/arrayParser.ts +3 -2
- package/src/arrayUnparser.ts +13 -0
- package/src/backsmali.ts +30 -0
- package/src/bsonParser.test.ts +2 -2
- package/src/bsonParser.ts +16 -5
- package/src/{parserInvariant.ts → customInvariant.ts} +2 -2
- package/src/dalvikBytecodeParser/formatParsers.ts +421 -0
- package/src/dalvikBytecodeParser.ts +2074 -0
- package/src/dalvikExecutable.ts +220 -0
- package/src/dalvikExecutableParser/stringSyntaxParser.ts +145 -0
- package/src/dalvikExecutableParser/typeParsers.ts +65 -0
- package/src/dalvikExecutableParser/typedNumbers.ts +57 -0
- package/src/dalvikExecutableParser.test.ts +89 -0
- package/src/dalvikExecutableParser.test.ts.md +634 -0
- package/src/dalvikExecutableParser.test.ts.snap +0 -0
- package/src/dalvikExecutableParser.ts +2768 -0
- package/src/dalvikExecutableParserAgainstSmaliParser.test.ts +346 -0
- package/src/debugLogInputParser.ts +28 -0
- package/src/debugLogParser.ts +20 -4
- package/src/disjunctionParser.ts +10 -5
- package/src/elementParser.ts +3 -3
- package/src/elementTerminatedArrayParser.test.ts +99 -0
- package/src/elementTerminatedArrayParser.ts +31 -0
- package/src/elementTerminatedSequenceArrayParser.test.ts +54 -0
- package/src/elementTerminatedSequenceArrayParser.ts +52 -0
- package/src/elementTerminatedSequenceParser.test.ts +54 -0
- package/src/elementTerminatedSequenceParser.ts +43 -0
- package/src/endOfInputParser.ts +4 -4
- package/src/exactElementParser.ts +18 -12
- package/src/exactSequenceParser.ts +24 -3
- package/src/fetchCid.ts +125 -0
- package/src/fixedLengthSequenceParser.test.ts +77 -0
- package/src/fixedLengthSequenceParser.ts +28 -1
- package/src/hasExecutable.ts +11 -0
- package/src/highResolutionTimer.ts +49 -0
- package/src/index.ts +15 -2
- package/src/inputReader.test.ts +216 -7
- package/src/inputReader.ts +80 -5
- package/src/inputReaderState.ts +33 -0
- package/src/inspect.ts +9 -0
- package/src/javaKeyStore.ts +0 -0
- package/src/javaKeyStoreParser.test.ts +22 -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 +23 -34
- package/src/leb128Parser.test.ts +171 -0
- package/src/leb128Parser.ts +125 -0
- package/src/listParser.ts +6 -6
- package/src/lookaheadParser.ts +19 -0
- package/src/negativeLookaheadParser.test.ts +53 -0
- package/src/negativeLookaheadParser.ts +36 -0
- package/src/nonEmptyArrayParser.test.ts +20 -0
- package/src/nonEmptyArrayParser.ts +44 -0
- package/src/optionalParser.ts +4 -3
- package/src/parser.test.ts +148 -27
- package/src/parser.test.ts.md +21 -21
- package/src/parser.test.ts.snap +0 -0
- package/src/parser.ts +153 -49
- package/src/parserAccessorParser.ts +12 -2
- package/src/parserConsumedSequenceParser.ts +29 -0
- package/src/parserContext.test.ts +38 -7
- package/src/parserContext.ts +127 -51
- package/src/parserCreatorCompose.ts +25 -7
- package/src/parserError.ts +9 -6
- package/src/parserImplementationInvariant.ts +2 -2
- package/src/parserInputCompanion.ts +102 -0
- package/src/promiseCompose.ts +17 -3
- package/src/promiseSettled.ts +6 -0
- package/src/quantifierParser.ts +25 -0
- package/src/separatedArrayParser.test.ts +34 -0
- package/src/separatedArrayParser.ts +55 -0
- package/src/sequenceBuffer.test.ts +72 -2
- package/src/sequenceBuffer.ts +93 -7
- package/src/sequenceTerminatedSequenceParser.test.ts +60 -0
- package/src/sequenceTerminatedSequenceParser.ts +62 -0
- package/src/sequenceUnparser.ts +9 -0
- package/src/skipParser.ts +7 -5
- package/src/skipToParser.ts +16 -0
- package/src/sliceBoundedParser.test.ts +45 -3
- package/src/sliceBoundedParser.ts +21 -3
- package/src/smali.ts +24 -0
- package/src/smaliParser.test.ts +132 -0
- package/src/smaliParser.test.ts.md +2320 -0
- package/src/smaliParser.test.ts.snap +0 -0
- package/src/smaliParser.ts +1166 -0
- package/src/terminatedArrayParser.test.ts +258 -0
- package/src/terminatedArrayParser.ts +111 -6
- package/src/toAsyncIterable.ts +7 -0
- package/src/toAsyncIterator.ts +48 -0
- package/src/tupleParser.ts +8 -5
- package/src/uint8Array.ts +10 -0
- package/src/unionParser.test.ts +79 -0
- package/src/unionParser.ts +44 -16
- 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 +223 -146
- package/src/zipUnparser.test.ts +119 -0
- package/src/zipUnparser.ts +300 -0
- package/build/apk.d.ts +0 -13
- package/build/apkParser.d.ts +0 -3
- package/build/apkParser.js +0 -135
- package/build/arbitraryDosDate.d.ts +0 -2
- package/build/arbitraryDosDate.js +0 -8
- package/build/arbitraryZipEntry.d.ts +0 -3
- package/build/arbitraryZipEntry.js +0 -26
- package/build/createDisjunctionParser.d.ts +0 -2
- package/build/createDisjunctionParser.js +0 -47
- package/build/createExactParser.d.ts +0 -2
- package/build/createExactParser.js +0 -12
- package/build/createSequentialUnionParser.d.ts +0 -2
- package/build/createSequentialUnionParser.js +0 -69
- package/build/fixedLengthChunkParser.d.ts +0 -2
- package/build/fixedLengthChunkParser.js +0 -12
- package/build/fixedLengthParser.d.ts +0 -2
- package/build/fixedLengthParser.js +0 -12
- package/build/inputChunkBuffer.d.ts +0 -15
- package/build/inputChunkBuffer.js +0 -40
- package/build/inputChunkBuffer.test.js +0 -34
- package/build/inputCompanion.d.ts +0 -18
- package/build/inputCompanion.js +0 -28
- package/build/invariantDefined.d.ts +0 -1
- package/build/invariantDefined.js +0 -5
- package/build/invariantIdentity.d.ts +0 -3
- package/build/invariantIdentity.js +0 -5
- package/build/jsonParser2.d.ts +0 -3
- package/build/jsonParser2.js +0 -52
- package/build/jsonParser2.test.js +0 -22
- package/build/negativeLookahead.js +0 -20
- package/build/parserCompose.d.ts +0 -3
- package/build/parserCompose.js +0 -7
- package/build/parserImplementationInvariantInvariant.d.ts +0 -3
- package/build/parserImplementationInvariantInvariant.js +0 -15
- package/build/promiseFish.d.ts +0 -1
- package/build/promiseFish.js +0 -3
- package/build/sequenceParser.d.ts +0 -3
- package/build/sequenceParser.js +0 -10
- package/build/terminatedSequenceParser.d.ts +0 -2
- package/build/terminatedSequenceParser.js +0 -24
- package/build/zipEntry.d.ts +0 -28
- package/build/zipFile.d.ts +0 -32
- package/build/zipFileEntry.d.ts +0 -6
- package/src/apk.ts +0 -16
- package/src/apkParser.test.ts.md +0 -268
- package/src/apkParser.test.ts.snap +0 -0
- package/src/apkParser.ts +0 -327
- package/src/inputCompanion.ts +0 -43
- package/src/invariantDefined.ts +0 -6
- package/src/invariantIdentity.ts +0 -8
- package/src/negativeLookahead.ts +0 -26
- /package/build/{apk.js → androidPackage.js} +0 -0
- /package/build/{apkParser.test.d.ts → androidPackageParser.test.d.ts} +0 -0
- /package/build/{arbitraryDosPermissions.d.ts → androidPackageUnparser.test.d.ts} +0 -0
- /package/build/{arbitraryDosPermissions.js → dalvikExecutableParser.test.d.ts} +0 -0
- /package/build/{inputChunkBuffer.test.d.ts → dalvikExecutableParserAgainstSmaliParser.test.d.ts} +0 -0
- /package/build/{jsonParser2.test.d.ts → elementTerminatedArrayParser.test.d.ts} +0 -0
- /package/build/{parserParsingInvariant.d.ts → elementTerminatedSequenceArrayParser.test.d.ts} +0 -0
- /package/build/{parserParsingInvariant.js → elementTerminatedSequenceParser.test.d.ts} +0 -0
- /package/build/{zipEntry.js → fixedLengthSequenceParser.test.d.ts} +0 -0
- /package/build/{zipFile.js → javaKeyStore.d.ts} +0 -0
- /package/build/{zipFileEntry.js → javaKeyStore.js} +0 -0
package/build/parserContext.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
import { ParserUnexpectedEndOfInputError, ParserParsingInvariantError, ParserParsingJoinNoneError, ParserParsingJoinAllError, ParserParsingJoinDeepestError, ParserParsingJoinFurthestError } from './parserError.js';
|
|
3
|
-
import {
|
|
1
|
+
/* eslint-disable prefer-arrow-callback */
|
|
2
|
+
import { ParserUnexpectedEndOfInputError, ParserParsingInvariantError, ParserParsingJoinNoneError, ParserParsingJoinAllError, ParserParsingJoinDeepestError, ParserParsingJoinFurthestError, } from './parserError.js';
|
|
3
|
+
import { customInvariant } from './customInvariant.js';
|
|
4
|
+
import { parserImplementationInvariant } from './parserImplementationInvariant.js';
|
|
4
5
|
let parserContextId = 0;
|
|
5
6
|
export class ParserContextImplementation {
|
|
6
|
-
|
|
7
|
+
_parserInputCompanion;
|
|
7
8
|
_inputReader;
|
|
8
9
|
_parentParserContext;
|
|
9
10
|
_options;
|
|
10
11
|
_id = parserContextId++;
|
|
11
12
|
_depth;
|
|
12
13
|
_exclusiveChildParserContext = undefined;
|
|
13
|
-
constructor(
|
|
14
|
-
this.
|
|
14
|
+
constructor(_parserInputCompanion, _inputReader, _parentParserContext = undefined, _options) {
|
|
15
|
+
this._parserInputCompanion = _parserInputCompanion;
|
|
15
16
|
this._inputReader = _inputReader;
|
|
16
17
|
this._parentParserContext = _parentParserContext;
|
|
17
18
|
this._options = _options;
|
|
@@ -30,13 +31,28 @@ export class ParserContextImplementation {
|
|
|
30
31
|
].join(' ');
|
|
31
32
|
}
|
|
32
33
|
from(elements) {
|
|
33
|
-
return this.
|
|
34
|
+
return this._parserInputCompanion.from(elements);
|
|
35
|
+
}
|
|
36
|
+
concat(sequences) {
|
|
37
|
+
return this._parserInputCompanion.concat(sequences);
|
|
34
38
|
}
|
|
35
39
|
length(sequence) {
|
|
36
|
-
return this.
|
|
40
|
+
return this._parserInputCompanion.length(sequence);
|
|
37
41
|
}
|
|
38
42
|
at(sequence, index) {
|
|
39
|
-
return this.
|
|
43
|
+
return this._parserInputCompanion.at(sequence, index);
|
|
44
|
+
}
|
|
45
|
+
subsequence(sequence, start, end) {
|
|
46
|
+
return this._parserInputCompanion.subsequence(sequence, start, end);
|
|
47
|
+
}
|
|
48
|
+
indexOf(sequence, element, fromIndex) {
|
|
49
|
+
return this._parserInputCompanion.indexOf(sequence, element, fromIndex);
|
|
50
|
+
}
|
|
51
|
+
indexOfSubsequence(sequence, subsequence, fromIndex) {
|
|
52
|
+
return this._parserInputCompanion.indexOfSubsequence(sequence, subsequence, fromIndex);
|
|
53
|
+
}
|
|
54
|
+
equals(sequenceA, sequenceB) {
|
|
55
|
+
return this._parserInputCompanion.equals(sequenceA, sequenceB);
|
|
40
56
|
}
|
|
41
57
|
get position() {
|
|
42
58
|
return this._inputReader.position;
|
|
@@ -48,6 +64,17 @@ export class ParserContextImplementation {
|
|
|
48
64
|
}
|
|
49
65
|
return this._inputReader.peek(offset);
|
|
50
66
|
}
|
|
67
|
+
async peekSequence(start, end) {
|
|
68
|
+
if (this._options.sliceEnd !== undefined
|
|
69
|
+
&& (this.position + end - 1) >= this._options.sliceEnd) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
parserImplementationInvariant(start >= 0, 'start (%s) >= 0', start);
|
|
73
|
+
parserImplementationInvariant(end >= start, 'end (%s) >= start (%s)', start, end);
|
|
74
|
+
parserImplementationInvariant(Number.isSafeInteger(start), 'start (%d) is not a safe integer', start);
|
|
75
|
+
parserImplementationInvariant(Number.isSafeInteger(end), 'end (%d) is not a safe integer', end);
|
|
76
|
+
return this._inputReader.peekSequence(start, end);
|
|
77
|
+
}
|
|
51
78
|
skip(offset) {
|
|
52
79
|
this._inputReader.skip(offset);
|
|
53
80
|
}
|
|
@@ -59,13 +86,19 @@ export class ParserContextImplementation {
|
|
|
59
86
|
this.skip(offset + 1);
|
|
60
87
|
return element;
|
|
61
88
|
}
|
|
89
|
+
async readSequence(start, end) {
|
|
90
|
+
const sequence = await this.peekSequence(start, end);
|
|
91
|
+
if (sequence === undefined) {
|
|
92
|
+
throw new ParserUnexpectedEndOfInputError('', this._depth, this.position);
|
|
93
|
+
}
|
|
94
|
+
this.skip(end);
|
|
95
|
+
return sequence;
|
|
96
|
+
}
|
|
62
97
|
lookahead(options = {}) {
|
|
63
98
|
const lookaheadInputReader = this._inputReader.lookahead();
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
invariant(this.position === lookaheadInputReader.position, 'lookahead this.position (%s) === lookaheadInputReader.position (%s)', this.position, lookaheadInputReader.position);
|
|
68
|
-
const lookaheadParserContext = new ParserContextImplementation(this._inputCompanion, lookaheadInputReader, this, {
|
|
99
|
+
parserImplementationInvariant(this.position === lookaheadInputReader.position, 'lookahead this.position (%s) === lookaheadInputReader.position (%s)', this.position, lookaheadInputReader.position);
|
|
100
|
+
const ParserContext = this._options.parserContextClass ?? ParserContextImplementation;
|
|
101
|
+
const lookaheadParserContext = new ParserContext(this._parserInputCompanion, lookaheadInputReader, this, {
|
|
69
102
|
...this._options,
|
|
70
103
|
...options,
|
|
71
104
|
debugName: [
|
|
@@ -77,60 +110,57 @@ export class ParserContextImplementation {
|
|
|
77
110
|
options.debugName,
|
|
78
111
|
].join(''),
|
|
79
112
|
});
|
|
80
|
-
|
|
81
|
-
debugger;
|
|
82
|
-
}
|
|
83
|
-
invariant(this.position === lookaheadParserContext.position, 'lookahead this.position (%s) === lookaheadParserContext.position (%s)', this.position, lookaheadParserContext.position);
|
|
113
|
+
parserImplementationInvariant(this.position === lookaheadParserContext.position, 'lookahead this.position (%s) === lookaheadParserContext.position (%s)', this.position, lookaheadParserContext.position);
|
|
84
114
|
return lookaheadParserContext;
|
|
85
115
|
}
|
|
86
116
|
unlookahead() {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
||
|
|
117
|
+
const parentParserContext = parserImplementationInvariant(this._parentParserContext, 'this._parentParserContext !== undefined');
|
|
118
|
+
parserImplementationInvariant((parentParserContext._exclusiveChildParserContext === undefined
|
|
119
|
+
|| parentParserContext._exclusiveChildParserContext === this), [
|
|
90
120
|
'Parent\'s exclusive child must be undefined or this',
|
|
91
121
|
'this: %s',
|
|
92
122
|
'parent: %s',
|
|
93
123
|
'parent.exclusiveChild: %s',
|
|
94
|
-
].join('\n'), this.toString(),
|
|
95
|
-
|
|
96
|
-
const offset = this._inputReader.position -
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
this._inputReader =
|
|
100
|
-
|
|
124
|
+
].join('\n'), this.toString(), parentParserContext.toString(), parentParserContext._exclusiveChildParserContext?.toString());
|
|
125
|
+
parserImplementationInvariant(parentParserContext.position <= this.position, 'unlookahead this._parentParserContext.position (%s) <= this.position (%s)', parentParserContext.position, this.position);
|
|
126
|
+
const offset = this._inputReader.position - parentParserContext._inputReader.position;
|
|
127
|
+
parentParserContext.skip(offset);
|
|
128
|
+
parserImplementationInvariant(parentParserContext.position === this.position, 'unlookahead this._parentParserContext.position (%s) === this.position (%s)', parentParserContext.position, this.position);
|
|
129
|
+
this._inputReader = parentParserContext._inputReader;
|
|
130
|
+
parentParserContext._exclusiveChildParserContext = this;
|
|
101
131
|
if (this._exclusiveChildParserContext) {
|
|
102
132
|
this._exclusiveChildParserContext.unlookahead();
|
|
103
133
|
}
|
|
104
134
|
}
|
|
105
135
|
dispose() {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
||
|
|
136
|
+
const parentParserContext = parserImplementationInvariant(this._parentParserContext, 'this._parentParserContext !== undefined');
|
|
137
|
+
parserImplementationInvariant((parentParserContext._exclusiveChildParserContext === undefined
|
|
138
|
+
|| parentParserContext._exclusiveChildParserContext === this), [
|
|
109
139
|
'Parent\'s exclusive child must be undefined or this',
|
|
110
140
|
'this: %s',
|
|
111
141
|
'parent: %s',
|
|
112
142
|
'parent.exclusiveChild: %s',
|
|
113
|
-
].join('\n'), this.toString(),
|
|
114
|
-
|
|
143
|
+
].join('\n'), this.toString(), parentParserContext.toString(), parentParserContext._exclusiveChildParserContext?.toString());
|
|
144
|
+
parentParserContext._exclusiveChildParserContext = undefined;
|
|
115
145
|
this._parentParserContext = undefined;
|
|
116
146
|
}
|
|
117
147
|
invariant(value, format, ...formatArguments) {
|
|
118
148
|
const parserContext = this;
|
|
119
|
-
return
|
|
149
|
+
return customInvariant(function (message) {
|
|
120
150
|
return new ParserParsingInvariantError(message, parserContext._depth, parserContext.position);
|
|
121
151
|
}, value, format, ...formatArguments);
|
|
122
152
|
}
|
|
123
153
|
invariantJoin(value, childErrors, format, ...formatArguments) {
|
|
124
|
-
|
|
154
|
+
parserImplementationInvariant(childErrors.length > 0, 'childErrors.length > 0');
|
|
125
155
|
const errorJoinMode = this._options.errorJoinMode ?? 'none';
|
|
126
156
|
const parserContext = this;
|
|
127
157
|
if (errorJoinMode === 'none') {
|
|
128
|
-
return
|
|
158
|
+
return customInvariant(function (message) {
|
|
129
159
|
return new ParserParsingJoinNoneError(message, parserContext._depth, parserContext.position);
|
|
130
160
|
}, value, format, ...formatArguments);
|
|
131
161
|
}
|
|
132
162
|
if (errorJoinMode === 'furthest') {
|
|
133
|
-
return
|
|
163
|
+
return customInvariant(function (message) {
|
|
134
164
|
let furthestPosition = 0;
|
|
135
165
|
let furthestChildErrors = [];
|
|
136
166
|
for (const childError of childErrors) {
|
|
@@ -154,7 +184,7 @@ export class ParserContextImplementation {
|
|
|
154
184
|
}, value, format, ...formatArguments);
|
|
155
185
|
}
|
|
156
186
|
if (errorJoinMode === 'deepest') {
|
|
157
|
-
return
|
|
187
|
+
return customInvariant(function (message) {
|
|
158
188
|
let deepestDepth = 0;
|
|
159
189
|
let deepestChildErrors = [];
|
|
160
190
|
for (const childError of childErrors) {
|
|
@@ -178,7 +208,7 @@ export class ParserContextImplementation {
|
|
|
178
208
|
}, value, format, ...formatArguments);
|
|
179
209
|
}
|
|
180
210
|
if (errorJoinMode === 'all') {
|
|
181
|
-
return
|
|
211
|
+
return customInvariant(function (message) {
|
|
182
212
|
message += [
|
|
183
213
|
'',
|
|
184
214
|
'Child error stacks, indented:',
|
|
@@ -188,6 +218,6 @@ export class ParserContextImplementation {
|
|
|
188
218
|
return new ParserParsingJoinAllError(message, parserContext._depth, parserContext.position, childErrors);
|
|
189
219
|
}, value, format, ...formatArguments);
|
|
190
220
|
}
|
|
191
|
-
|
|
221
|
+
return parserImplementationInvariant(false, 'Unsupported errorJoinMode: %s', errorJoinMode);
|
|
192
222
|
}
|
|
193
223
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import test from 'ava';
|
|
2
2
|
import { ParserContextImplementation } from './parserContext.js';
|
|
3
|
-
import {
|
|
3
|
+
import { stringParserInputCompanion } from './parserInputCompanion.js';
|
|
4
4
|
import { InputReaderImplementation } from './inputReader.js';
|
|
5
5
|
import { ParserUnexpectedEndOfInputError } from './parserError.js';
|
|
6
6
|
const commonParserContextArguments = [
|
|
@@ -11,7 +11,7 @@ const commonParserContextArguments = [
|
|
|
11
11
|
},
|
|
12
12
|
];
|
|
13
13
|
test('parserContext.read', async (t) => {
|
|
14
|
-
const parserContext = new ParserContextImplementation(
|
|
14
|
+
const parserContext = new ParserContextImplementation(stringParserInputCompanion, new InputReaderImplementation(stringParserInputCompanion, (async function* () {
|
|
15
15
|
yield '';
|
|
16
16
|
yield 'abc';
|
|
17
17
|
yield 'def';
|
|
@@ -25,8 +25,28 @@ test('parserContext.read', async (t) => {
|
|
|
25
25
|
instanceOf: ParserUnexpectedEndOfInputError,
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
|
+
test('parserContext.readSequence', async (t) => {
|
|
29
|
+
const parserContext = new ParserContextImplementation(stringParserInputCompanion, new InputReaderImplementation(stringParserInputCompanion, (async function* () {
|
|
30
|
+
yield '';
|
|
31
|
+
yield 'abc';
|
|
32
|
+
yield 'def';
|
|
33
|
+
yield '';
|
|
34
|
+
yield 'gh';
|
|
35
|
+
})()), ...commonParserContextArguments);
|
|
36
|
+
t.is(await parserContext.readSequence(0, 0), '');
|
|
37
|
+
t.is(await parserContext.readSequence(0, 1), 'a');
|
|
38
|
+
t.is(await parserContext.readSequence(1, 4), 'cde');
|
|
39
|
+
t.is(await parserContext.readSequence(0, 1), 'f');
|
|
40
|
+
t.is(await parserContext.readSequence(0, 0), '');
|
|
41
|
+
t.is(await parserContext.readSequence(0, 1), 'g');
|
|
42
|
+
t.is(await parserContext.readSequence(1, 1), '');
|
|
43
|
+
t.is(await parserContext.readSequence(0, 0), '');
|
|
44
|
+
await t.throwsAsync(async () => parserContext.readSequence(0, 1), {
|
|
45
|
+
instanceOf: ParserUnexpectedEndOfInputError,
|
|
46
|
+
});
|
|
47
|
+
});
|
|
28
48
|
test('parserContext.lookahead', async (t) => {
|
|
29
|
-
const parserContext = new ParserContextImplementation(
|
|
49
|
+
const parserContext = new ParserContextImplementation(stringParserInputCompanion, new InputReaderImplementation(stringParserInputCompanion, (async function* () {
|
|
30
50
|
yield* 'abcdefgh';
|
|
31
51
|
})()), ...commonParserContextArguments);
|
|
32
52
|
const lookaheadContext1 = parserContext.lookahead();
|
|
@@ -35,11 +55,15 @@ test('parserContext.lookahead', async (t) => {
|
|
|
35
55
|
sliceEnd: 3,
|
|
36
56
|
});
|
|
37
57
|
t.is(await lookaheadContext3.peek(2), 'c');
|
|
58
|
+
t.is(await lookaheadContext3.peekSequence(2, 3), 'c');
|
|
38
59
|
t.is(await lookaheadContext3.peek(3), undefined);
|
|
60
|
+
t.is(await lookaheadContext3.peekSequence(3, 4), undefined);
|
|
39
61
|
t.is(await lookaheadContext3.read(0), 'a');
|
|
40
62
|
t.is(await lookaheadContext3.read(0), 'b');
|
|
41
63
|
t.is(await lookaheadContext3.read(0), 'c');
|
|
42
64
|
t.is(await lookaheadContext3.peek(0), undefined);
|
|
65
|
+
t.is(await lookaheadContext3.peekSequence(0, 1), undefined);
|
|
66
|
+
t.is(await lookaheadContext3.peekSequence(0, 0), '');
|
|
43
67
|
t.is(await parserContext.peek(0), 'a');
|
|
44
68
|
t.is(await lookaheadContext1.peek(0), 'a');
|
|
45
69
|
t.is(await lookaheadContext2.peek(0), 'a');
|
|
@@ -52,9 +76,12 @@ test('parserContext.lookahead', async (t) => {
|
|
|
52
76
|
t.is(lookaheadContext1.position, 1);
|
|
53
77
|
t.is(lookaheadContext2.position, 0);
|
|
54
78
|
t.is(lookaheadContext3.position, 3);
|
|
79
|
+
lookaheadContext3.skip(1);
|
|
80
|
+
t.is(await lookaheadContext3.peekSequence(0, 0), undefined);
|
|
81
|
+
t.is(lookaheadContext3.position, 4);
|
|
55
82
|
});
|
|
56
83
|
test('parserContext.unlookahead', async (t) => {
|
|
57
|
-
const parserContext = new ParserContextImplementation(
|
|
84
|
+
const parserContext = new ParserContextImplementation(stringParserInputCompanion, new InputReaderImplementation(stringParserInputCompanion, (async function* () {
|
|
58
85
|
yield* 'abcdefgh';
|
|
59
86
|
})()), ...commonParserContextArguments);
|
|
60
87
|
const lookaheadContext = parserContext.lookahead();
|
|
@@ -68,7 +95,7 @@ test('parserContext.unlookahead', async (t) => {
|
|
|
68
95
|
t.is(await lookaheadContext.read(0), 'c');
|
|
69
96
|
});
|
|
70
97
|
test('parserContext.unlookahead while peeking', async (t) => {
|
|
71
|
-
const parserContext = new ParserContextImplementation(
|
|
98
|
+
const parserContext = new ParserContextImplementation(stringParserInputCompanion, new InputReaderImplementation(stringParserInputCompanion, (async function* () {
|
|
72
99
|
yield* 'abcdefgh';
|
|
73
100
|
})()), ...commonParserContextArguments);
|
|
74
101
|
const lookaheadContext = parserContext.lookahead();
|
|
@@ -79,7 +106,7 @@ test('parserContext.unlookahead while peeking', async (t) => {
|
|
|
79
106
|
t.is(await peekPromise, 'c');
|
|
80
107
|
});
|
|
81
108
|
test('parserContext deep unlookahead normal order', async (t) => {
|
|
82
|
-
const parserContext = new ParserContextImplementation(
|
|
109
|
+
const parserContext = new ParserContextImplementation(stringParserInputCompanion, new InputReaderImplementation(stringParserInputCompanion, (async function* () {
|
|
83
110
|
yield* 'abcdefgh';
|
|
84
111
|
})()), ...commonParserContextArguments);
|
|
85
112
|
const child = parserContext.lookahead();
|
|
@@ -92,7 +119,7 @@ test('parserContext deep unlookahead normal order', async (t) => {
|
|
|
92
119
|
t.is(await parserContext.read(0), 'd');
|
|
93
120
|
});
|
|
94
121
|
test('parserContext deep unlookahead weird order', async (t) => {
|
|
95
|
-
const parserContext = new ParserContextImplementation(
|
|
122
|
+
const parserContext = new ParserContextImplementation(stringParserInputCompanion, new InputReaderImplementation(stringParserInputCompanion, (async function* () {
|
|
96
123
|
yield* 'abcdefgh';
|
|
97
124
|
})()), ...commonParserContextArguments);
|
|
98
125
|
const child = parserContext.lookahead({
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { Parser } from
|
|
2
|
-
import { DeriveSequenceElement } from
|
|
3
|
-
export declare function parserCreatorCompose<Arguments extends unknown[], OutputA, OutputB, Sequence, Element = DeriveSequenceElement<Sequence>>(f1: (...
|
|
1
|
+
import { type Parser } from './parser.js';
|
|
2
|
+
import { type DeriveSequenceElement } from './sequence.js';
|
|
3
|
+
export declare function parserCreatorCompose<Arguments extends unknown[], OutputA, OutputB, Sequence, Element = DeriveSequenceElement<Sequence>>(f1: (...arguments_: Arguments) => Parser<OutputA, Sequence, Element>, f2: (outputA: OutputA) => Parser<OutputB, Sequence, Element>): (...arguments_: Arguments) => Parser<OutputB, Sequence, Element>;
|
|
4
|
+
export declare function parserCreatorComposeMem<Arguments extends unknown[], OutputA, OutputB, Sequence, Element = DeriveSequenceElement<Sequence>>(f1: (...arguments_: Arguments) => Parser<OutputA, Sequence, Element>, f2: (outputA: OutputA) => Parser<OutputB, Sequence, Element>): (...arguments_: Arguments) => Parser<OutputB, Sequence, Element>;
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
import mem from 'mem';
|
|
1
2
|
export function parserCreatorCompose(f1, f2) {
|
|
2
|
-
|
|
3
|
-
const parserA = f1(...
|
|
4
|
-
|
|
3
|
+
const parserCreatorComposedOuter = (...arguments_) => {
|
|
4
|
+
const parserA = f1(...arguments_);
|
|
5
|
+
const parserCreatorComposedInner = async (parserContext) => {
|
|
5
6
|
const outputA = await parserA(parserContext);
|
|
6
7
|
const parserB = f2(outputA);
|
|
7
8
|
return parserB(parserContext);
|
|
8
9
|
};
|
|
10
|
+
return parserCreatorComposedInner;
|
|
9
11
|
};
|
|
12
|
+
return parserCreatorComposedOuter;
|
|
13
|
+
}
|
|
14
|
+
export function parserCreatorComposeMem(f1, f2) {
|
|
15
|
+
return parserCreatorCompose(mem(f1), mem(f2));
|
|
10
16
|
}
|
package/build/parserError.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { InputReaderState } from "./inputReaderState.js";
|
|
1
2
|
export declare class ParserError extends Error {
|
|
2
3
|
name: string;
|
|
4
|
+
position: undefined | number;
|
|
5
|
+
inputReaderSate: undefined | InputReaderState<unknown>;
|
|
3
6
|
}
|
|
4
7
|
export declare class ParserImplementationError extends ParserError {
|
|
5
8
|
name: string;
|
|
@@ -41,3 +44,6 @@ export declare class ParserParsingInvariantError extends ParserParsingFailedErro
|
|
|
41
44
|
export declare class ParserUnexpectedEndOfInputError extends ParserParsingFailedError {
|
|
42
45
|
name: string;
|
|
43
46
|
}
|
|
47
|
+
export declare class ParserUnexpectedRemainingInputError extends ParserParsingFailedError {
|
|
48
|
+
name: string;
|
|
49
|
+
}
|
package/build/parserError.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export class ParserError extends Error {
|
|
2
2
|
name = 'ParserError';
|
|
3
|
+
position = undefined;
|
|
4
|
+
inputReaderSate = undefined;
|
|
3
5
|
}
|
|
4
6
|
export class ParserImplementationError extends ParserError {
|
|
5
7
|
name = 'ParserImplementationError';
|
|
@@ -12,12 +14,7 @@ export class ParserParsingFailedError extends ParserError {
|
|
|
12
14
|
position;
|
|
13
15
|
name = 'ParserParsingFailedError';
|
|
14
16
|
constructor(message, depth, position) {
|
|
15
|
-
super(
|
|
16
|
-
'(position: ',
|
|
17
|
-
position,
|
|
18
|
-
') ',
|
|
19
|
-
message,
|
|
20
|
-
].join(''));
|
|
17
|
+
super(message);
|
|
21
18
|
this.depth = depth;
|
|
22
19
|
this.position = position;
|
|
23
20
|
}
|
|
@@ -59,3 +56,6 @@ export class ParserParsingInvariantError extends ParserParsingFailedError {
|
|
|
59
56
|
export class ParserUnexpectedEndOfInputError extends ParserParsingFailedError {
|
|
60
57
|
name = 'ParserUnexpectedEndOfInputError';
|
|
61
58
|
}
|
|
59
|
+
export class ParserUnexpectedRemainingInputError extends ParserParsingFailedError {
|
|
60
|
+
name = 'ParserUnexpectedRemainingInputError';
|
|
61
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type Falsy, type ValueOrAccessor } from './
|
|
1
|
+
import { type Falsy, type ValueOrAccessor } from './customInvariant.js';
|
|
2
2
|
export declare function parserImplementationInvariant<T>(value: T, format: ValueOrAccessor<string | string[]>, ...formatArguments: any[]): Exclude<T, Falsy>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ParserImplementationInvariantError } from './parserError.js';
|
|
2
|
-
import {
|
|
2
|
+
import { customInvariant } from './customInvariant.js';
|
|
3
3
|
export function parserImplementationInvariant(value, format, ...formatArguments) {
|
|
4
|
-
return
|
|
4
|
+
return customInvariant(ParserImplementationInvariantError, value, format, ...formatArguments);
|
|
5
5
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type ParserInputCompanion<Sequence, Element> = {
|
|
2
|
+
is(value: unknown): value is Sequence;
|
|
3
|
+
from(elements: Element[]): Sequence;
|
|
4
|
+
concat(sequences: Sequence[]): Sequence;
|
|
5
|
+
length(sequence: Sequence): number;
|
|
6
|
+
at(sequence: Sequence, index: number): Element | undefined;
|
|
7
|
+
subsequence(sequence: Sequence, start: number, end: number): Sequence;
|
|
8
|
+
indexOf(sequence: Sequence, element: Element, fromIndex?: number): number;
|
|
9
|
+
indexOfSubsequence(sequence: Sequence, subsequence: Sequence, fromIndex?: number): number;
|
|
10
|
+
equals(sequenceA: Sequence, sequenceB: Sequence): boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare class StringParserInputCompanion implements ParserInputCompanion<string, string> {
|
|
13
|
+
is(value: unknown): value is string;
|
|
14
|
+
from(elements: string[]): string;
|
|
15
|
+
concat(sequences: string[]): string;
|
|
16
|
+
length(sequence: string): number;
|
|
17
|
+
at(sequence: string, index: number): string | undefined;
|
|
18
|
+
subsequence(sequence: string, start: number, end: number): string;
|
|
19
|
+
indexOf(sequence: string, element: string, fromIndex?: number): number;
|
|
20
|
+
indexOfSubsequence(sequence: string, subsequence: string, fromIndex?: number): number;
|
|
21
|
+
equals(sequenceA: string, sequenceB: string): boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare const stringParserInputCompanion: StringParserInputCompanion;
|
|
24
|
+
export declare class Uint8ArrayParserInputCompanion implements ParserInputCompanion<Uint8Array, number> {
|
|
25
|
+
is(value: unknown): value is Uint8Array;
|
|
26
|
+
from(elements: number[]): Uint8Array;
|
|
27
|
+
concat(sequences: Uint8Array[]): Uint8Array;
|
|
28
|
+
length(sequence: Uint8Array): number;
|
|
29
|
+
at(sequence: Uint8Array, index: number): number | undefined;
|
|
30
|
+
subsequence(sequence: Uint8Array, start: number, end: number): Uint8Array;
|
|
31
|
+
indexOf(sequence: Uint8Array, element: number, fromIndex?: number): number;
|
|
32
|
+
indexOfSubsequence(sequence: Uint8Array, subsequence: Uint8Array, fromIndex?: number): number;
|
|
33
|
+
equals(sequenceA: Uint8Array, sequenceB: Uint8Array): boolean;
|
|
34
|
+
}
|
|
35
|
+
export declare const uint8ArrayParserInputCompanion: Uint8ArrayParserInputCompanion;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export class StringParserInputCompanion {
|
|
2
|
+
is(value) {
|
|
3
|
+
return typeof value === 'string';
|
|
4
|
+
}
|
|
5
|
+
from(elements) {
|
|
6
|
+
return elements.join('');
|
|
7
|
+
}
|
|
8
|
+
concat(sequences) {
|
|
9
|
+
return sequences.join('');
|
|
10
|
+
}
|
|
11
|
+
length(sequence) {
|
|
12
|
+
return sequence.length;
|
|
13
|
+
}
|
|
14
|
+
at(sequence, index) {
|
|
15
|
+
return sequence.at(index);
|
|
16
|
+
}
|
|
17
|
+
subsequence(sequence, start, end) {
|
|
18
|
+
return sequence.slice(start, end);
|
|
19
|
+
}
|
|
20
|
+
indexOf(sequence, element, fromIndex) {
|
|
21
|
+
return sequence.indexOf(element, fromIndex);
|
|
22
|
+
}
|
|
23
|
+
indexOfSubsequence(sequence, subsequence, fromIndex) {
|
|
24
|
+
return sequence.indexOf(subsequence, fromIndex);
|
|
25
|
+
}
|
|
26
|
+
equals(sequenceA, sequenceB) {
|
|
27
|
+
return sequenceA === sequenceB;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export const stringParserInputCompanion = new StringParserInputCompanion();
|
|
31
|
+
export class Uint8ArrayParserInputCompanion {
|
|
32
|
+
is(value) {
|
|
33
|
+
return value instanceof Uint8Array;
|
|
34
|
+
}
|
|
35
|
+
from(elements) {
|
|
36
|
+
return new Uint8Array(elements);
|
|
37
|
+
}
|
|
38
|
+
concat(sequences) {
|
|
39
|
+
return new Uint8Array(Buffer.concat(sequences));
|
|
40
|
+
}
|
|
41
|
+
length(sequence) {
|
|
42
|
+
return sequence.length;
|
|
43
|
+
}
|
|
44
|
+
at(sequence, index) {
|
|
45
|
+
return sequence.at(index);
|
|
46
|
+
}
|
|
47
|
+
subsequence(sequence, start, end) {
|
|
48
|
+
return sequence.subarray(start, end);
|
|
49
|
+
}
|
|
50
|
+
indexOf(sequence, element, fromIndex) {
|
|
51
|
+
return sequence.indexOf(element, fromIndex);
|
|
52
|
+
}
|
|
53
|
+
indexOfSubsequence(sequence, subsequence, fromIndex) {
|
|
54
|
+
return Buffer.from(sequence).indexOf(Buffer.from(subsequence), fromIndex);
|
|
55
|
+
}
|
|
56
|
+
equals(sequenceA, sequenceB) {
|
|
57
|
+
if (sequenceA.length !== sequenceB.length) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
for (let index = 0; index < sequenceA.length; index++) {
|
|
61
|
+
if (sequenceA[index] !== sequenceB[index]) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export const uint8ArrayParserInputCompanion = new Uint8ArrayParserInputCompanion();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function promiseCompose<A, B, C>(f1: (a: A) => Promise<B>, f2: (b: B) => C | Promise<C>): (a: A) => Promise<C>;
|
|
1
|
+
export declare function promiseCompose<A, B, C>(f1: (a: A) => B | Promise<B>, f2: (b: B) => C | Promise<C>): (a: A) => C | Promise<C>;
|
package/build/promiseCompose.js
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
export function promiseCompose(f1, f2) {
|
|
2
|
-
|
|
2
|
+
function promiseComposed(a) {
|
|
3
|
+
const bOrBPromise = f1(a);
|
|
4
|
+
if (bOrBPromise instanceof Promise) {
|
|
5
|
+
return bOrBPromise.then(f2);
|
|
6
|
+
}
|
|
7
|
+
return f2(bOrBPromise);
|
|
8
|
+
}
|
|
9
|
+
;
|
|
10
|
+
Object.defineProperty(promiseComposed, 'name', {
|
|
11
|
+
value: `promiseCompose(${f1.name}, ${f2.name})`,
|
|
12
|
+
});
|
|
13
|
+
return promiseComposed;
|
|
3
14
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function promiseSettled<T>(promise: Promise<T>): Promise<PromiseSettledResult<T>>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getParserName, setParserName } from './parser.js';
|
|
2
|
+
export const createQuantifierParser = (childParser, count) => {
|
|
3
|
+
const quantifierParser = async (parserContext) => {
|
|
4
|
+
const elements = [];
|
|
5
|
+
for (let index = 0; index < count; index++) {
|
|
6
|
+
elements.push(await childParser(parserContext));
|
|
7
|
+
}
|
|
8
|
+
return elements;
|
|
9
|
+
};
|
|
10
|
+
setParserName(quantifierParser, [
|
|
11
|
+
getParserName(childParser, 'anonymousQuantifierChild'),
|
|
12
|
+
'{',
|
|
13
|
+
count,
|
|
14
|
+
'}',
|
|
15
|
+
].join(''));
|
|
16
|
+
return quantifierParser;
|
|
17
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { getParserName, setParserName } from './parser.js';
|
|
2
|
+
import { ParserParsingFailedError } from './parserError.js';
|
|
3
|
+
import { promiseCompose } from './promiseCompose.js';
|
|
4
|
+
import { createTupleParser } from './tupleParser.js';
|
|
5
|
+
export const createSeparatedArrayParser = (elementParser, separatorParser) => {
|
|
6
|
+
const separatorThenElementParser = promiseCompose(createTupleParser([
|
|
7
|
+
separatorParser,
|
|
8
|
+
elementParser,
|
|
9
|
+
]), ([, element]) => element);
|
|
10
|
+
const separatedArrayParser = async (parserContext) => {
|
|
11
|
+
let parser = elementParser;
|
|
12
|
+
const elements = [];
|
|
13
|
+
while (true) {
|
|
14
|
+
const elementParserContext = parserContext.lookahead();
|
|
15
|
+
const initialPosition = elementParserContext.position;
|
|
16
|
+
try {
|
|
17
|
+
const element = await parser(elementParserContext);
|
|
18
|
+
if (elementParserContext.position === initialPosition) {
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
elements.push(element);
|
|
22
|
+
elementParserContext.unlookahead();
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
if (error instanceof ParserParsingFailedError) {
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
elementParserContext.dispose();
|
|
32
|
+
}
|
|
33
|
+
parser = separatorThenElementParser;
|
|
34
|
+
}
|
|
35
|
+
return elements;
|
|
36
|
+
};
|
|
37
|
+
setParserName(separatedArrayParser, getParserName(elementParser, 'anonymousSeparatedArrayChild') + '*');
|
|
38
|
+
return separatedArrayParser;
|
|
39
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import { testProp, fc } from '@fast-check/ava';
|
|
3
|
+
import { createSeparatedArrayParser } from './separatedArrayParser.js';
|
|
4
|
+
import { runParser, runParserWithRemainingInput } from './parser.js';
|
|
5
|
+
import { stringParserInputCompanion } from './parserInputCompanion.js';
|
|
6
|
+
import { createExactSequenceParser } from './exactSequenceParser.js';
|
|
7
|
+
test('does not loop forever with a child parser that does not consume anything', async (t) => {
|
|
8
|
+
const parser = createSeparatedArrayParser(async () => undefined, () => undefined);
|
|
9
|
+
const { output } = await runParserWithRemainingInput(parser, 'foo', stringParserInputCompanion);
|
|
10
|
+
t.deepEqual(output, []);
|
|
11
|
+
});
|
|
12
|
+
testProp('separatedArray', [
|
|
13
|
+
fc.array(fc.constant('element')),
|
|
14
|
+
], async (t, elements) => {
|
|
15
|
+
const separatedArrayParser = createSeparatedArrayParser(createExactSequenceParser('element'), createExactSequenceParser('separator'));
|
|
16
|
+
const actual = await runParser(separatedArrayParser, elements.join('separator'), stringParserInputCompanion);
|
|
17
|
+
const expected = elements;
|
|
18
|
+
t.deepEqual(actual, expected);
|
|
19
|
+
}, {
|
|
20
|
+
verbose: true,
|
|
21
|
+
});
|