@futpib/parser 1.0.3 → 1.0.6
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/.claude/settings.local.json +24 -0
- package/.github/workflows/main.yml +1 -0
- package/build/androidPackageParser.js +30 -32
- package/build/arbitraryDalvikBytecode.d.ts +3 -3
- package/build/arbitraryDalvikBytecode.js +33 -27
- package/build/arbitraryDalvikExecutable.js +55 -17
- package/build/arbitraryJava.d.ts +31 -0
- package/build/arbitraryJava.js +532 -0
- package/build/arbitraryJavaScript.d.ts +3 -0
- package/build/arbitraryJavaScript.js +263 -0
- package/build/arbitraryJavascript.d.ts +3 -0
- package/build/arbitraryJavascript.js +263 -0
- package/build/arbitraryZig.d.ts +3 -0
- package/build/arbitraryZig.js +240 -0
- package/build/arbitraryZipStream.d.ts +1 -1
- package/build/arrayParser.js +72 -13
- package/build/backsmali.d.ts +4 -3
- package/build/backsmali.js +26 -6
- package/build/bash.d.ts +89 -0
- package/build/bash.js +1 -0
- package/build/bashParser.d.ts +6 -0
- package/build/bashParser.js +335 -0
- package/build/bashParser.test.d.ts +1 -0
- package/build/bashParser.test.js +343 -0
- package/build/bashParserEdgeCases.test.d.ts +1 -0
- package/build/bashParserEdgeCases.test.js +117 -0
- package/build/dalvikBytecodeParser/addressConversion.d.ts +110 -0
- package/build/dalvikBytecodeParser/addressConversion.js +334 -0
- package/build/dalvikBytecodeParser/formatParsers.d.ts +7 -6
- package/build/dalvikBytecodeParser/formatParsers.js +13 -14
- package/build/dalvikBytecodeParser.d.ts +60 -31
- package/build/dalvikBytecodeParser.js +92 -35
- package/build/dalvikBytecodeParser.test-d.d.ts +1 -0
- package/build/dalvikBytecodeParser.test-d.js +268 -0
- package/build/dalvikBytecodeUnparser/formatUnparsers.d.ts +9 -8
- package/build/dalvikBytecodeUnparser/formatUnparsers.js +13 -12
- package/build/dalvikBytecodeUnparser.d.ts +2 -2
- package/build/dalvikBytecodeUnparser.js +23 -23
- package/build/dalvikBytecodeUnparser.test.js +7 -7
- package/build/dalvikExecutable.d.ts +3 -3
- package/build/dalvikExecutable.test-d.d.ts +1 -0
- package/build/dalvikExecutable.test-d.js +59 -0
- package/build/dalvikExecutableParser/typedNumbers.d.ts +18 -0
- package/build/dalvikExecutableParser/typedNumbers.js +3 -0
- package/build/dalvikExecutableParser.d.ts +2 -1
- package/build/dalvikExecutableParser.js +96 -77
- package/build/dalvikExecutableParser.test.js +24 -3
- package/build/dalvikExecutableParserAgainstSmaliParser.test.js +3 -0
- package/build/dalvikExecutableUnparser/poolScanners.d.ts +2 -2
- package/build/dalvikExecutableUnparser/sectionUnparsers.d.ts +3 -3
- package/build/dalvikExecutableUnparser/sectionUnparsers.js +26 -11
- package/build/dalvikExecutableUnparser.d.ts +2 -2
- package/build/dalvikExecutableUnparser.test.js +2 -1
- package/build/disjunctionParser.d.ts +5 -3
- package/build/disjunctionParser.js +79 -17
- package/build/disjunctionParser.test-d.d.ts +1 -0
- package/build/disjunctionParser.test-d.js +72 -0
- package/build/elementSwitchParser.d.ts +4 -0
- package/build/{exactElementSwitchParser.js → elementSwitchParser.js} +3 -4
- package/build/elementSwitchParser.test-d.d.ts +1 -0
- package/build/elementSwitchParser.test-d.js +44 -0
- package/build/exactSequenceParser.d.ts +4 -2
- package/build/exactSequenceParser.test-d.d.ts +1 -0
- package/build/exactSequenceParser.test-d.js +36 -0
- package/build/fetchCid.js +2 -66
- package/build/index.d.ts +25 -2
- package/build/index.js +23 -1
- package/build/index.test.js +16 -1
- package/build/inputReader.d.ts +10 -0
- package/build/inputReader.js +36 -0
- package/build/java.d.ts +502 -0
- package/build/java.js +2 -0
- package/build/javaKeyStoreParser.js +14 -17
- package/build/javaParser.d.ts +51 -0
- package/build/javaParser.js +1538 -0
- package/build/javaParser.test.d.ts +1 -0
- package/build/javaParser.test.js +1287 -0
- package/build/javaScript.d.ts +35 -0
- package/build/javaScript.js +1 -0
- package/build/javaScriptParser.d.ts +9 -0
- package/build/javaScriptParser.js +34 -0
- package/build/javaScriptUnparser.d.ts +3 -0
- package/build/javaScriptUnparser.js +4 -0
- package/build/javaScriptUnparser.test.d.ts +1 -0
- package/build/javaScriptUnparser.test.js +24 -0
- package/build/javaUnparser.d.ts +2 -0
- package/build/javaUnparser.js +519 -0
- package/build/javaUnparser.test.d.ts +1 -0
- package/build/javaUnparser.test.js +24 -0
- package/build/javascript.d.ts +35 -0
- package/build/javascript.js +1 -0
- package/build/javascriptParser.d.ts +9 -0
- package/build/javascriptParser.js +34 -0
- package/build/javascriptUnparser.d.ts +3 -0
- package/build/javascriptUnparser.js +4 -0
- package/build/javascriptUnparser.test.d.ts +1 -0
- package/build/javascriptUnparser.test.js +24 -0
- package/build/jsonParser.js +2 -12
- package/build/lazyMessageError.d.ts +3 -0
- package/build/lookaheadParser.js +60 -3
- package/build/negativeLookaheadParser.js +70 -11
- package/build/nonEmptyArrayParser.js +72 -13
- package/build/objectParser.d.ts +12 -0
- package/build/objectParser.js +31 -0
- package/build/objectParser.test-d.d.ts +1 -0
- package/build/objectParser.test-d.js +112 -0
- package/build/objectParser.test.d.ts +1 -0
- package/build/objectParser.test.js +55 -0
- package/build/optionalParser.js +69 -10
- package/build/parser.d.ts +4 -0
- package/build/parser.js +3 -1
- package/build/parser.test.js +114 -1
- package/build/parserConsumedSequenceParser.js +66 -7
- package/build/parserContext.d.ts +6 -0
- package/build/parserContext.js +20 -11
- package/build/parserError.d.ts +119 -27
- package/build/parserError.js +16 -8
- package/build/regexpParser.d.ts +2 -0
- package/build/regexpParser.js +101 -0
- package/build/regexpParser.test.d.ts +1 -0
- package/build/regexpParser.test.js +114 -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 +600 -0
- package/build/regularExpressionParser.test.d.ts +1 -0
- package/build/regularExpressionParser.test.js +89 -0
- package/build/separatedArrayParser.js +73 -14
- package/build/separatedNonEmptyArrayParser.js +73 -14
- package/build/sliceBoundedParser.js +62 -5
- package/build/smaliParser.d.ts +7 -7
- package/build/smaliParser.js +185 -268
- package/build/smaliParser.test.js +58 -0
- package/build/stringEscapes.d.ts +5 -0
- package/build/stringEscapes.js +244 -0
- package/build/symbolicExpression.d.ts +29 -0
- package/build/symbolicExpression.js +1 -0
- package/build/symbolicExpressionParser.d.ts +4 -0
- package/build/symbolicExpressionParser.js +123 -0
- package/build/symbolicExpressionParser.test.d.ts +1 -0
- package/build/symbolicExpressionParser.test.js +289 -0
- package/build/terminatedArrayParser.js +113 -38
- package/build/terminatedArrayParser.test.js +4 -2
- package/build/tupleParser.d.ts +7 -15
- package/build/tupleParser.js +1 -0
- package/build/unionParser.d.ts +5 -3
- package/build/unionParser.js +7 -2
- package/build/unionParser.test-d.d.ts +1 -0
- package/build/unionParser.test-d.js +72 -0
- package/build/unionParser.test.js +10 -11
- package/build/zig.d.ts +280 -0
- package/build/zig.js +2 -0
- package/build/zigParser.d.ts +3 -0
- package/build/zigParser.js +1119 -0
- package/build/zigParser.test.d.ts +1 -0
- package/build/zigParser.test.js +1590 -0
- package/build/zigUnparser.d.ts +2 -0
- package/build/zigUnparser.js +460 -0
- package/build/zigUnparser.test.d.ts +1 -0
- package/build/zigUnparser.test.js +24 -0
- package/build/zipParser.js +19 -32
- package/build/zipUnparser.js +19 -7
- package/build/zipUnparser.test.js +1 -1
- package/node_modules-@types/s-expression/index.d.ts +5 -0
- package/package.json +25 -6
- package/src/androidPackageParser.ts +33 -60
- package/src/arbitraryDalvikBytecode.ts +39 -31
- package/src/arbitraryDalvikExecutable.ts +65 -20
- package/src/arbitraryJava.ts +804 -0
- package/src/arbitraryJavaScript.ts +410 -0
- package/src/arbitraryZig.ts +380 -0
- package/src/arrayParser.ts +1 -3
- package/src/backsmali.ts +35 -4
- package/src/bash.ts +127 -0
- package/src/bashParser.test.ts +590 -0
- package/src/bashParser.ts +498 -0
- package/src/dalvikBytecodeParser/addressConversion.ts +496 -0
- package/src/dalvikBytecodeParser/formatParsers.ts +19 -29
- package/src/dalvikBytecodeParser.test-d.ts +310 -0
- package/src/dalvikBytecodeParser.ts +194 -69
- package/src/dalvikBytecodeUnparser/formatUnparsers.ts +27 -26
- package/src/dalvikBytecodeUnparser.test.ts +7 -7
- package/src/dalvikBytecodeUnparser.ts +31 -30
- package/src/dalvikExecutable.test-d.ts +132 -0
- package/src/dalvikExecutable.ts +3 -3
- package/src/dalvikExecutableParser/typedNumbers.ts +11 -0
- package/src/dalvikExecutableParser.test.ts +37 -3
- package/src/dalvikExecutableParser.test.ts.md +163 -2
- package/src/dalvikExecutableParser.test.ts.snap +0 -0
- package/src/dalvikExecutableParser.ts +121 -139
- package/src/dalvikExecutableParserAgainstSmaliParser.test.ts +4 -0
- package/src/dalvikExecutableUnparser/poolScanners.ts +6 -6
- package/src/dalvikExecutableUnparser/sectionUnparsers.ts +38 -14
- package/src/dalvikExecutableUnparser.test.ts +3 -2
- package/src/dalvikExecutableUnparser.ts +4 -4
- package/src/disjunctionParser.test-d.ts +105 -0
- package/src/disjunctionParser.ts +18 -15
- package/src/elementSwitchParser.test-d.ts +74 -0
- package/src/elementSwitchParser.ts +51 -0
- package/src/exactSequenceParser.test-d.ts +43 -0
- package/src/exactSequenceParser.ts +13 -8
- package/src/fetchCid.ts +2 -76
- package/src/index.test.ts +22 -1
- package/src/index.ts +119 -2
- package/src/inputReader.ts +53 -0
- package/src/java.ts +708 -0
- package/src/javaKeyStoreParser.ts +18 -32
- package/src/javaParser.test.ts +1592 -0
- package/src/javaParser.ts +2640 -0
- package/src/javaScript.ts +36 -0
- package/src/javaScriptParser.ts +57 -0
- package/src/javaScriptUnparser.test.ts +37 -0
- package/src/javaScriptUnparser.ts +7 -0
- package/src/javaUnparser.test.ts +37 -0
- package/src/javaUnparser.ts +640 -0
- package/src/jsonParser.ts +6 -27
- package/src/lookaheadParser.ts +2 -6
- package/src/negativeLookaheadParser.ts +1 -3
- package/src/nonEmptyArrayParser.ts +1 -3
- package/src/objectParser.test-d.ts +152 -0
- package/src/objectParser.test.ts +71 -0
- package/src/objectParser.ts +69 -0
- package/src/optionalParser.ts +1 -3
- package/src/parser.test.ts +151 -4
- package/src/parser.ts +11 -1
- package/src/parserConsumedSequenceParser.ts +2 -4
- package/src/parserContext.ts +26 -11
- package/src/parserError.ts +17 -3
- package/src/regexpParser.test.ts +264 -0
- package/src/regexpParser.ts +126 -0
- package/src/regularExpression.ts +24 -0
- package/src/regularExpressionParser.test.ts +102 -0
- package/src/regularExpressionParser.ts +920 -0
- package/src/separatedArrayParser.ts +1 -3
- package/src/separatedNonEmptyArrayParser.ts +1 -3
- package/src/sliceBoundedParser.test.ts +2 -2
- package/src/sliceBoundedParser.ts +15 -19
- package/src/smaliParser.test.ts +64 -0
- package/src/smaliParser.test.ts.md +12 -12
- package/src/smaliParser.test.ts.snap +0 -0
- package/src/smaliParser.ts +246 -534
- package/src/stringEscapes.ts +253 -0
- package/src/symbolicExpression.ts +17 -0
- package/src/symbolicExpressionParser.test.ts +466 -0
- package/src/symbolicExpressionParser.ts +190 -0
- package/src/terminatedArrayParser.test.ts +9 -6
- package/src/terminatedArrayParser.ts +25 -29
- package/src/tupleParser.ts +21 -18
- package/src/unionParser.test-d.ts +105 -0
- package/src/unionParser.test.ts +18 -17
- package/src/unionParser.ts +28 -16
- package/src/zig.ts +411 -0
- package/src/zigParser.test.ts +1693 -0
- package/src/zigParser.ts +1745 -0
- package/src/zigUnparser.test.ts +37 -0
- package/src/zigUnparser.ts +615 -0
- package/src/zipParser.ts +20 -56
- package/src/zipUnparser.test.ts +1 -1
- package/src/zipUnparser.ts +22 -7
- package/tsconfig.json +2 -2
- package/build/exactElementSwitchParser.d.ts +0 -3
- package/src/exactElementSwitchParser.ts +0 -41
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { testProp, fc } from '@fast-check/ava';
|
|
2
|
+
import { regularExpressionParser } from './regularExpressionParser.js';
|
|
3
|
+
const seed = process.env.SEED ? Number(process.env.SEED) : undefined;
|
|
4
|
+
// Import directly from file path to bypass package exports
|
|
5
|
+
// eslint-disable-next-line import/no-unresolved
|
|
6
|
+
import { parseRegExpString } from '../node_modules/@gruhn/regex-utils/dist/regex-parser.js';
|
|
7
|
+
import { runParser } from './parser.js';
|
|
8
|
+
import { stringParserInputCompanion } from './parserInputCompanion.js';
|
|
9
|
+
import { arbitrarilySlicedAsyncIterator } from './arbitrarilySlicedAsyncInterator.js';
|
|
10
|
+
// Normalize AST for comparison - removes hashes from CharSets and normalizes structure
|
|
11
|
+
function normalizeCharacterSet(charset) {
|
|
12
|
+
if (charset.type === 'empty') {
|
|
13
|
+
return { type: 'empty' };
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
type: 'node',
|
|
17
|
+
range: { start: charset.range.start, end: charset.range.end },
|
|
18
|
+
left: normalizeCharacterSet(charset.left),
|
|
19
|
+
right: normalizeCharacterSet(charset.right),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function normalizeRegularExpression(ast) {
|
|
23
|
+
switch (ast.type) {
|
|
24
|
+
case 'epsilon':
|
|
25
|
+
return { type: 'epsilon' };
|
|
26
|
+
case 'literal':
|
|
27
|
+
return { type: 'literal', charset: normalizeCharacterSet(ast.charset) };
|
|
28
|
+
case 'concat':
|
|
29
|
+
return { type: 'concat', left: normalizeRegularExpression(ast.left), right: normalizeRegularExpression(ast.right) };
|
|
30
|
+
case 'union':
|
|
31
|
+
return { type: 'union', left: normalizeRegularExpression(ast.left), right: normalizeRegularExpression(ast.right) };
|
|
32
|
+
case 'star':
|
|
33
|
+
return { type: 'star', inner: normalizeRegularExpression(ast.inner) };
|
|
34
|
+
case 'plus':
|
|
35
|
+
return { type: 'plus', inner: normalizeRegularExpression(ast.inner) };
|
|
36
|
+
case 'optional':
|
|
37
|
+
return { type: 'optional', inner: normalizeRegularExpression(ast.inner) };
|
|
38
|
+
case 'repeat':
|
|
39
|
+
return { type: 'repeat', inner: normalizeRegularExpression(ast.inner), bounds: ast.bounds };
|
|
40
|
+
case 'capture-group':
|
|
41
|
+
if (ast.name !== undefined) {
|
|
42
|
+
return { type: 'capture-group', inner: normalizeRegularExpression(ast.inner), name: ast.name };
|
|
43
|
+
}
|
|
44
|
+
return { type: 'capture-group', inner: normalizeRegularExpression(ast.inner) };
|
|
45
|
+
case 'lookahead':
|
|
46
|
+
return { type: 'lookahead', isPositive: ast.isPositive, inner: normalizeRegularExpression(ast.inner), right: normalizeRegularExpression(ast.right) };
|
|
47
|
+
case 'start-anchor':
|
|
48
|
+
return { type: 'start-anchor', left: normalizeRegularExpression(ast.left), right: normalizeRegularExpression(ast.right) };
|
|
49
|
+
case 'end-anchor':
|
|
50
|
+
return { type: 'end-anchor', left: normalizeRegularExpression(ast.left), right: normalizeRegularExpression(ast.right) };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// Generate regex patterns that are likely to be supported
|
|
54
|
+
const supportedRegexArbitrary = fc.stringMatching(/^([a-zA-Z0-9]|\\[dDwWsS.]|\[(\^)?([a-zA-Z0-9](-[a-zA-Z0-9])?|\\[dDwWsS])*\]|\.|\((\?[:=!])?[a-zA-Z0-9]*\)|[*+?]|\{[0-9]+(,[0-9]*)?\}|\||\^|\$)*$/).filter(s => {
|
|
55
|
+
// Filter out patterns that JavaScript doesn't support
|
|
56
|
+
try {
|
|
57
|
+
new RegExp(s);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
// Filter out patterns that @gruhn/regex-utils doesn't support
|
|
63
|
+
try {
|
|
64
|
+
parseRegExpString(s);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
// Filter out quantified lookaheads - @gruhn/regex-utils has a bug where it treats
|
|
70
|
+
// quantifiers after lookaheads as literals instead of quantifiers.
|
|
71
|
+
// See: https://github.com/gruhn/regex-utils/issues/13
|
|
72
|
+
// JavaScript allows (?=a){2} but @gruhn/regex-utils parses {2} as literal text.
|
|
73
|
+
if (/\(\?[=!][^)]*\)[*+?]|\(\?[=!][^)]*\)\{[0-9]/.test(s)) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
});
|
|
78
|
+
testProp('regularExpressionParser matches @gruhn/regex-utils', [
|
|
79
|
+
arbitrarilySlicedAsyncIterator(supportedRegexArbitrary),
|
|
80
|
+
], async (t, [regexStr, regexStringChunkIterator]) => {
|
|
81
|
+
const expected = normalizeRegularExpression(parseRegExpString(regexStr));
|
|
82
|
+
const actual = normalizeRegularExpression(await runParser(regularExpressionParser, regexStringChunkIterator, stringParserInputCompanion, {
|
|
83
|
+
errorJoinMode: 'none',
|
|
84
|
+
}));
|
|
85
|
+
t.deepEqual(actual, expected);
|
|
86
|
+
}, {
|
|
87
|
+
verbose: true,
|
|
88
|
+
seed,
|
|
89
|
+
});
|
|
@@ -1,3 +1,55 @@
|
|
|
1
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
+
}
|
|
18
|
+
else if (async) {
|
|
19
|
+
env.stack.push({ async: true });
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
+
return function (env) {
|
|
25
|
+
function fail(e) {
|
|
26
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
+
env.hasError = true;
|
|
28
|
+
}
|
|
29
|
+
var r, s = 0;
|
|
30
|
+
function next() {
|
|
31
|
+
while (r = env.stack.pop()) {
|
|
32
|
+
try {
|
|
33
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
+
if (r.dispose) {
|
|
35
|
+
var result = r.dispose.call(r.value);
|
|
36
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
+
}
|
|
38
|
+
else s |= 1;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
+
if (env.hasError) throw env.error;
|
|
46
|
+
}
|
|
47
|
+
return next();
|
|
48
|
+
};
|
|
49
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
+
var e = new Error(message);
|
|
51
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
+
});
|
|
1
53
|
import { getParserName, setParserName } from './parser.js';
|
|
2
54
|
import { isParserParsingFailedError } from './parserError.js';
|
|
3
55
|
import { promiseCompose } from './promiseCompose.js';
|
|
@@ -11,26 +63,33 @@ export const createSeparatedArrayParser = (elementParser, separatorParser) => {
|
|
|
11
63
|
let parser = elementParser;
|
|
12
64
|
const elements = [];
|
|
13
65
|
while (true) {
|
|
14
|
-
const
|
|
15
|
-
const initialPosition = elementParserContext.position;
|
|
66
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
16
67
|
try {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
68
|
+
const elementParserContext = __addDisposableResource(env_1, parserContext.lookahead(), false);
|
|
69
|
+
const initialPosition = elementParserContext.position;
|
|
70
|
+
try {
|
|
71
|
+
const element = await parser(elementParserContext);
|
|
72
|
+
if (elementParserContext.position === initialPosition) {
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
elements.push(element);
|
|
76
|
+
elementParserContext.unlookahead();
|
|
20
77
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
break;
|
|
78
|
+
catch (error) {
|
|
79
|
+
if (isParserParsingFailedError(error)) {
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
throw error;
|
|
27
83
|
}
|
|
28
|
-
|
|
84
|
+
parser = separatorThenElementParser;
|
|
85
|
+
}
|
|
86
|
+
catch (e_1) {
|
|
87
|
+
env_1.error = e_1;
|
|
88
|
+
env_1.hasError = true;
|
|
29
89
|
}
|
|
30
90
|
finally {
|
|
31
|
-
|
|
91
|
+
__disposeResources(env_1);
|
|
32
92
|
}
|
|
33
|
-
parser = separatorThenElementParser;
|
|
34
93
|
}
|
|
35
94
|
return elements;
|
|
36
95
|
};
|
|
@@ -1,3 +1,55 @@
|
|
|
1
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
+
}
|
|
18
|
+
else if (async) {
|
|
19
|
+
env.stack.push({ async: true });
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
+
return function (env) {
|
|
25
|
+
function fail(e) {
|
|
26
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
+
env.hasError = true;
|
|
28
|
+
}
|
|
29
|
+
var r, s = 0;
|
|
30
|
+
function next() {
|
|
31
|
+
while (r = env.stack.pop()) {
|
|
32
|
+
try {
|
|
33
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
+
if (r.dispose) {
|
|
35
|
+
var result = r.dispose.call(r.value);
|
|
36
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
+
}
|
|
38
|
+
else s |= 1;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
+
if (env.hasError) throw env.error;
|
|
46
|
+
}
|
|
47
|
+
return next();
|
|
48
|
+
};
|
|
49
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
+
var e = new Error(message);
|
|
51
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
+
});
|
|
1
53
|
import { getParserName, setParserName } from './parser.js';
|
|
2
54
|
import { isParserParsingFailedError } from './parserError.js';
|
|
3
55
|
import { promiseCompose } from './promiseCompose.js';
|
|
@@ -11,26 +63,33 @@ export const createSeparatedNonEmptyArrayParser = (elementParser, separatorParse
|
|
|
11
63
|
let parser = elementParser;
|
|
12
64
|
const elements = [];
|
|
13
65
|
while (true) {
|
|
14
|
-
const
|
|
15
|
-
const initialPosition = elementParserContext.position;
|
|
66
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
16
67
|
try {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
68
|
+
const elementParserContext = __addDisposableResource(env_1, parserContext.lookahead(), false);
|
|
69
|
+
const initialPosition = elementParserContext.position;
|
|
70
|
+
try {
|
|
71
|
+
const element = await parser(elementParserContext);
|
|
72
|
+
if (elementParserContext.position === initialPosition) {
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
elements.push(element);
|
|
76
|
+
elementParserContext.unlookahead();
|
|
20
77
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
break;
|
|
78
|
+
catch (error) {
|
|
79
|
+
if (isParserParsingFailedError(error)) {
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
throw error;
|
|
27
83
|
}
|
|
28
|
-
|
|
84
|
+
parser = separatorThenElementParser;
|
|
85
|
+
}
|
|
86
|
+
catch (e_1) {
|
|
87
|
+
env_1.error = e_1;
|
|
88
|
+
env_1.hasError = true;
|
|
29
89
|
}
|
|
30
90
|
finally {
|
|
31
|
-
|
|
91
|
+
__disposeResources(env_1);
|
|
32
92
|
}
|
|
33
|
-
parser = separatorThenElementParser;
|
|
34
93
|
}
|
|
35
94
|
parserContext.invariant(elements.length > 0, 'Expected elementParser (%s) to match at least once', getParserName(elementParser, 'anonymousSeparatedNonEmptyArrayChild'));
|
|
36
95
|
return elements;
|
|
@@ -1,19 +1,76 @@
|
|
|
1
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
+
}
|
|
18
|
+
else if (async) {
|
|
19
|
+
env.stack.push({ async: true });
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
+
return function (env) {
|
|
25
|
+
function fail(e) {
|
|
26
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
+
env.hasError = true;
|
|
28
|
+
}
|
|
29
|
+
var r, s = 0;
|
|
30
|
+
function next() {
|
|
31
|
+
while (r = env.stack.pop()) {
|
|
32
|
+
try {
|
|
33
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
+
if (r.dispose) {
|
|
35
|
+
var result = r.dispose.call(r.value);
|
|
36
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
+
}
|
|
38
|
+
else s |= 1;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
+
if (env.hasError) throw env.error;
|
|
46
|
+
}
|
|
47
|
+
return next();
|
|
48
|
+
};
|
|
49
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
+
var e = new Error(message);
|
|
51
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
+
});
|
|
1
53
|
import { getParserName, setParserName } from './parser.js';
|
|
2
54
|
export const createSliceBoundedParser = (childParser, sliceEnd, mustConsumeAll = true) => {
|
|
3
55
|
const sliceBoundedParser = async (parserContext) => {
|
|
4
|
-
const
|
|
5
|
-
const childParserContext = parserContext.lookahead({
|
|
6
|
-
sliceEnd: absoluteSliceEnd,
|
|
7
|
-
});
|
|
56
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
8
57
|
try {
|
|
58
|
+
const absoluteSliceEnd = parserContext.position + sliceEnd;
|
|
59
|
+
const childParserContext = __addDisposableResource(env_1, parserContext.lookahead({
|
|
60
|
+
sliceEnd: absoluteSliceEnd,
|
|
61
|
+
}), false);
|
|
9
62
|
const value = await childParser(childParserContext);
|
|
10
63
|
childParserContext.invariant((!mustConsumeAll
|
|
11
64
|
|| childParserContext.position === absoluteSliceEnd), 'child parser must consume all input in the slice (%s in total, up to position %s), instead consumed %s up to position %s', sliceEnd, absoluteSliceEnd, childParserContext.position - parserContext.position, childParserContext.position);
|
|
12
65
|
childParserContext.unlookahead();
|
|
13
66
|
return value;
|
|
14
67
|
}
|
|
68
|
+
catch (e_1) {
|
|
69
|
+
env_1.error = e_1;
|
|
70
|
+
env_1.hasError = true;
|
|
71
|
+
}
|
|
15
72
|
finally {
|
|
16
|
-
|
|
73
|
+
__disposeResources(env_1);
|
|
17
74
|
}
|
|
18
75
|
};
|
|
19
76
|
setParserName(sliceBoundedParser, [
|
package/build/smaliParser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Simplify } from 'type-fest';
|
|
2
|
-
import { type
|
|
2
|
+
import { type DalvikBytecodeOperation, type DalvikBytecode } from './dalvikBytecodeParser/addressConversion.js';
|
|
3
3
|
import { type DalvikExecutableClassDefinition, type DalvikExecutableField, type DalvikExecutableFieldWithAccess, type DalvikExecutableMethod, type DalvikExecutableMethodWithAccess } from './dalvikExecutable.js';
|
|
4
4
|
import { type Parser } from './parser.js';
|
|
5
5
|
import { type IndexIntoMethodIds } from './dalvikExecutableParser/typedNumbers.js';
|
|
@@ -43,20 +43,20 @@ type SmaliCodeParameter = {
|
|
|
43
43
|
annotation: SmaliAnnotation | undefined;
|
|
44
44
|
};
|
|
45
45
|
export declare const smaliCodeParameterParser: Parser<SmaliCodeParameter, string>;
|
|
46
|
-
type
|
|
47
|
-
|
|
48
|
-
} ? Simplify<Omit<T, '
|
|
46
|
+
type SmaliCodeOperationFromDalvikOperation<T extends DalvikBytecodeOperation> = T extends {
|
|
47
|
+
targetInstructionIndices: number[];
|
|
48
|
+
} ? Simplify<Omit<T, 'targetInstructionIndices'> & {
|
|
49
49
|
branchOffsetIndices: number[];
|
|
50
50
|
}> : T extends {
|
|
51
|
-
|
|
52
|
-
} ? Simplify<Omit<T, '
|
|
51
|
+
targetInstructionIndex: number;
|
|
52
|
+
} ? Simplify<Omit<T, 'targetInstructionIndex'> & {
|
|
53
53
|
branchOffsetIndex: number;
|
|
54
54
|
}> : T extends {
|
|
55
55
|
methodIndex: IndexIntoMethodIds;
|
|
56
56
|
} ? Simplify<Omit<T, 'methodIndex'> & {
|
|
57
57
|
method: DalvikExecutableMethod;
|
|
58
58
|
}> : T;
|
|
59
|
-
type SmaliCodeOperation =
|
|
59
|
+
type SmaliCodeOperation = SmaliCodeOperationFromDalvikOperation<DalvikBytecodeOperation>;
|
|
60
60
|
export declare const smaliCodeOperationParser: Parser<SmaliCodeOperation, string>;
|
|
61
61
|
type SmaliMethod<DalvikBytecode> = {
|
|
62
62
|
dalvikExecutableMethodWithAccess: DalvikExecutableMethodWithAccess<DalvikBytecode>;
|