@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
|
@@ -1,50 +1,120 @@
|
|
|
1
1
|
import test from 'ava';
|
|
2
2
|
import { SequenceBufferImplementation } from './sequenceBuffer.js';
|
|
3
|
-
import {
|
|
3
|
+
import { stringParserInputCompanion } from './parserInputCompanion.js';
|
|
4
4
|
|
|
5
5
|
test('sequenceBuffer', t => {
|
|
6
|
-
const sequenceBuffer = new SequenceBufferImplementation(
|
|
6
|
+
const sequenceBuffer = new SequenceBufferImplementation(stringParserInputCompanion);
|
|
7
7
|
|
|
8
|
+
t.is(sequenceBuffer.length, 0);
|
|
8
9
|
t.is(sequenceBuffer.peek(0), undefined);
|
|
9
10
|
|
|
11
|
+
t.deepEqual(sequenceBuffer.toSequenceBufferState(), {
|
|
12
|
+
consumedBufferedSequences: [],
|
|
13
|
+
unconsumedBufferedSequences: [],
|
|
14
|
+
});
|
|
15
|
+
|
|
10
16
|
sequenceBuffer.push('');
|
|
11
17
|
|
|
18
|
+
t.is(sequenceBuffer.length, 0);
|
|
12
19
|
t.is(sequenceBuffer.peek(0), undefined);
|
|
13
20
|
|
|
21
|
+
t.deepEqual(sequenceBuffer.toSequenceBufferState(), {
|
|
22
|
+
consumedBufferedSequences: [],
|
|
23
|
+
unconsumedBufferedSequences: [],
|
|
24
|
+
});
|
|
25
|
+
|
|
14
26
|
sequenceBuffer.push('abc');
|
|
15
27
|
|
|
28
|
+
t.is(sequenceBuffer.length, 3);
|
|
16
29
|
t.is(sequenceBuffer.peek(0), 'a');
|
|
17
30
|
t.is(sequenceBuffer.peek(1), 'b');
|
|
18
31
|
t.is(sequenceBuffer.peek(2), 'c');
|
|
19
32
|
t.is(sequenceBuffer.peek(3), undefined);
|
|
20
33
|
|
|
34
|
+
t.deepEqual(sequenceBuffer.toSequenceBufferState(), {
|
|
35
|
+
consumedBufferedSequences: [],
|
|
36
|
+
unconsumedBufferedSequences: ['abc'],
|
|
37
|
+
});
|
|
38
|
+
|
|
21
39
|
sequenceBuffer.push('def');
|
|
22
40
|
|
|
41
|
+
t.is(sequenceBuffer.length, 6);
|
|
23
42
|
t.is(sequenceBuffer.peek(0), 'a');
|
|
24
43
|
t.is(sequenceBuffer.peek(3), 'd');
|
|
25
44
|
t.is(sequenceBuffer.peek(6), undefined);
|
|
26
45
|
|
|
46
|
+
t.is(sequenceBuffer.peekSequence(1, 4), 'abcdef'.slice(1, 4), 'bcd');
|
|
47
|
+
t.is(sequenceBuffer.peekSequence(1, 5), 'abcdef'.slice(1, 5), 'bcde');
|
|
48
|
+
t.is(sequenceBuffer.peekSequence(1, 6), 'abcdef'.slice(1, 6), 'bcdef');
|
|
49
|
+
t.is(sequenceBuffer.peekSequence(1, 7), undefined, 'bcdef?');
|
|
50
|
+
|
|
51
|
+
t.deepEqual(sequenceBuffer.toSequenceBufferState(), {
|
|
52
|
+
consumedBufferedSequences: [],
|
|
53
|
+
unconsumedBufferedSequences: ['abc', 'def'],
|
|
54
|
+
});
|
|
55
|
+
|
|
27
56
|
sequenceBuffer.push('');
|
|
28
57
|
|
|
58
|
+
t.is(sequenceBuffer.length, 6);
|
|
29
59
|
t.is(sequenceBuffer.peek(0), 'a');
|
|
30
60
|
t.is(sequenceBuffer.peek(3), 'd');
|
|
31
61
|
t.is(sequenceBuffer.peek(6), undefined);
|
|
32
62
|
|
|
63
|
+
t.deepEqual(sequenceBuffer.toSequenceBufferState(), {
|
|
64
|
+
consumedBufferedSequences: [],
|
|
65
|
+
unconsumedBufferedSequences: ['abc', 'def', ''],
|
|
66
|
+
});
|
|
67
|
+
|
|
33
68
|
sequenceBuffer.skip(1);
|
|
34
69
|
|
|
70
|
+
t.is(sequenceBuffer.length, 5);
|
|
35
71
|
t.is(sequenceBuffer.peek(0), 'b');
|
|
36
72
|
t.is(sequenceBuffer.peek(3), 'e');
|
|
37
73
|
t.is(sequenceBuffer.peek(5), undefined);
|
|
38
74
|
|
|
75
|
+
t.deepEqual(sequenceBuffer.toSequenceBufferState(), {
|
|
76
|
+
consumedBufferedSequences: ['a'],
|
|
77
|
+
unconsumedBufferedSequences: ['bc', 'def', ''],
|
|
78
|
+
});
|
|
79
|
+
|
|
39
80
|
sequenceBuffer.skip(3);
|
|
40
81
|
|
|
82
|
+
t.is(sequenceBuffer.length, 2);
|
|
41
83
|
t.is(sequenceBuffer.peek(0), 'e');
|
|
42
84
|
t.is(sequenceBuffer.peek(2), undefined);
|
|
43
85
|
|
|
86
|
+
t.deepEqual(sequenceBuffer.toSequenceBufferState(), {
|
|
87
|
+
consumedBufferedSequences: ['d'],
|
|
88
|
+
unconsumedBufferedSequences: ['ef', ''],
|
|
89
|
+
});
|
|
90
|
+
|
|
44
91
|
sequenceBuffer.push('gh');
|
|
45
92
|
|
|
93
|
+
t.is(sequenceBuffer.length, 4);
|
|
46
94
|
t.is(sequenceBuffer.peek(0), 'e');
|
|
47
95
|
t.is(sequenceBuffer.peek(2), 'g');
|
|
48
96
|
t.is(sequenceBuffer.peek(3), 'h');
|
|
49
97
|
t.is(sequenceBuffer.peek(4), undefined);
|
|
98
|
+
|
|
99
|
+
t.is(sequenceBuffer.peekSequence(1, 3), 'efgh'.slice(1, 3), 'fg');
|
|
100
|
+
t.is(sequenceBuffer.peekSequence(1, 4), 'efgh'.slice(1, 4), 'fgh');
|
|
101
|
+
t.is(sequenceBuffer.peekSequence(1, 5), undefined, 'fgh?');
|
|
102
|
+
|
|
103
|
+
t.deepEqual(sequenceBuffer.toSequenceBufferState(), {
|
|
104
|
+
consumedBufferedSequences: ['d'],
|
|
105
|
+
unconsumedBufferedSequences: ['ef', '', 'gh'],
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('skip more then first sequence length', t => {
|
|
110
|
+
const sequenceBuffer = new SequenceBufferImplementation(stringParserInputCompanion);
|
|
111
|
+
|
|
112
|
+
sequenceBuffer.push('a');
|
|
113
|
+
sequenceBuffer.push('b');
|
|
114
|
+
sequenceBuffer.skip(2);
|
|
115
|
+
|
|
116
|
+
t.deepEqual(sequenceBuffer.toSequenceBufferState(), {
|
|
117
|
+
consumedBufferedSequences: [],
|
|
118
|
+
unconsumedBufferedSequences: [],
|
|
119
|
+
});
|
|
50
120
|
});
|
package/src/sequenceBuffer.ts
CHANGED
|
@@ -1,24 +1,37 @@
|
|
|
1
1
|
import invariant from 'invariant';
|
|
2
|
-
import { type
|
|
2
|
+
import { type ParserInputCompanion } from './parserInputCompanion.js';
|
|
3
|
+
|
|
4
|
+
export type SequenceBufferState<Sequence> = {
|
|
5
|
+
consumedBufferedSequences: Sequence[];
|
|
6
|
+
unconsumedBufferedSequences: Sequence[];
|
|
7
|
+
};
|
|
3
8
|
|
|
4
9
|
export type SequenceBuffer<Sequence, Element> = {
|
|
5
10
|
push(sequence: Sequence): void;
|
|
6
11
|
peek(offset: number): Element | undefined;
|
|
12
|
+
peekSequence(start: number, end: number): Sequence | undefined;
|
|
7
13
|
skip(offset: number): void;
|
|
14
|
+
|
|
15
|
+
toSequenceBufferState(): SequenceBufferState<Sequence>;
|
|
8
16
|
};
|
|
9
17
|
|
|
10
18
|
export class SequenceBufferImplementation<Sequence, Element> implements SequenceBuffer<Sequence, Element> {
|
|
11
19
|
private readonly _sequences: Sequence[] = [];
|
|
12
20
|
private _indexInFirstSequence = 0;
|
|
13
21
|
|
|
14
|
-
constructor(private readonly
|
|
22
|
+
constructor(private readonly _parserInputCompanion: ParserInputCompanion<Sequence, Element>) {}
|
|
15
23
|
|
|
16
|
-
|
|
17
|
-
this._sequences.
|
|
24
|
+
get length() {
|
|
25
|
+
return this._sequences.reduce(
|
|
26
|
+
(sequenceLength, sequence) => sequenceLength + this._parserInputCompanion.length(sequence),
|
|
27
|
+
0 - this._indexInFirstSequence,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
18
30
|
|
|
31
|
+
private _shift() {
|
|
19
32
|
while (this._sequences.length > 0) {
|
|
20
33
|
const firstSequence = this._sequences[0];
|
|
21
|
-
const firstSequenceLength = this.
|
|
34
|
+
const firstSequenceLength = this._parserInputCompanion.length(firstSequence);
|
|
22
35
|
|
|
23
36
|
if (firstSequenceLength === 0) {
|
|
24
37
|
this._sequences.shift();
|
|
@@ -34,16 +47,22 @@ export class SequenceBufferImplementation<Sequence, Element> implements Sequence
|
|
|
34
47
|
}
|
|
35
48
|
}
|
|
36
49
|
|
|
50
|
+
push(sequence: Sequence) {
|
|
51
|
+
this._sequences.push(sequence);
|
|
52
|
+
|
|
53
|
+
this._shift();
|
|
54
|
+
}
|
|
55
|
+
|
|
37
56
|
peek(offset: number): Element | undefined {
|
|
38
57
|
invariant(offset >= 0, 'Offset must be non-negative.');
|
|
39
58
|
|
|
40
59
|
let index = this._indexInFirstSequence + offset;
|
|
41
60
|
|
|
42
61
|
for (const sequence of this._sequences) {
|
|
43
|
-
const sequenceLength = this.
|
|
62
|
+
const sequenceLength = this._parserInputCompanion.length(sequence);
|
|
44
63
|
|
|
45
64
|
if (index < sequenceLength) {
|
|
46
|
-
return this.
|
|
65
|
+
return this._parserInputCompanion.at(sequence, index);
|
|
47
66
|
}
|
|
48
67
|
|
|
49
68
|
index -= sequenceLength;
|
|
@@ -52,7 +71,74 @@ export class SequenceBufferImplementation<Sequence, Element> implements Sequence
|
|
|
52
71
|
return undefined;
|
|
53
72
|
}
|
|
54
73
|
|
|
74
|
+
peekSequence(start: number, end: number): Sequence | undefined {
|
|
75
|
+
invariant(start >= 0, 'Start must be non-negative.');
|
|
76
|
+
invariant(end >= start, 'End must be greater than or equal to start.');
|
|
77
|
+
|
|
78
|
+
let startIndex = this._indexInFirstSequence + start;
|
|
79
|
+
let endIndex = this._indexInFirstSequence + end;
|
|
80
|
+
|
|
81
|
+
const sequences: Sequence[] = [];
|
|
82
|
+
|
|
83
|
+
for (const sequence of this._sequences) {
|
|
84
|
+
const sequenceLength = this._parserInputCompanion.length(sequence);
|
|
85
|
+
|
|
86
|
+
if (startIndex < sequenceLength) {
|
|
87
|
+
const subsequence = this._parserInputCompanion.subsequence(
|
|
88
|
+
sequence,
|
|
89
|
+
Math.max(0, startIndex),
|
|
90
|
+
Math.min(sequenceLength, endIndex),
|
|
91
|
+
)
|
|
92
|
+
sequences.push(subsequence);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
startIndex -= sequenceLength;
|
|
96
|
+
endIndex -= sequenceLength;
|
|
97
|
+
|
|
98
|
+
if (endIndex <= 0) {
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return endIndex > 0 ? undefined : this._parserInputCompanion.concat(sequences);
|
|
104
|
+
}
|
|
105
|
+
|
|
55
106
|
skip(offset: number) {
|
|
56
107
|
this._indexInFirstSequence += offset;
|
|
108
|
+
|
|
109
|
+
this._shift();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
toSequenceBufferState(): SequenceBufferState<Sequence> {
|
|
113
|
+
if (this._sequences.length === 0) {
|
|
114
|
+
return {
|
|
115
|
+
consumedBufferedSequences: [],
|
|
116
|
+
unconsumedBufferedSequences: [],
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (this._indexInFirstSequence === 0) {
|
|
121
|
+
return {
|
|
122
|
+
consumedBufferedSequences: [],
|
|
123
|
+
unconsumedBufferedSequences: this._sequences.slice(),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const firstSequence = this._sequences[0];
|
|
128
|
+
const firstSequenceLength = this._parserInputCompanion.length(firstSequence);
|
|
129
|
+
|
|
130
|
+
const consumedFirstSequence = this._parserInputCompanion.subsequence(firstSequence, 0, this._indexInFirstSequence);
|
|
131
|
+
const unconsumedFirstSequence = this._parserInputCompanion.subsequence(firstSequence, this._indexInFirstSequence, firstSequenceLength);
|
|
132
|
+
|
|
133
|
+
const unconsumedFirstSequenceLength = this._parserInputCompanion.length(unconsumedFirstSequence);
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
consumedBufferedSequences: [consumedFirstSequence],
|
|
137
|
+
unconsumedBufferedSequences: (
|
|
138
|
+
unconsumedFirstSequenceLength === 0
|
|
139
|
+
? this._sequences.slice(1)
|
|
140
|
+
: [unconsumedFirstSequence, ...this._sequences.slice(1)]
|
|
141
|
+
),
|
|
142
|
+
};
|
|
57
143
|
}
|
|
58
144
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as fc from 'fast-check';
|
|
2
|
+
import { testProp } from '@fast-check/ava';
|
|
3
|
+
import { Parser, runParser } from './parser.js';
|
|
4
|
+
import { stringParserInputCompanion } from './parserInputCompanion.js';
|
|
5
|
+
import { createSequenceTerminatedSequenceParser } from './sequenceTerminatedSequenceParser.js';
|
|
6
|
+
|
|
7
|
+
testProp.serial(
|
|
8
|
+
'sequenceTerminatedSequenceParser',
|
|
9
|
+
[
|
|
10
|
+
fc.tuple(
|
|
11
|
+
fc
|
|
12
|
+
.string({
|
|
13
|
+
minLength: 1,
|
|
14
|
+
}),
|
|
15
|
+
fc
|
|
16
|
+
.integer({
|
|
17
|
+
min: 1,
|
|
18
|
+
}),
|
|
19
|
+
)
|
|
20
|
+
.map(([ string, terminatorLength ]) => ({
|
|
21
|
+
string,
|
|
22
|
+
terminator: string.slice(-terminatorLength),
|
|
23
|
+
}))
|
|
24
|
+
.filter(({ string, terminator }) => string.split(terminator).length === 2)
|
|
25
|
+
],
|
|
26
|
+
async (t, { string, terminator }) => {
|
|
27
|
+
const sequenceTerminatedSequenceParser = createSequenceTerminatedSequenceParser<string>(
|
|
28
|
+
terminator,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const createTestWrapperParser = (innerParser: typeof sequenceTerminatedSequenceParser): Parser<{
|
|
32
|
+
string: string;
|
|
33
|
+
nextPeek: string | undefined;
|
|
34
|
+
position: number;
|
|
35
|
+
}, string> => async parserContext => {
|
|
36
|
+
const string = await innerParser(parserContext);
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
string,
|
|
40
|
+
nextPeek: await parserContext.peek(0),
|
|
41
|
+
position: parserContext.position,
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const actual = await runParser(
|
|
46
|
+
createTestWrapperParser(sequenceTerminatedSequenceParser),
|
|
47
|
+
string,
|
|
48
|
+
stringParserInputCompanion,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
t.deepEqual(actual, {
|
|
52
|
+
string: string.split(terminator)[0],
|
|
53
|
+
nextPeek: undefined,
|
|
54
|
+
position: string.length,
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
verbose: true,
|
|
59
|
+
},
|
|
60
|
+
);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { inspect } from "./inspect.js";
|
|
2
|
+
import { Parser, setParserName } from "./parser.js";
|
|
3
|
+
import { DeriveSequenceElement } from "./sequence.js";
|
|
4
|
+
|
|
5
|
+
function clamp(x: number, min: number, max: number) {
|
|
6
|
+
return Math.max(min, Math.min(x, max));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const createSequenceTerminatedSequenceParser = <Sequence, Element = DeriveSequenceElement<Sequence>>(
|
|
10
|
+
terminatorSequence: Sequence,
|
|
11
|
+
{
|
|
12
|
+
consumeTerminator = true,
|
|
13
|
+
}: {
|
|
14
|
+
consumeTerminator?: boolean;
|
|
15
|
+
} = {},
|
|
16
|
+
): Parser<Sequence, Sequence, Element> => {
|
|
17
|
+
const elementTerminatedSequenceParser: Parser<Sequence, Sequence, Element> = async parserContext => {
|
|
18
|
+
let window = 1;
|
|
19
|
+
let nonEndOfInputWindow = 0;
|
|
20
|
+
|
|
21
|
+
while (true) {
|
|
22
|
+
const sequence = await parserContext.peekSequence(0, window);
|
|
23
|
+
|
|
24
|
+
if (sequence === undefined) {
|
|
25
|
+
window = clamp(
|
|
26
|
+
Math.floor(window * 0.75),
|
|
27
|
+
nonEndOfInputWindow + 1,
|
|
28
|
+
window - 1,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
parserContext.invariant(
|
|
32
|
+
window !== nonEndOfInputWindow,
|
|
33
|
+
'Unexpected end of input without terminated sequence',
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
nonEndOfInputWindow = Math.max(window, nonEndOfInputWindow);
|
|
40
|
+
|
|
41
|
+
const terminatorIndex = parserContext.indexOfSubsequence(sequence, terminatorSequence);
|
|
42
|
+
|
|
43
|
+
if (terminatorIndex === -1) {
|
|
44
|
+
window = window * 2;
|
|
45
|
+
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const sequence_ = await parserContext.readSequence(0, terminatorIndex);
|
|
50
|
+
|
|
51
|
+
if (consumeTerminator) {
|
|
52
|
+
parserContext.skip(parserContext.length(terminatorSequence));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return sequence_;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
setParserName(elementTerminatedSequenceParser, `.*?${inspect(terminatorSequence)}`);
|
|
60
|
+
|
|
61
|
+
return elementTerminatedSequenceParser;
|
|
62
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Unparser } from "./unparser.js";
|
|
2
|
+
|
|
3
|
+
export const createSequenceUnparser = <Sequence>(): Unparser<Sequence, Sequence> => {
|
|
4
|
+
const sequenceUnparser: Unparser<Sequence, Sequence> = async function * (input) {
|
|
5
|
+
yield input;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
return sequenceUnparser;
|
|
9
|
+
}
|
package/src/skipParser.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { type Parser } from './parser.js';
|
|
1
|
+
import { setParserName, type Parser } from './parser.js';
|
|
2
2
|
import { parserImplementationInvariant } from './parserImplementationInvariant.js';
|
|
3
3
|
|
|
4
|
-
export const createSkipParser = <Sequence>(length: number): Parser<
|
|
4
|
+
export const createSkipParser = <Sequence>(length: number): Parser<void, Sequence, unknown> => {
|
|
5
5
|
parserImplementationInvariant(length > 0, 'Length must be positive.');
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const skipParser: Parser<void, Sequence, unknown> = parserContext => {
|
|
8
8
|
parserContext.skip(length);
|
|
9
|
-
|
|
10
|
-
return undefined;
|
|
11
9
|
};
|
|
10
|
+
|
|
11
|
+
setParserName(skipParser, `createSkipParser(${length})`);
|
|
12
|
+
|
|
13
|
+
return skipParser;
|
|
12
14
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Parser, setParserName } from "./parser.js";
|
|
2
|
+
import { parserImplementationInvariant } from './parserImplementationInvariant.js';
|
|
3
|
+
|
|
4
|
+
export const createSkipToParser = (offset: number): Parser<void, Uint8Array> => {
|
|
5
|
+
const skipToParser: Parser<void, Uint8Array> = (parserContext) => {
|
|
6
|
+
const length = offset - parserContext.position;
|
|
7
|
+
|
|
8
|
+
parserImplementationInvariant(length >= 0, 'Skip length must be positive, got %s (position: %s)', length, parserContext.position);
|
|
9
|
+
|
|
10
|
+
parserContext.skip(length);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
setParserName(skipToParser, `createSkipToParser(${offset})`);
|
|
14
|
+
|
|
15
|
+
return skipToParser;
|
|
16
|
+
};
|
|
@@ -3,8 +3,19 @@ import { createArrayParser } from './arrayParser.js';
|
|
|
3
3
|
import { createElementParser } from './elementParser.js';
|
|
4
4
|
import { createTupleParser } from './tupleParser.js';
|
|
5
5
|
import { createSliceBoundedParser } from './sliceBoundedParser.js';
|
|
6
|
-
import { runParser } from './parser.js';
|
|
7
|
-
import {
|
|
6
|
+
import { runParser, runParserWithRemainingInput } from './parser.js';
|
|
7
|
+
import { stringParserInputCompanion } from './parserInputCompanion.js';
|
|
8
|
+
import { createExactElementParser } from './exactElementParser.js';
|
|
9
|
+
|
|
10
|
+
async function stringFromAsyncIterable(asyncIterable: AsyncIterable<string>) {
|
|
11
|
+
let string = '';
|
|
12
|
+
|
|
13
|
+
for await (const chunk of asyncIterable) {
|
|
14
|
+
string += chunk;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return string;
|
|
18
|
+
}
|
|
8
19
|
|
|
9
20
|
const anythingParser = createArrayParser(createElementParser<string>());
|
|
10
21
|
|
|
@@ -15,7 +26,7 @@ test('sliceBoundedParser', async t => {
|
|
|
15
26
|
createElementParser(),
|
|
16
27
|
]);
|
|
17
28
|
|
|
18
|
-
const result = await runParser(parser, 'abba',
|
|
29
|
+
const result = await runParser(parser, 'abba', stringParserInputCompanion);
|
|
19
30
|
|
|
20
31
|
t.deepEqual(result, [
|
|
21
32
|
'a',
|
|
@@ -26,3 +37,34 @@ test('sliceBoundedParser', async t => {
|
|
|
26
37
|
'a',
|
|
27
38
|
]);
|
|
28
39
|
});
|
|
40
|
+
|
|
41
|
+
test('sliceBoundedParser mustConsumeAll: true fail to cosume all', async t => {
|
|
42
|
+
const parser = createTupleParser([
|
|
43
|
+
createElementParser<string>(),
|
|
44
|
+
createSliceBoundedParser(createArrayParser(createExactElementParser('b' as string)), 2),
|
|
45
|
+
createElementParser(),
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
await t.throwsAsync(() => runParser(parser, 'abcd', stringParserInputCompanion), {
|
|
49
|
+
message: /child parser must consume all input in the slice/,
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('sliceBoundedParser mustConsumeAll: false', async t => {
|
|
54
|
+
const parser = createTupleParser([
|
|
55
|
+
createElementParser<string>(),
|
|
56
|
+
createSliceBoundedParser(createArrayParser(createExactElementParser('b' as string)), 2, false),
|
|
57
|
+
createElementParser(),
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
const { output, remainingInput } = await runParserWithRemainingInput(parser, 'abcd', stringParserInputCompanion);
|
|
61
|
+
|
|
62
|
+
t.deepEqual(output, [
|
|
63
|
+
'a',
|
|
64
|
+
[
|
|
65
|
+
'b',
|
|
66
|
+
],
|
|
67
|
+
'c',
|
|
68
|
+
]);
|
|
69
|
+
t.deepEqual(await stringFromAsyncIterable(remainingInput!), 'd');
|
|
70
|
+
});
|
|
@@ -1,16 +1,32 @@
|
|
|
1
|
-
import { getParserName, Parser, setParserName } from
|
|
1
|
+
import { getParserName, type Parser, setParserName } from './parser.js';
|
|
2
2
|
|
|
3
3
|
export const createSliceBoundedParser = <Output, Sequence>(
|
|
4
4
|
childParser: Parser<Output, Sequence>,
|
|
5
5
|
sliceEnd: number,
|
|
6
|
+
mustConsumeAll: boolean = true,
|
|
6
7
|
): Parser<Output, Sequence> => {
|
|
7
8
|
const sliceBoundedParser: typeof childParser = async parserContext => {
|
|
9
|
+
const absoluteSliceEnd = parserContext.position + sliceEnd;
|
|
10
|
+
|
|
8
11
|
const childParserContext = parserContext.lookahead({
|
|
9
|
-
sliceEnd:
|
|
12
|
+
sliceEnd: absoluteSliceEnd,
|
|
10
13
|
});
|
|
11
14
|
|
|
12
15
|
try {
|
|
13
16
|
const value = await childParser(childParserContext);
|
|
17
|
+
|
|
18
|
+
childParserContext.invariant(
|
|
19
|
+
(
|
|
20
|
+
!mustConsumeAll
|
|
21
|
+
|| childParserContext.position === absoluteSliceEnd
|
|
22
|
+
),
|
|
23
|
+
'child parser must consume all input in the slice (%s in total, up to position %s), instead consumed %s up to position %s',
|
|
24
|
+
sliceEnd,
|
|
25
|
+
absoluteSliceEnd,
|
|
26
|
+
childParserContext.position - parserContext.position,
|
|
27
|
+
childParserContext.position,
|
|
28
|
+
);
|
|
29
|
+
|
|
14
30
|
childParserContext.unlookahead();
|
|
15
31
|
return value;
|
|
16
32
|
} finally {
|
|
@@ -23,8 +39,10 @@ export const createSliceBoundedParser = <Output, Sequence>(
|
|
|
23
39
|
getParserName(childParser, 'anonymousSliceBoundedChild'),
|
|
24
40
|
',',
|
|
25
41
|
sliceEnd,
|
|
42
|
+
',',
|
|
43
|
+
mustConsumeAll,
|
|
26
44
|
')',
|
|
27
45
|
].join(''));
|
|
28
46
|
|
|
29
47
|
return sliceBoundedParser;
|
|
30
|
-
}
|
|
48
|
+
};
|
package/src/smali.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { execa } from 'execa';
|
|
3
|
+
import { temporaryFile } from 'tempy';
|
|
4
|
+
|
|
5
|
+
export async function smaliClass(smaliStream: AsyncIterable<string>) {
|
|
6
|
+
const inputFilePath = temporaryFile();
|
|
7
|
+
const outputFilePath = temporaryFile();
|
|
8
|
+
|
|
9
|
+
await fs.writeFile(inputFilePath, smaliStream);
|
|
10
|
+
|
|
11
|
+
await execa('smali', [
|
|
12
|
+
'assemble',
|
|
13
|
+
'--output', outputFilePath,
|
|
14
|
+
inputFilePath,
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
await fs.unlink(inputFilePath);
|
|
18
|
+
|
|
19
|
+
const dex = await fs.readFile(outputFilePath);
|
|
20
|
+
|
|
21
|
+
await fs.unlink(outputFilePath);
|
|
22
|
+
|
|
23
|
+
return dex;
|
|
24
|
+
}
|