@futpib/parser 1.0.2 → 1.0.4
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/.github/copilot-instructions.md +149 -0
- package/.github/workflows/copilot-setup-steps.yml +18 -0
- package/.github/workflows/main.yml +29 -8
- package/.yarn/releases/yarn-4.9.4.cjs +942 -0
- package/.yarnrc.yml +1 -1
- package/build/allSettledStream.js +1 -1
- package/build/allSettledStream.test.js +2 -2
- package/build/androidPackageParser.d.ts +1 -1
- package/build/androidPackageParser.js +5 -3
- package/build/androidPackageParser.test.js +7 -7
- package/build/androidPackageUnparser.d.ts +2 -2
- package/build/androidPackageUnparser.js +18 -14
- package/build/androidPackageUnparser.test.js +7 -7
- package/build/arbitrarilySlicedAsyncInterator.js +2 -1
- package/build/arbitraryDalvikBytecode.d.ts +4 -0
- package/build/arbitraryDalvikBytecode.js +640 -0
- package/build/arbitraryDalvikExecutable.d.ts +3 -0
- package/build/arbitraryDalvikExecutable.js +282 -0
- package/build/arbitraryDosDateTime.js +1 -0
- package/build/arbitraryZipStream.js +1 -1
- package/build/arrayParser.js +2 -2
- package/build/arrayUnparser.d.ts +1 -1
- package/build/backsmali.d.ts +3 -1
- package/build/backsmali.js +31 -3
- package/build/bash.d.ts +84 -0
- package/build/bash.js +1 -0
- package/build/bashParser.d.ts +6 -0
- package/build/bashParser.js +294 -0
- package/build/bashParser.test.d.ts +1 -0
- package/build/bashParser.test.js +181 -0
- package/build/customInvariant.d.ts +2 -1
- package/build/customInvariant.js +4 -6
- package/build/dalvikBytecodeParser/formatParsers.d.ts +76 -2
- package/build/dalvikBytecodeParser/formatParsers.js +146 -11
- package/build/dalvikBytecodeParser/formatSizes.d.ts +34 -0
- package/build/dalvikBytecodeParser/formatSizes.js +34 -0
- package/build/dalvikBytecodeParser/operationFormats.d.ts +225 -0
- package/build/dalvikBytecodeParser/operationFormats.js +225 -0
- package/build/dalvikBytecodeParser.d.ts +1105 -5
- package/build/dalvikBytecodeParser.js +658 -205
- package/build/dalvikBytecodeUnparser/formatUnparsers.d.ts +152 -0
- package/build/dalvikBytecodeUnparser/formatUnparsers.js +225 -0
- package/build/dalvikBytecodeUnparser.d.ts +3 -0
- package/build/dalvikBytecodeUnparser.js +642 -0
- package/build/dalvikBytecodeUnparser.test.d.ts +1 -0
- package/build/dalvikBytecodeUnparser.test.js +25 -0
- package/build/dalvikExecutable.d.ts +65 -8
- package/build/dalvikExecutable.js +36 -0
- package/build/dalvikExecutableParser/stringSyntaxParser.d.ts +1 -1
- package/build/dalvikExecutableParser/stringSyntaxParser.js +17 -17
- package/build/dalvikExecutableParser/typeParsers.d.ts +2 -1
- package/build/dalvikExecutableParser/typeParsers.js +16 -11
- package/build/dalvikExecutableParser/typedNumbers.d.ts +85 -69
- package/build/dalvikExecutableParser/typedNumbers.js +0 -1
- package/build/dalvikExecutableParser.d.ts +2 -2
- package/build/dalvikExecutableParser.js +655 -337
- package/build/dalvikExecutableParser.test.js +24 -22
- package/build/dalvikExecutableParserAgainstSmaliParser.test.js +223 -246
- package/build/dalvikExecutableUnparser/annotationUnparsers.d.ts +14 -0
- package/build/dalvikExecutableUnparser/annotationUnparsers.js +97 -0
- package/build/dalvikExecutableUnparser/poolBuilders.d.ts +49 -0
- package/build/dalvikExecutableUnparser/poolBuilders.js +140 -0
- package/build/dalvikExecutableUnparser/poolScanners.d.ts +4 -0
- package/build/dalvikExecutableUnparser/poolScanners.js +220 -0
- package/build/dalvikExecutableUnparser/sectionUnparsers.d.ts +25 -0
- package/build/dalvikExecutableUnparser/sectionUnparsers.js +581 -0
- package/build/dalvikExecutableUnparser/utils.d.ts +10 -0
- package/build/dalvikExecutableUnparser/utils.js +108 -0
- package/build/dalvikExecutableUnparser.d.ts +4 -0
- package/build/dalvikExecutableUnparser.js +406 -0
- package/build/dalvikExecutableUnparser.test.d.ts +1 -0
- package/build/dalvikExecutableUnparser.test.js +31 -0
- package/build/debugLogInputParser.js +1 -1
- package/build/disjunctionParser.d.ts +2 -2
- package/build/disjunctionParser.js +2 -2
- package/build/elementTerminatedArrayParser.d.ts +2 -2
- package/build/elementTerminatedArrayParser.js +1 -1
- package/build/elementTerminatedArrayParser.test.js +5 -5
- package/build/elementTerminatedSequenceArrayParser.d.ts +2 -2
- package/build/elementTerminatedSequenceArrayParser.js +1 -1
- package/build/elementTerminatedSequenceArrayParser.test.js +2 -2
- package/build/elementTerminatedSequenceParser.d.ts +2 -2
- package/build/elementTerminatedSequenceParser.js +1 -1
- package/build/elementTerminatedSequenceParser.test.js +2 -2
- package/build/endOfInputParser.d.ts +1 -1
- package/build/exactElementSwitchParser.d.ts +3 -0
- package/build/exactElementSwitchParser.js +22 -0
- package/build/fetchCid.js +2 -6
- package/build/fetchCid.test.d.ts +1 -0
- package/build/fetchCid.test.js +16 -0
- package/build/fixedLengthSequenceParser.test.js +2 -2
- package/build/hasExecutable.js +2 -2
- package/build/highResolutionTimer.js +1 -1
- package/build/index.d.ts +24 -2
- package/build/index.js +22 -1
- package/build/inputReader.d.ts +1 -1
- package/build/inputReader.test.js +33 -45
- package/build/javaKeyStoreParser.test.js +6 -6
- package/build/jsonParser.js +8 -8
- package/build/lazyMessageError.d.ts +48 -0
- package/build/lazyMessageError.js +53 -0
- package/build/lazyMessageError.test.d.ts +1 -0
- package/build/lazyMessageError.test.js +15 -0
- package/build/leb128Parser.d.ts +1 -1
- package/build/leb128Parser.js +10 -10
- package/build/leb128Parser.test.js +7 -7
- package/build/negativeLookaheadParser.js +2 -2
- package/build/negativeLookaheadParser.test.js +4 -4
- package/build/noStackCaptureOverheadError.d.ts +4 -0
- package/build/noStackCaptureOverheadError.js +9 -0
- package/build/noStackCaptureOverheadError.test.d.ts +1 -0
- package/build/noStackCaptureOverheadError.test.js +15 -0
- package/build/nonEmptyArrayParser.js +2 -2
- package/build/nonEmptyArrayParser.test.js +2 -1
- package/build/optionalParser.js +2 -2
- package/build/parser.d.ts +2 -1
- package/build/parser.js +23 -8
- package/build/parser.test.js +78 -29
- package/build/parserConsumedSequenceParser.d.ts +1 -1
- package/build/parserConsumedSequenceParser.js +2 -2
- package/build/parserContext.d.ts +8 -6
- package/build/parserContext.js +60 -33
- package/build/parserContext.test.js +7 -3
- package/build/parserError.d.ts +603 -44
- package/build/parserError.js +98 -53
- package/build/parserImplementationInvariant.d.ts +1 -1
- package/build/parserImplementationInvariant.js +2 -2
- package/build/parserInputCompanion.js +2 -2
- package/build/promiseCompose.js +1 -2
- package/build/regexpParser.d.ts +2 -0
- package/build/regexpParser.js +71 -0
- package/build/regexpParser.test.d.ts +1 -0
- package/build/regexpParser.test.js +83 -0
- package/build/regularExpression.d.ts +63 -0
- package/build/regularExpression.js +1 -0
- package/build/regularExpressionParser.d.ts +3 -0
- package/build/regularExpressionParser.js +580 -0
- package/build/regularExpressionParser.test.d.ts +1 -0
- package/build/regularExpressionParser.test.js +89 -0
- package/build/separatedArrayParser.js +2 -2
- package/build/separatedNonEmptyArrayParser.d.ts +2 -0
- package/build/separatedNonEmptyArrayParser.js +40 -0
- package/build/separatedNonEmptyArrayParser.test.d.ts +1 -0
- package/build/separatedNonEmptyArrayParser.test.js +66 -0
- package/build/sequenceBuffer.js +1 -1
- package/build/sequenceTerminatedSequenceParser.d.ts +2 -2
- package/build/sequenceTerminatedSequenceParser.js +3 -3
- package/build/sequenceTerminatedSequenceParser.test.js +1 -1
- package/build/sequenceUnparser.d.ts +1 -1
- package/build/skipToParser.d.ts +1 -1
- package/build/skipToParser.js +2 -2
- package/build/sliceBoundedParser.test.js +4 -9
- package/build/smali.d.ts +1 -1
- package/build/smali.js +6 -2
- package/build/smaliParser.d.ts +62 -6
- package/build/smaliParser.js +1721 -296
- package/build/smaliParser.test.js +338 -43
- package/build/stringFromAsyncIterable.d.ts +1 -0
- package/build/stringFromAsyncIterable.js +7 -0
- package/build/terminatedArrayParser.js +4 -4
- package/build/terminatedArrayParser.test.js +7 -7
- package/build/toAsyncIterator.js +4 -4
- package/build/unionParser.d.ts +1 -1
- package/build/unionParser.js +2 -2
- package/build/unionParser.test.js +3 -3
- package/build/unparser.d.ts +3 -3
- package/build/unparser.js +6 -4
- package/build/unparser.test.js +7 -19
- package/build/unparserContext.d.ts +2 -2
- package/build/unparserContext.js +2 -3
- package/build/unparserError.d.ts +2 -1
- package/build/unparserError.js +2 -1
- package/build/unparserImplementationInvariant.d.ts +1 -1
- package/build/unparserOutputCompanion.d.ts +1 -1
- package/build/unparserOutputCompanion.js +1 -1
- package/build/zipParser.js +1 -1
- package/build/zipUnparser.d.ts +3 -3
- package/build/zipUnparser.js +9 -19
- package/build/zipUnparser.test.js +1 -1
- package/package.json +20 -26
- package/src/allSettledStream.test.ts +2 -2
- package/src/allSettledStream.ts +3 -3
- package/src/androidPackageParser.test.ts +17 -19
- package/src/androidPackageParser.ts +129 -171
- package/src/androidPackageUnparser.test.ts +19 -21
- package/src/androidPackageUnparser.ts +23 -17
- package/src/arbitrarilySlicedAsyncInterable.ts +1 -1
- package/src/arbitrarilySlicedAsyncInterator.ts +4 -4
- package/src/arbitraryDalvikBytecode.ts +992 -0
- package/src/arbitraryDalvikExecutable.ts +434 -0
- package/src/arbitraryDosDateTime.ts +1 -0
- package/src/arbitraryZipStream.ts +1 -1
- package/src/arrayParser.ts +2 -2
- package/src/arrayUnparser.ts +2 -2
- package/src/backsmali.ts +48 -4
- package/src/bash.ts +120 -0
- package/src/bashParser.test.ts +332 -0
- package/src/bashParser.ts +461 -0
- package/src/bsonParser.test.ts +12 -14
- package/src/customInvariant.ts +8 -12
- package/src/dalvikBytecodeParser/formatParsers.ts +376 -17
- package/src/dalvikBytecodeParser/formatSizes.ts +35 -0
- package/src/dalvikBytecodeParser/operationFormats.ts +226 -0
- package/src/dalvikBytecodeParser.ts +1042 -243
- package/src/dalvikBytecodeUnparser/formatUnparsers.ts +442 -0
- package/src/dalvikBytecodeUnparser.test.ts +44 -0
- package/src/dalvikBytecodeUnparser.ts +758 -0
- package/src/dalvikExecutable.ts +110 -48
- package/src/dalvikExecutableParser/stringSyntaxParser.ts +33 -33
- package/src/dalvikExecutableParser/typeParsers.ts +23 -14
- package/src/dalvikExecutableParser/typedNumbers.ts +19 -19
- package/src/dalvikExecutableParser.test.ts +60 -60
- package/src/dalvikExecutableParser.test.ts.md +6 -6
- package/src/dalvikExecutableParser.test.ts.snap +0 -0
- package/src/dalvikExecutableParser.ts +911 -434
- package/src/dalvikExecutableParserAgainstSmaliParser.test.ts +256 -239
- package/src/dalvikExecutableUnparser/annotationUnparsers.ts +135 -0
- package/src/dalvikExecutableUnparser/poolBuilders.ts +189 -0
- package/src/dalvikExecutableUnparser/poolScanners.ts +297 -0
- package/src/dalvikExecutableUnparser/sectionUnparsers.ts +683 -0
- package/src/dalvikExecutableUnparser/utils.ts +149 -0
- package/src/dalvikExecutableUnparser.test.ts +57 -0
- package/src/dalvikExecutableUnparser.ts +581 -0
- package/src/debugLogInputParser.ts +1 -1
- package/src/disjunctionParser.ts +5 -5
- package/src/elementTerminatedArrayParser.test.ts +8 -8
- package/src/elementTerminatedArrayParser.ts +2 -2
- package/src/elementTerminatedSequenceArrayParser.test.ts +4 -6
- package/src/elementTerminatedSequenceArrayParser.ts +2 -2
- package/src/elementTerminatedSequenceParser.test.ts +4 -6
- package/src/elementTerminatedSequenceParser.ts +2 -2
- package/src/endOfInputParser.ts +1 -1
- package/src/exactElementSwitchParser.ts +41 -0
- package/src/fetchCid.test.ts +20 -0
- package/src/fetchCid.ts +3 -7
- package/src/fixedLengthSequenceParser.test.ts +10 -12
- package/src/hasExecutable.ts +2 -2
- package/src/highResolutionTimer.ts +1 -1
- package/src/index.ts +113 -2
- package/src/inputReader.test.ts +39 -52
- package/src/inputReader.ts +2 -4
- package/src/inputReaderState.ts +1 -1
- package/src/inspect.ts +1 -1
- package/src/javaKeyStoreParser.test.ts +12 -14
- package/src/javaKeyStoreParser.ts +2 -6
- package/src/jsonParser.test.ts +2 -4
- package/src/jsonParser.ts +34 -38
- package/src/lazyMessageError.test.ts +21 -0
- package/src/lazyMessageError.ts +88 -0
- package/src/leb128Parser.test.ts +25 -23
- package/src/leb128Parser.ts +19 -19
- package/src/negativeLookaheadParser.test.ts +7 -11
- package/src/negativeLookaheadParser.ts +2 -2
- package/src/noStackCaptureOverheadError.test.ts +17 -0
- package/src/noStackCaptureOverheadError.ts +12 -0
- package/src/nonEmptyArrayParser.test.ts +3 -2
- package/src/nonEmptyArrayParser.ts +2 -2
- package/src/optionalParser.ts +2 -2
- package/src/parser.test.ts +96 -43
- package/src/parser.test.ts.md +13 -6
- package/src/parser.test.ts.snap +0 -0
- package/src/parser.ts +35 -12
- package/src/parserAccessorParser.ts +1 -1
- package/src/parserConsumedSequenceParser.ts +3 -3
- package/src/parserContext.test.ts +7 -3
- package/src/parserContext.ts +82 -48
- package/src/parserError.ts +143 -63
- package/src/parserImplementationInvariant.ts +3 -3
- package/src/parserInputCompanion.ts +2 -2
- package/src/promiseCompose.ts +2 -2
- package/src/regexpParser.test.ts +186 -0
- package/src/regexpParser.ts +94 -0
- package/src/regularExpression.ts +24 -0
- package/src/regularExpressionParser.test.ts +102 -0
- package/src/regularExpressionParser.ts +921 -0
- package/src/separatedArrayParser.ts +3 -3
- package/src/separatedNonEmptyArrayParser.test.ts +117 -0
- package/src/separatedNonEmptyArrayParser.ts +61 -0
- package/src/sequenceBuffer.test.ts +9 -9
- package/src/sequenceBuffer.ts +4 -4
- package/src/sequenceTerminatedSequenceParser.test.ts +3 -5
- package/src/sequenceTerminatedSequenceParser.ts +4 -4
- package/src/sequenceUnparser.ts +2 -2
- package/src/skipToParser.ts +2 -2
- package/src/sliceBoundedParser.test.ts +4 -12
- package/src/sliceBoundedParser.ts +2 -2
- package/src/smali.ts +8 -3
- package/src/smaliParser.test.ts +377 -66
- package/src/smaliParser.test.ts.md +1635 -48
- package/src/smaliParser.test.ts.snap +0 -0
- package/src/smaliParser.ts +2751 -569
- package/src/stringFromAsyncIterable.ts +9 -0
- package/src/terminatedArrayParser.test.ts +11 -11
- package/src/terminatedArrayParser.ts +5 -7
- package/src/toAsyncIterator.ts +8 -8
- package/src/uint8Array.ts +2 -3
- package/src/unionParser.test.ts +22 -23
- package/src/unionParser.ts +6 -8
- package/src/unparser.test.ts +18 -34
- package/src/unparser.ts +13 -9
- package/src/unparserContext.ts +9 -13
- package/src/unparserError.ts +2 -1
- package/src/unparserImplementationInvariant.ts +1 -1
- package/src/unparserOutputCompanion.ts +1 -1
- package/src/zip.ts +2 -6
- package/src/zipParser.ts +10 -18
- package/src/zipUnparser.test.ts +1 -1
- package/src/zipUnparser.ts +52 -64
- package/tsconfig.json +7 -1
- package/xo.config.ts +15 -0
- package/.yarn/releases/yarn-4.5.3.cjs +0 -934
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import { fetchCid } from './fetchCid.js';
|
|
3
|
+
const cid = 'bafybeicb3qajmwy6li7hche2nkucvytaxcyxhwhphmi73tgydjzmyoqoda';
|
|
4
|
+
test('fetchCid', async (t) => {
|
|
5
|
+
await Promise.all([
|
|
6
|
+
fetchCid(cid),
|
|
7
|
+
fetchCid(cid),
|
|
8
|
+
fetchCid(cid),
|
|
9
|
+
]);
|
|
10
|
+
await Promise.all([
|
|
11
|
+
fetchCid(cid),
|
|
12
|
+
fetchCid(cid),
|
|
13
|
+
fetchCid(cid),
|
|
14
|
+
]);
|
|
15
|
+
t.pass();
|
|
16
|
+
});
|
|
@@ -29,9 +29,9 @@ testProp.serial('fixedLengthSequenceParser', [
|
|
|
29
29
|
position: parserContext.position,
|
|
30
30
|
};
|
|
31
31
|
};
|
|
32
|
-
const { output: actualNaive } = await naiveTotalTimer.measureAsync(() => runParserWithRemainingInput(createTestWrapperParser(fixedLengthSequenceParserNaive), sequence, stringParserInputCompanion));
|
|
32
|
+
const { output: actualNaive } = await naiveTotalTimer.measureAsync(async () => runParserWithRemainingInput(createTestWrapperParser(fixedLengthSequenceParserNaive), sequence, stringParserInputCompanion));
|
|
33
33
|
t.true(actualNaive.result.length === Number(length));
|
|
34
|
-
const { output: actual } = await totalTimer.measureAsync(() => runParserWithRemainingInput(createTestWrapperParser(fixedLengthSequenceParser), sequence, stringParserInputCompanion));
|
|
34
|
+
const { output: actual } = await totalTimer.measureAsync(async () => runParserWithRemainingInput(createTestWrapperParser(fixedLengthSequenceParser), sequence, stringParserInputCompanion));
|
|
35
35
|
t.deepEqual(actual, actualNaive);
|
|
36
36
|
}, {
|
|
37
37
|
verbose: true,
|
package/build/hasExecutable.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { execa } from 'execa';
|
|
2
2
|
export async function hasExecutable(executable) {
|
|
3
|
-
const hasExecutable = execa(executable).
|
|
3
|
+
const hasExecutable = execa(executable).catch(() => false).then(() => true);
|
|
4
4
|
if (!hasExecutable) {
|
|
5
|
-
console.warn(
|
|
5
|
+
console.warn('Executable %o not found', executable);
|
|
6
6
|
}
|
|
7
7
|
return hasExecutable;
|
|
8
8
|
}
|
package/build/index.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
export { type Parser, runParser, setParserName, getParserName, } from './parser.js';
|
|
1
|
+
export { type Parser, runParser, runParserWithRemainingInput, setParserName, getParserName, cloneParser, type RunParserOptions, type RunParserWithRemainingInputResult, } from './parser.js';
|
|
2
2
|
export type { ParserContext, } from './parserContext.js';
|
|
3
|
+
export { type ParserInputCompanion, StringParserInputCompanion, stringParserInputCompanion, Uint8ArrayParserInputCompanion, uint8ArrayParserInputCompanion, } from './parserInputCompanion.js';
|
|
4
|
+
export { type UnparserOutputCompanion, StringUnparserOutputCompanion, stringUnparserOutputCompanion, Uint8ArrayUnparserOutputCompanion, uint8ArrayUnparserOutputCompanion, } from './unparserOutputCompanion.js';
|
|
5
|
+
export { type ParserError, type ParserParsingFailedError, type ParserParsingJoinError, type ParserErrorModule, isParserError, isParserParsingFailedError, isParserParsingJoinError, normalParserErrorModule, noStackCaptureOverheadParserErrorModule, } from './parserError.js';
|
|
6
|
+
export { parserCreatorCompose, parserCreatorComposeMem, } from './parserCreatorCompose.js';
|
|
7
|
+
export { promiseCompose, } from './promiseCompose.js';
|
|
8
|
+
export type { DeriveSequenceElement, } from './sequence.js';
|
|
3
9
|
export { createTupleParser, } from './tupleParser.js';
|
|
4
10
|
export { createExactSequenceParser, } from './exactSequenceParser.js';
|
|
5
11
|
export { createFixedLengthSequenceParser, } from './fixedLengthSequenceParser.js';
|
|
@@ -16,6 +22,22 @@ export { createSkipParser, } from './skipParser.js';
|
|
|
16
22
|
export { createEndOfInputParser, } from './endOfInputParser.js';
|
|
17
23
|
export { createListParser, } from './listParser.js';
|
|
18
24
|
export { createDebugLogParser, } from './debugLogParser.js';
|
|
19
|
-
export {
|
|
25
|
+
export { createNonEmptyArrayParser, } from './nonEmptyArrayParser.js';
|
|
26
|
+
export { createSeparatedArrayParser, } from './separatedArrayParser.js';
|
|
27
|
+
export { createSeparatedNonEmptyArrayParser, } from './separatedNonEmptyArrayParser.js';
|
|
28
|
+
export { createLookaheadParser, } from './lookaheadParser.js';
|
|
29
|
+
export { createNegativeLookaheadParser, } from './negativeLookaheadParser.js';
|
|
30
|
+
export { createElementTerminatedSequenceParser, } from './elementTerminatedSequenceParser.js';
|
|
31
|
+
export { createElementTerminatedSequenceArrayParser, } from './elementTerminatedSequenceArrayParser.js';
|
|
32
|
+
export { createElementTerminatedArrayParserUnsafe, } from './elementTerminatedArrayParser.js';
|
|
33
|
+
export { createSequenceTerminatedSequenceParser, } from './sequenceTerminatedSequenceParser.js';
|
|
34
|
+
export { createQuantifierParser, } from './quantifierParser.js';
|
|
35
|
+
export { createSkipToParser, } from './skipToParser.js';
|
|
36
|
+
export { createDebugLogInputParser, } from './debugLogInputParser.js';
|
|
37
|
+
export { createElementSwitchParser, } from './exactElementSwitchParser.js';
|
|
38
|
+
export { createParserConsumedSequenceParser, } from './parserConsumedSequenceParser.js';
|
|
39
|
+
export { type Unparser, type UnparserResult, runUnparser, } from './unparser.js';
|
|
40
|
+
export { type UnparserContext, WriteLater, WriteEarlier, UnparserContextImplementation, } from './unparserContext.js';
|
|
20
41
|
export { createArrayUnparser, } from './arrayUnparser.js';
|
|
21
42
|
export { createSequenceUnparser, } from './sequenceUnparser.js';
|
|
43
|
+
export { createRegExpParser, } from './regexpParser.js';
|
package/build/index.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
export { runParser, setParserName, getParserName, } from './parser.js';
|
|
1
|
+
export { runParser, runParserWithRemainingInput, setParserName, getParserName, cloneParser, } from './parser.js';
|
|
2
|
+
export { StringParserInputCompanion, stringParserInputCompanion, Uint8ArrayParserInputCompanion, uint8ArrayParserInputCompanion, } from './parserInputCompanion.js';
|
|
3
|
+
export { StringUnparserOutputCompanion, stringUnparserOutputCompanion, Uint8ArrayUnparserOutputCompanion, uint8ArrayUnparserOutputCompanion, } from './unparserOutputCompanion.js';
|
|
4
|
+
export { isParserError, isParserParsingFailedError, isParserParsingJoinError, normalParserErrorModule, noStackCaptureOverheadParserErrorModule, } from './parserError.js';
|
|
5
|
+
export { parserCreatorCompose, parserCreatorComposeMem, } from './parserCreatorCompose.js';
|
|
6
|
+
export { promiseCompose, } from './promiseCompose.js';
|
|
2
7
|
export { createTupleParser, } from './tupleParser.js';
|
|
3
8
|
export { createExactSequenceParser, } from './exactSequenceParser.js';
|
|
4
9
|
export { createFixedLengthSequenceParser, } from './fixedLengthSequenceParser.js';
|
|
@@ -15,6 +20,22 @@ export { createSkipParser, } from './skipParser.js';
|
|
|
15
20
|
export { createEndOfInputParser, } from './endOfInputParser.js';
|
|
16
21
|
export { createListParser, } from './listParser.js';
|
|
17
22
|
export { createDebugLogParser, } from './debugLogParser.js';
|
|
23
|
+
export { createNonEmptyArrayParser, } from './nonEmptyArrayParser.js';
|
|
24
|
+
export { createSeparatedArrayParser, } from './separatedArrayParser.js';
|
|
25
|
+
export { createSeparatedNonEmptyArrayParser, } from './separatedNonEmptyArrayParser.js';
|
|
26
|
+
export { createLookaheadParser, } from './lookaheadParser.js';
|
|
27
|
+
export { createNegativeLookaheadParser, } from './negativeLookaheadParser.js';
|
|
28
|
+
export { createElementTerminatedSequenceParser, } from './elementTerminatedSequenceParser.js';
|
|
29
|
+
export { createElementTerminatedSequenceArrayParser, } from './elementTerminatedSequenceArrayParser.js';
|
|
30
|
+
export { createElementTerminatedArrayParserUnsafe, } from './elementTerminatedArrayParser.js';
|
|
31
|
+
export { createSequenceTerminatedSequenceParser, } from './sequenceTerminatedSequenceParser.js';
|
|
32
|
+
export { createQuantifierParser, } from './quantifierParser.js';
|
|
33
|
+
export { createSkipToParser, } from './skipToParser.js';
|
|
34
|
+
export { createDebugLogInputParser, } from './debugLogInputParser.js';
|
|
35
|
+
export { createElementSwitchParser, } from './exactElementSwitchParser.js';
|
|
36
|
+
export { createParserConsumedSequenceParser, } from './parserConsumedSequenceParser.js';
|
|
18
37
|
export { runUnparser, } from './unparser.js';
|
|
38
|
+
export { WriteLater, WriteEarlier, UnparserContextImplementation, } from './unparserContext.js';
|
|
19
39
|
export { createArrayUnparser, } from './arrayUnparser.js';
|
|
20
40
|
export { createSequenceUnparser, } from './sequenceUnparser.js';
|
|
41
|
+
export { createRegExpParser, } from './regexpParser.js';
|
package/build/inputReader.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ParserInputCompanion } from './parserInputCompanion.js';
|
|
2
|
-
import { InputReaderState } from './inputReaderState.js';
|
|
2
|
+
import { type InputReaderState } from './inputReaderState.js';
|
|
3
3
|
export type InputReader<Sequence, Element> = {
|
|
4
4
|
get position(): number;
|
|
5
5
|
peek(offset: number): Promise<Element | undefined>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import test from 'ava';
|
|
2
2
|
import { InputReaderImplementation } from './inputReader.js';
|
|
3
3
|
import { stringParserInputCompanion } from './parserInputCompanion.js';
|
|
4
|
-
import { ParserImplementationError } from './parserError.js';
|
|
5
4
|
import { toAsyncIterable } from './toAsyncIterable.js';
|
|
6
5
|
test('inputReader', async (t) => {
|
|
7
6
|
const inputReader = new InputReaderImplementation(stringParserInputCompanion, (async function* () {
|
|
@@ -188,10 +187,15 @@ test('inputReader.lookahead', async (t) => {
|
|
|
188
187
|
t.is(read, 2);
|
|
189
188
|
inputReader.skip(1);
|
|
190
189
|
await t.throwsAsync(async () => lookahead0a.peek(0), {
|
|
191
|
-
|
|
190
|
+
any: true,
|
|
191
|
+
name: 'ParserImplementationInvariantError',
|
|
192
|
+
});
|
|
193
|
+
await t.throwsAsync(async () => lookahead0b.peek(0), {
|
|
194
|
+
any: true,
|
|
195
|
+
});
|
|
196
|
+
await t.throwsAsync(async () => lookahead0c.peek(0), {
|
|
197
|
+
any: true,
|
|
192
198
|
});
|
|
193
|
-
await t.throwsAsync(async () => lookahead0b.peek(0));
|
|
194
|
-
await t.throwsAsync(async () => lookahead0c.peek(0));
|
|
195
199
|
const lookahead1a = inputReader.lookahead();
|
|
196
200
|
const lookahead1b = inputReader.lookahead();
|
|
197
201
|
t.is(await lookahead1a.peek(0), 'b');
|
|
@@ -216,11 +220,19 @@ test('inputReader.lookahead', async (t) => {
|
|
|
216
220
|
inputReader.skip(1);
|
|
217
221
|
t.is(await inputReader.peek(0), 'c');
|
|
218
222
|
t.is(inputReader.position, 2);
|
|
219
|
-
await t.throwsAsync(async () => lookahead0a.peek(0)
|
|
220
|
-
|
|
221
|
-
|
|
223
|
+
await t.throwsAsync(async () => lookahead0a.peek(0), {
|
|
224
|
+
any: true,
|
|
225
|
+
});
|
|
226
|
+
await t.throwsAsync(async () => lookahead0b.peek(0), {
|
|
227
|
+
any: true,
|
|
228
|
+
});
|
|
229
|
+
await t.throwsAsync(async () => lookahead0c.peek(0), {
|
|
230
|
+
any: true,
|
|
231
|
+
});
|
|
222
232
|
t.is(await lookahead1a.peek(0), 'c');
|
|
223
|
-
await t.throwsAsync(async () => lookahead1b.peek(0)
|
|
233
|
+
await t.throwsAsync(async () => lookahead1b.peek(0), {
|
|
234
|
+
any: true,
|
|
235
|
+
});
|
|
224
236
|
t.is(await lookahead2a.peek(0), 'd');
|
|
225
237
|
t.is(await lookahead2b.peek(0), 'c');
|
|
226
238
|
t.is(lookahead0a.position, 0);
|
|
@@ -279,8 +291,8 @@ test('inputReader.lookahead skip position', async (t) => {
|
|
|
279
291
|
const END_OF_CONSUMED_SEQUENCES = Symbol('END_OF_CONSUMED_SEQUENCES');
|
|
280
292
|
const END_OF_BUFFERED_SEQUENCES = Symbol('END_OF_BUFFERED_SEQUENCES');
|
|
281
293
|
async function inputReaderStateToArray({ unconsumedBufferedSequences, consumedBufferedSequences, unbufferedSequences, }) {
|
|
282
|
-
const unconsumedBufferedSequencesArray = unconsumedBufferedSequences
|
|
283
|
-
const consumedBufferedSequencesArray = consumedBufferedSequences
|
|
294
|
+
const unconsumedBufferedSequencesArray = [...unconsumedBufferedSequences];
|
|
295
|
+
const consumedBufferedSequencesArray = [...consumedBufferedSequences];
|
|
284
296
|
const unbufferedSequencesArray = [];
|
|
285
297
|
if (unbufferedSequences) {
|
|
286
298
|
for await (const sequence of toAsyncIterable(unbufferedSequences)) {
|
|
@@ -295,39 +307,9 @@ async function inputReaderStateToArray({ unconsumedBufferedSequences, consumedBu
|
|
|
295
307
|
...unbufferedSequencesArray,
|
|
296
308
|
];
|
|
297
309
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
0,
|
|
302
|
-
[END_OF_CONSUMED_SEQUENCES, 'abc', END_OF_BUFFERED_SEQUENCES, 'def', '', 'gh'],
|
|
303
|
-
],
|
|
304
|
-
[
|
|
305
|
-
['', 'abc', 'def', '', 'gh'],
|
|
306
|
-
1,
|
|
307
|
-
['a', END_OF_CONSUMED_SEQUENCES, 'bc', END_OF_BUFFERED_SEQUENCES, 'def', '', 'gh'],
|
|
308
|
-
],
|
|
309
|
-
[
|
|
310
|
-
['', 'abc', 'def', '', 'gh'],
|
|
311
|
-
2,
|
|
312
|
-
['ab', END_OF_CONSUMED_SEQUENCES, 'c', END_OF_BUFFERED_SEQUENCES, 'def', '', 'gh'],
|
|
313
|
-
],
|
|
314
|
-
[
|
|
315
|
-
['', 'abc', 'def', '', 'gh'],
|
|
316
|
-
3,
|
|
317
|
-
[END_OF_CONSUMED_SEQUENCES, 'def', END_OF_BUFFERED_SEQUENCES, '', 'gh'],
|
|
318
|
-
],
|
|
319
|
-
[
|
|
320
|
-
['', 'abc', 'def', '', 'gh'],
|
|
321
|
-
4,
|
|
322
|
-
['d', END_OF_CONSUMED_SEQUENCES, 'ef', END_OF_BUFFERED_SEQUENCES, '', 'gh'],
|
|
323
|
-
],
|
|
324
|
-
[
|
|
325
|
-
['', 'abc', 'def', '', 'gh'],
|
|
326
|
-
8,
|
|
327
|
-
[END_OF_CONSUMED_SEQUENCES, END_OF_BUFFERED_SEQUENCES],
|
|
328
|
-
],
|
|
329
|
-
]) {
|
|
330
|
-
test('inputReader.toInputReaderState ' + JSON.stringify({ input, position }), async (t) => {
|
|
310
|
+
const inputReaderStateMacro = test.macro({
|
|
311
|
+
title: (providedTitle, input, position) => providedTitle ?? `inputReader.toInputReaderState ${JSON.stringify({ input, position })}`,
|
|
312
|
+
async exec(t, input, position, expected) {
|
|
331
313
|
const inputReader = new InputReaderImplementation(stringParserInputCompanion, (async function* () {
|
|
332
314
|
yield* input;
|
|
333
315
|
})());
|
|
@@ -335,5 +317,11 @@ for (const [input, position, expected,] of [
|
|
|
335
317
|
await inputReader.peek(0);
|
|
336
318
|
const actual = await inputReaderStateToArray(inputReader.toInputReaderState());
|
|
337
319
|
t.deepEqual(actual, expected);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
320
|
+
},
|
|
321
|
+
});
|
|
322
|
+
test(inputReaderStateMacro, ['', 'abc', 'def', '', 'gh'], 0, [END_OF_CONSUMED_SEQUENCES, 'abc', END_OF_BUFFERED_SEQUENCES, 'def', '', 'gh']);
|
|
323
|
+
test(inputReaderStateMacro, ['', 'abc', 'def', '', 'gh'], 1, ['a', END_OF_CONSUMED_SEQUENCES, 'bc', END_OF_BUFFERED_SEQUENCES, 'def', '', 'gh']);
|
|
324
|
+
test(inputReaderStateMacro, ['', 'abc', 'def', '', 'gh'], 2, ['ab', END_OF_CONSUMED_SEQUENCES, 'c', END_OF_BUFFERED_SEQUENCES, 'def', '', 'gh']);
|
|
325
|
+
test(inputReaderStateMacro, ['', 'abc', 'def', '', 'gh'], 3, [END_OF_CONSUMED_SEQUENCES, 'def', END_OF_BUFFERED_SEQUENCES, '', 'gh']);
|
|
326
|
+
test(inputReaderStateMacro, ['', 'abc', 'def', '', 'gh'], 4, ['d', END_OF_CONSUMED_SEQUENCES, 'ef', END_OF_BUFFERED_SEQUENCES, '', 'gh']);
|
|
327
|
+
test(inputReaderStateMacro, ['', 'abc', 'def', '', 'gh'], 8, [END_OF_CONSUMED_SEQUENCES, END_OF_BUFFERED_SEQUENCES]);
|
|
@@ -3,14 +3,14 @@ import { uint8ArrayParserInputCompanion } from './parserInputCompanion.js';
|
|
|
3
3
|
import { runParser } from './parser.js';
|
|
4
4
|
import { javaKeyStoreParser } from './javaKeyStoreParser.js';
|
|
5
5
|
import { fetchCid } from './fetchCid.js';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
test('javaKeyStore ' + javaKeyStoreCid, async (t) => {
|
|
6
|
+
const javaKeyStoreMacro = test.macro({
|
|
7
|
+
title: (providedTitle, javaKeyStoreCid) => providedTitle ?? `javaKeyStore ${javaKeyStoreCid}`,
|
|
8
|
+
async exec(t, javaKeyStoreCid) {
|
|
10
9
|
const javaKeyStoreStream = await fetchCid(javaKeyStoreCid);
|
|
11
10
|
const actual = await runParser(javaKeyStoreParser, javaKeyStoreStream, uint8ArrayParserInputCompanion, {
|
|
12
11
|
errorJoinMode: 'all',
|
|
13
12
|
});
|
|
14
13
|
t.snapshot(actual);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
test(javaKeyStoreMacro, 'bafkreig6k53b6p7bdvfjxc5mcb4qv3mffqls5ymqerxkqd6ih2xy5cs3n4');
|
package/build/jsonParser.js
CHANGED
|
@@ -17,16 +17,16 @@ const whitespaceParser = createArrayParser(createUnionParser([
|
|
|
17
17
|
createExactSequenceParser('\r'),
|
|
18
18
|
createExactSequenceParser('\n'),
|
|
19
19
|
]));
|
|
20
|
-
const jsonQuoteEscapeSequenceParser = promiseCompose(createExactSequenceParser(
|
|
20
|
+
const jsonQuoteEscapeSequenceParser = promiseCompose(createExactSequenceParser(String.raw `\"`), () => '"');
|
|
21
21
|
const jsonBackslashEscapeSequenceParser = promiseCompose(createExactSequenceParser('\\\\'), () => '\\');
|
|
22
|
-
const jsonSlashEscapeSequenceParser = promiseCompose(createExactSequenceParser(
|
|
23
|
-
const jsonBackspaceEscapeSequenceParser = promiseCompose(createExactSequenceParser(
|
|
24
|
-
const jsonFormFeedEscapeSequenceParser = promiseCompose(createExactSequenceParser(
|
|
25
|
-
const jsonNewLineEscapeSequenceParser = promiseCompose(createExactSequenceParser(
|
|
26
|
-
const jsonCarriageReturnEscapeSequenceParser = promiseCompose(createExactSequenceParser(
|
|
27
|
-
const jsonTabEscapeSequenceParser = promiseCompose(createExactSequenceParser(
|
|
22
|
+
const jsonSlashEscapeSequenceParser = promiseCompose(createExactSequenceParser(String.raw `\/`), () => '/');
|
|
23
|
+
const jsonBackspaceEscapeSequenceParser = promiseCompose(createExactSequenceParser(String.raw `\b`), () => '\b');
|
|
24
|
+
const jsonFormFeedEscapeSequenceParser = promiseCompose(createExactSequenceParser(String.raw `\f`), () => '\f');
|
|
25
|
+
const jsonNewLineEscapeSequenceParser = promiseCompose(createExactSequenceParser(String.raw `\n`), () => '\n');
|
|
26
|
+
const jsonCarriageReturnEscapeSequenceParser = promiseCompose(createExactSequenceParser(String.raw `\r`), () => '\r');
|
|
27
|
+
const jsonTabEscapeSequenceParser = promiseCompose(createExactSequenceParser(String.raw `\t`), () => '\t');
|
|
28
28
|
const jsonUnicodeEscapeSequenceParser = promiseCompose(createTupleParser([
|
|
29
|
-
createExactSequenceParser(
|
|
29
|
+
createExactSequenceParser(String.raw `\u`),
|
|
30
30
|
createFixedLengthSequenceParser(4),
|
|
31
31
|
]), ([, hexCode]) => String.fromCharCode(Number.parseInt(hexCode, 16)));
|
|
32
32
|
const jsonStringEscapeSequenceParser = createUnionParser([
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { NoStackCaptureOverheadError } from "./noStackCaptureOverheadError.js";
|
|
2
|
+
type ValueOrAccessor<T> = T | (() => T);
|
|
3
|
+
export type LazyMessage = ValueOrAccessor<string | string[]> | [ValueOrAccessor<string | string[]>, ...Array<ValueOrAccessor<unknown>>];
|
|
4
|
+
export declare function formatLazyMessage(lazyMessage: LazyMessage): string;
|
|
5
|
+
export interface LazyMessageError extends Error {
|
|
6
|
+
computeMessage(): void;
|
|
7
|
+
}
|
|
8
|
+
export declare function createLazyMessageErrorClass(BaseError: typeof NoStackCaptureOverheadError | typeof Error): {
|
|
9
|
+
new (lazyMessage: LazyMessage): {
|
|
10
|
+
name: string;
|
|
11
|
+
_lazyMessage: undefined | LazyMessage;
|
|
12
|
+
computeMessage(): void;
|
|
13
|
+
message: string;
|
|
14
|
+
stack?: string;
|
|
15
|
+
cause?: unknown;
|
|
16
|
+
};
|
|
17
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
18
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
19
|
+
stackTraceLimit: number;
|
|
20
|
+
};
|
|
21
|
+
export declare const NormalLazyMessageError: {
|
|
22
|
+
new (lazyMessage: LazyMessage): {
|
|
23
|
+
name: string;
|
|
24
|
+
_lazyMessage: undefined | LazyMessage;
|
|
25
|
+
computeMessage(): void;
|
|
26
|
+
message: string;
|
|
27
|
+
stack?: string;
|
|
28
|
+
cause?: unknown;
|
|
29
|
+
};
|
|
30
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
31
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
32
|
+
stackTraceLimit: number;
|
|
33
|
+
};
|
|
34
|
+
export declare const NoStackCaptureOverheadLazyMessageError: {
|
|
35
|
+
new (lazyMessage: LazyMessage): {
|
|
36
|
+
name: string;
|
|
37
|
+
_lazyMessage: undefined | LazyMessage;
|
|
38
|
+
computeMessage(): void;
|
|
39
|
+
message: string;
|
|
40
|
+
stack?: string;
|
|
41
|
+
cause?: unknown;
|
|
42
|
+
};
|
|
43
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
44
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
45
|
+
stackTraceLimit: number;
|
|
46
|
+
};
|
|
47
|
+
export declare function isLazyMessageError(value: unknown): value is LazyMessageError;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { NoStackCaptureOverheadError } from "./noStackCaptureOverheadError.js";
|
|
2
|
+
function formatLazyMessageFormat(format) {
|
|
3
|
+
if (typeof format === 'function') {
|
|
4
|
+
format = format();
|
|
5
|
+
}
|
|
6
|
+
if (Array.isArray(format)) {
|
|
7
|
+
return format.join('\n');
|
|
8
|
+
}
|
|
9
|
+
return format;
|
|
10
|
+
}
|
|
11
|
+
function formatLazyMessageSubstitutions(format, formatArguments) {
|
|
12
|
+
return format.replaceAll('%s', () => {
|
|
13
|
+
const argumentOrAccessor = formatArguments.shift();
|
|
14
|
+
return typeof argumentOrAccessor === 'function' ? argumentOrAccessor() : argumentOrAccessor;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export function formatLazyMessage(lazyMessage) {
|
|
18
|
+
if (Array.isArray(lazyMessage)) {
|
|
19
|
+
const [format, ...formatArguments] = lazyMessage;
|
|
20
|
+
const formattedFormat = formatLazyMessageFormat(format);
|
|
21
|
+
return formatLazyMessageSubstitutions(formattedFormat, formatArguments);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return formatLazyMessageFormat(lazyMessage);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export function createLazyMessageErrorClass(BaseError) {
|
|
28
|
+
return class LazyMessageError extends BaseError {
|
|
29
|
+
name = 'LazyMessageError';
|
|
30
|
+
_lazyMessage;
|
|
31
|
+
constructor(lazyMessage) {
|
|
32
|
+
super('LAZY_MESSAGE');
|
|
33
|
+
this._lazyMessage = lazyMessage;
|
|
34
|
+
}
|
|
35
|
+
computeMessage() {
|
|
36
|
+
if (this._lazyMessage === undefined) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
this.message = formatLazyMessage(this._lazyMessage);
|
|
40
|
+
this.stack = this.stack?.replace('LAZY_MESSAGE', this.message);
|
|
41
|
+
delete this._lazyMessage;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export const NormalLazyMessageError = createLazyMessageErrorClass(Error);
|
|
46
|
+
export const NoStackCaptureOverheadLazyMessageError = createLazyMessageErrorClass(NoStackCaptureOverheadError);
|
|
47
|
+
export function isLazyMessageError(value) {
|
|
48
|
+
return (typeof value === 'object'
|
|
49
|
+
&& value !== null
|
|
50
|
+
&& value instanceof Error
|
|
51
|
+
&& '_lazyMessage' in value
|
|
52
|
+
&& typeof value.computeMessage === 'function');
|
|
53
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import { NormalLazyMessageError } from './lazyMessageError.js';
|
|
3
|
+
test('LazyMessageError works', t => {
|
|
4
|
+
const error = new NormalLazyMessageError([
|
|
5
|
+
() => [
|
|
6
|
+
'Line 1: %s',
|
|
7
|
+
'Line 2: %s and %s.',
|
|
8
|
+
],
|
|
9
|
+
42,
|
|
10
|
+
() => 'foo',
|
|
11
|
+
true,
|
|
12
|
+
]);
|
|
13
|
+
error.computeMessage();
|
|
14
|
+
t.is(error.message, 'Line 1: 42\nLine 2: foo and true.');
|
|
15
|
+
});
|
package/build/leb128Parser.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Parser } from
|
|
1
|
+
import { type Parser } from './parser.js';
|
|
2
2
|
export declare const uleb128Parser: Parser<bigint, Uint8Array>;
|
|
3
3
|
export declare const sleb128Parser: Parser<bigint, Uint8Array>;
|
|
4
4
|
export declare const uleb128NumberParser: Parser<number, Uint8Array>;
|
package/build/leb128Parser.js
CHANGED
|
@@ -3,8 +3,8 @@ export const uleb128Parser = async (parserContext) => {
|
|
|
3
3
|
let value = 0n;
|
|
4
4
|
while (true) {
|
|
5
5
|
const byte = await parserContext.read(0);
|
|
6
|
-
const byteValue = BigInt(byte &
|
|
7
|
-
const byteNotLast = BigInt(byte &
|
|
6
|
+
const byteValue = BigInt(byte & 0b0111_1111);
|
|
7
|
+
const byteNotLast = BigInt(byte & 0b1000_0000);
|
|
8
8
|
value |= byteValue << leastSignificantValueBitIndex;
|
|
9
9
|
if (byteNotLast) {
|
|
10
10
|
leastSignificantValueBitIndex += 7n;
|
|
@@ -19,14 +19,14 @@ export const sleb128Parser = async (parserContext) => {
|
|
|
19
19
|
let leastSignificantValueBitIndex = 0n;
|
|
20
20
|
while (true) {
|
|
21
21
|
const byte = await parserContext.read(0);
|
|
22
|
-
const byteValue = BigInt(byte &
|
|
23
|
-
const byteNotLast = BigInt(byte &
|
|
22
|
+
const byteValue = BigInt(byte & 0b0111_1111);
|
|
23
|
+
const byteNotLast = BigInt(byte & 0b1000_0000);
|
|
24
24
|
value |= byteValue << leastSignificantValueBitIndex;
|
|
25
25
|
leastSignificantValueBitIndex += 7n;
|
|
26
26
|
if (byteNotLast) {
|
|
27
27
|
continue;
|
|
28
28
|
}
|
|
29
|
-
const mostSignificantInputBit = byte &
|
|
29
|
+
const mostSignificantInputBit = byte & 0b0100_0000;
|
|
30
30
|
if (mostSignificantInputBit) {
|
|
31
31
|
value |= (~0n << leastSignificantValueBitIndex);
|
|
32
32
|
}
|
|
@@ -49,8 +49,8 @@ export const uleb128UnsafeNumberParser = async (parserContext) => {
|
|
|
49
49
|
let value = 0;
|
|
50
50
|
while (true) {
|
|
51
51
|
const byte = await parserContext.read(0);
|
|
52
|
-
const byteValue = byte &
|
|
53
|
-
const byteNotLast = byte &
|
|
52
|
+
const byteValue = byte & 0b0111_1111;
|
|
53
|
+
const byteNotLast = byte & 0b1000_0000;
|
|
54
54
|
value |= byteValue << leastSignificantValueBitIndex;
|
|
55
55
|
if (byteNotLast) {
|
|
56
56
|
leastSignificantValueBitIndex += 7;
|
|
@@ -65,14 +65,14 @@ export const sleb128UnsafeNumberParser = async (parserContext) => {
|
|
|
65
65
|
let leastSignificantValueBitIndex = 0;
|
|
66
66
|
while (true) {
|
|
67
67
|
const byte = await parserContext.read(0);
|
|
68
|
-
const byteValue = byte &
|
|
69
|
-
const byteNotLast = byte &
|
|
68
|
+
const byteValue = byte & 0b0111_1111;
|
|
69
|
+
const byteNotLast = byte & 0b1000_0000;
|
|
70
70
|
value |= byteValue << leastSignificantValueBitIndex;
|
|
71
71
|
leastSignificantValueBitIndex += 7;
|
|
72
72
|
if (byteNotLast) {
|
|
73
73
|
continue;
|
|
74
74
|
}
|
|
75
|
-
const mostSignificantInputBit = byte &
|
|
75
|
+
const mostSignificantInputBit = byte & 0b0100_0000;
|
|
76
76
|
if (leastSignificantValueBitIndex < 32 && mostSignificantInputBit) {
|
|
77
77
|
value |= (~0 << leastSignificantValueBitIndex);
|
|
78
78
|
}
|
|
@@ -4,7 +4,7 @@ import test from 'ava';
|
|
|
4
4
|
import leb128 from 'leb128';
|
|
5
5
|
import { uint8ArrayParserInputCompanion } from './parserInputCompanion.js';
|
|
6
6
|
import { runParser } from './parser.js';
|
|
7
|
-
import { uleb128Parser, sleb128Parser, uleb128NumberParser, sleb128NumberParser } from './leb128Parser.js';
|
|
7
|
+
import { uleb128Parser, sleb128Parser, uleb128NumberParser, sleb128NumberParser, } from './leb128Parser.js';
|
|
8
8
|
test('sleb128, uleb128, uleb128p1', async (t) => {
|
|
9
9
|
for (const [input, expectedSleb128, expectedUleb128,] of [
|
|
10
10
|
[Buffer.from('00', 'hex'), 0n, 0n],
|
|
@@ -29,13 +29,13 @@ test('sleb128, uleb128, uleb128p1', async (t) => {
|
|
|
29
29
|
}
|
|
30
30
|
for (const [input, expectedSleb128,] of [
|
|
31
31
|
[new Uint8Array([2]), 2n],
|
|
32
|
-
[new Uint8Array([
|
|
32
|
+
[new Uint8Array([0x7E]), -2n],
|
|
33
33
|
[new Uint8Array([127 + 0x80, 0]), 127n],
|
|
34
|
-
[new Uint8Array([1 + 0x80,
|
|
34
|
+
[new Uint8Array([1 + 0x80, 0x7F]), -127n],
|
|
35
35
|
[new Uint8Array([0 + 0x80, 1]), 128n],
|
|
36
|
-
[new Uint8Array([0 + 0x80,
|
|
36
|
+
[new Uint8Array([0 + 0x80, 0x7F]), -128n],
|
|
37
37
|
[new Uint8Array([1 + 0x80, 1]), 129n],
|
|
38
|
-
[new Uint8Array([
|
|
38
|
+
[new Uint8Array([0x7F + 0x80, 0x7E]), -129n],
|
|
39
39
|
]) {
|
|
40
40
|
const actualSleb128 = await runParser(sleb128Parser, input, uint8ArrayParserInputCompanion);
|
|
41
41
|
t.is(actualSleb128, expectedSleb128, 'sleb128');
|
|
@@ -65,7 +65,7 @@ testProp.skip('uleb128NumberParser on large number', [
|
|
|
65
65
|
], async (t, natural) => {
|
|
66
66
|
const uleb128 = leb128.unsigned.encode(natural);
|
|
67
67
|
if (natural > (2 ** 32) - 1) {
|
|
68
|
-
await t.throwsAsync(() => runParser(uleb128NumberParser, uleb128, uint8ArrayParserInputCompanion));
|
|
68
|
+
await t.throwsAsync(async () => runParser(uleb128NumberParser, uleb128, uint8ArrayParserInputCompanion));
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
71
|
const actualUleb128 = await runParser(uleb128NumberParser, uleb128, uint8ArrayParserInputCompanion);
|
|
@@ -79,7 +79,7 @@ testProp.skip('sleb128NumberParser on large number', [
|
|
|
79
79
|
], async (t, integer) => {
|
|
80
80
|
const sleb128 = leb128.signed.encode(integer);
|
|
81
81
|
if (integer > (2 ** 32) - 1 || integer < -(2 ** 32)) {
|
|
82
|
-
await t.throwsAsync(() => runParser(sleb128NumberParser, sleb128, uint8ArrayParserInputCompanion));
|
|
82
|
+
await t.throwsAsync(async () => runParser(sleb128NumberParser, sleb128, uint8ArrayParserInputCompanion));
|
|
83
83
|
return;
|
|
84
84
|
}
|
|
85
85
|
const actualSleb128 = await runParser(sleb128NumberParser, sleb128, uint8ArrayParserInputCompanion);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getParserName, setParserName } from './parser.js';
|
|
2
|
-
import {
|
|
2
|
+
import { isParserParsingFailedError } from './parserError.js';
|
|
3
3
|
export const createNegativeLookaheadParser = (childParser) => {
|
|
4
4
|
const negativeLookaheadParser = async (parserContext) => {
|
|
5
5
|
const childParserContext = parserContext.lookahead();
|
|
@@ -9,7 +9,7 @@ export const createNegativeLookaheadParser = (childParser) => {
|
|
|
9
9
|
childParserSuccess = true;
|
|
10
10
|
}
|
|
11
11
|
catch (error) {
|
|
12
|
-
if (!(error
|
|
12
|
+
if (!isParserParsingFailedError(error)) {
|
|
13
13
|
throw error;
|
|
14
14
|
}
|
|
15
15
|
childParserSuccess = false;
|
|
@@ -5,24 +5,24 @@ import { createExactSequenceParser } from './exactSequenceParser.js';
|
|
|
5
5
|
import { runParser } from './parser.js';
|
|
6
6
|
import { stringParserInputCompanion } from './parserInputCompanion.js';
|
|
7
7
|
import { createTupleParser } from './tupleParser.js';
|
|
8
|
-
import { ParserParsingFailedError } from './parserError.js';
|
|
9
8
|
testProp('negativeLookaheadParser', [
|
|
10
9
|
fc.tuple(fc.string({
|
|
11
10
|
minLength: 1,
|
|
12
11
|
}), fc.string({
|
|
13
12
|
minLength: 1,
|
|
14
|
-
})).filter(([a, b]) => !a.startsWith(b))
|
|
13
|
+
})).filter(([a, b]) => !a.startsWith(b)),
|
|
15
14
|
], async (t, [stringA, stringB]) => {
|
|
16
15
|
const result = await runParser(createTupleParser([
|
|
17
16
|
createNegativeLookaheadParser(createExactSequenceParser(stringB)),
|
|
18
17
|
createExactSequenceParser(stringA + stringB),
|
|
19
18
|
]), stringA + stringB, stringParserInputCompanion);
|
|
20
19
|
t.deepEqual(result, [undefined, stringA + stringB]);
|
|
21
|
-
await t.throwsAsync(() => runParser(createTupleParser([
|
|
20
|
+
await t.throwsAsync(async () => runParser(createTupleParser([
|
|
22
21
|
createNegativeLookaheadParser(createExactSequenceParser(stringA)),
|
|
23
22
|
createExactSequenceParser(stringA + stringB),
|
|
24
23
|
]), stringA + stringB, stringParserInputCompanion), {
|
|
25
|
-
|
|
24
|
+
any: true,
|
|
25
|
+
name: 'ParserParsingInvariantError',
|
|
26
26
|
message: /lookahead/,
|
|
27
27
|
});
|
|
28
28
|
}, {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
class NoStackCaptureOverheadErrorClass extends Error {
|
|
2
|
+
}
|
|
3
|
+
function NoStackCaptureOverheadErrorConstructor(message) {
|
|
4
|
+
this.name = 'NoStackCaptureOverheadError';
|
|
5
|
+
this.message = message;
|
|
6
|
+
this.stack = 'This stack is intentionally left blank to avoid capture overhead.';
|
|
7
|
+
}
|
|
8
|
+
NoStackCaptureOverheadErrorConstructor.prototype = Object.create(Error.prototype);
|
|
9
|
+
export const NoStackCaptureOverheadError = NoStackCaptureOverheadErrorConstructor;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import test from 'ava';
|
|
2
|
+
import util from 'util';
|
|
3
|
+
import { NoStackCaptureOverheadError } from './noStackCaptureOverheadError.js';
|
|
4
|
+
test('NoStackCaptureOverheadError works', t => {
|
|
5
|
+
const error = new NoStackCaptureOverheadError('Test message');
|
|
6
|
+
t.is(error.name, 'NoStackCaptureOverheadError');
|
|
7
|
+
t.is(error.message, 'Test message');
|
|
8
|
+
t.true(error instanceof Error, 'error is instance of Error');
|
|
9
|
+
t.true(error instanceof NoStackCaptureOverheadError, 'error is instance of NoStackCaptureOverheadError');
|
|
10
|
+
t.false(new Error() instanceof NoStackCaptureOverheadError, 'regular Error is not instance of NoStackCaptureOverheadError');
|
|
11
|
+
if (typeof Error.isError === 'function') {
|
|
12
|
+
t.false(Error.isError(error), 'Error.isError does not identify error as Error');
|
|
13
|
+
}
|
|
14
|
+
t.false(util.types.isNativeError(error), 'util.types.isNativeError does not identify error as native Error');
|
|
15
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getParserName, setParserName } from './parser.js';
|
|
2
|
-
import {
|
|
2
|
+
import { isParserParsingFailedError } from './parserError.js';
|
|
3
3
|
export const createNonEmptyArrayParser = (elementParser) => {
|
|
4
4
|
const nonEmptyArrayParser = async (parserContext) => {
|
|
5
5
|
const elements = [];
|
|
@@ -15,7 +15,7 @@ export const createNonEmptyArrayParser = (elementParser) => {
|
|
|
15
15
|
elementParserContext.unlookahead();
|
|
16
16
|
}
|
|
17
17
|
catch (error) {
|
|
18
|
-
if (error
|
|
18
|
+
if (isParserParsingFailedError(error)) {
|
|
19
19
|
break;
|
|
20
20
|
}
|
|
21
21
|
throw error;
|