@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.
Files changed (380) hide show
  1. package/build/allSettledStream.js +32 -14
  2. package/build/allSettledStream.test.js +32 -0
  3. package/build/androidPackage.d.ts +39 -0
  4. package/build/androidPackageParser.d.ts +17 -0
  5. package/build/androidPackageParser.js +183 -0
  6. package/build/{apkParser.test.js → androidPackageParser.test.js} +7 -7
  7. package/build/androidPackageUnparser.d.ts +4 -0
  8. package/build/androidPackageUnparser.js +90 -0
  9. package/build/androidPackageUnparser.test.js +26 -0
  10. package/build/arbitrarilySlicedAsyncInterable.d.ts +3 -1
  11. package/build/arbitrarilySlicedAsyncInterable.js +3 -3
  12. package/build/arbitraryFileSystemEntry.js +1 -1
  13. package/build/arbitraryZip.d.ts +1 -1
  14. package/build/arbitraryZip.js +13 -19
  15. package/build/arbitraryZipPermissions.d.ts +1 -8
  16. package/build/arbitraryZipPermissions.js +1 -16
  17. package/build/arbitraryZipStream.d.ts +1 -1
  18. package/build/arbitraryZipStream.js +3 -3
  19. package/build/arrayParser.d.ts +1 -1
  20. package/build/arrayParser.js +2 -2
  21. package/build/arrayParser.test.js +4 -4
  22. package/build/arrayUnparser.d.ts +2 -0
  23. package/build/arrayUnparser.js +8 -0
  24. package/build/backsmali.d.ts +1 -0
  25. package/build/backsmali.js +22 -0
  26. package/build/bsonParser.js +6 -2
  27. package/build/bsonParser.test.js +2 -2
  28. package/build/{parserInvariant.d.ts → customInvariant.d.ts} +1 -1
  29. package/build/{parserInvariant.js → customInvariant.js} +1 -1
  30. package/build/dalvikBytecodeParser/formatParsers.d.ts +97 -0
  31. package/build/dalvikBytecodeParser/formatParsers.js +169 -0
  32. package/build/dalvikBytecodeParser.d.ts +107 -0
  33. package/build/dalvikBytecodeParser.js +836 -0
  34. package/build/dalvikExecutable.d.ts +158 -0
  35. package/build/dalvikExecutable.js +20 -0
  36. package/build/dalvikExecutableParser/stringSyntaxParser.d.ts +4 -0
  37. package/build/dalvikExecutableParser/stringSyntaxParser.js +76 -0
  38. package/build/dalvikExecutableParser/typeParsers.d.ts +10 -0
  39. package/build/dalvikExecutableParser/typeParsers.js +34 -0
  40. package/build/dalvikExecutableParser/typedNumbers.d.ts +90 -0
  41. package/build/dalvikExecutableParser/typedNumbers.js +19 -0
  42. package/build/dalvikExecutableParser.d.ts +5 -0
  43. package/build/dalvikExecutableParser.js +1439 -0
  44. package/build/dalvikExecutableParser.test.js +70 -0
  45. package/build/dalvikExecutableParserAgainstSmaliParser.test.js +298 -0
  46. package/build/debugLogInputParser.d.ts +4 -0
  47. package/build/debugLogInputParser.js +16 -0
  48. package/build/debugLogParser.d.ts +1 -1
  49. package/build/debugLogParser.js +15 -4
  50. package/build/disjunctionParser.d.ts +2 -1
  51. package/build/disjunctionParser.js +4 -2
  52. package/build/elementParser.d.ts +2 -2
  53. package/build/elementParser.js +1 -1
  54. package/build/elementTerminatedArrayParser.d.ts +3 -0
  55. package/build/elementTerminatedArrayParser.js +18 -0
  56. package/build/elementTerminatedArrayParser.test.js +52 -0
  57. package/build/elementTerminatedSequenceArrayParser.d.ts +3 -0
  58. package/build/elementTerminatedSequenceArrayParser.js +32 -0
  59. package/build/elementTerminatedSequenceArrayParser.test.js +34 -0
  60. package/build/elementTerminatedSequenceParser.d.ts +3 -0
  61. package/build/elementTerminatedSequenceParser.js +27 -0
  62. package/build/elementTerminatedSequenceParser.test.js +34 -0
  63. package/build/endOfInputParser.d.ts +2 -2
  64. package/build/exactElementParser.d.ts +1 -1
  65. package/build/exactElementParser.js +10 -5
  66. package/build/exactSequenceParser.d.ts +2 -1
  67. package/build/exactSequenceParser.js +12 -2
  68. package/build/fetchCid.d.ts +1 -0
  69. package/build/fetchCid.js +107 -0
  70. package/build/fixedLengthSequenceParser.d.ts +1 -0
  71. package/build/fixedLengthSequenceParser.js +18 -1
  72. package/build/fixedLengthSequenceParser.test.js +41 -0
  73. package/build/hasExecutable.d.ts +1 -0
  74. package/build/hasExecutable.js +8 -0
  75. package/build/highResolutionTimer.d.ts +16 -0
  76. package/build/highResolutionTimer.js +42 -0
  77. package/build/index.d.ts +5 -2
  78. package/build/index.js +3 -0
  79. package/build/inputReader.d.ts +14 -3
  80. package/build/inputReader.js +43 -6
  81. package/build/inputReader.test.js +172 -7
  82. package/build/inputReaderState.d.ts +10 -0
  83. package/build/inputReaderState.js +16 -0
  84. package/build/inspect.d.ts +1 -0
  85. package/build/inspect.js +7 -0
  86. package/build/javaKeyStoreParser.d.ts +2 -0
  87. package/build/javaKeyStoreParser.js +67 -0
  88. package/build/javaKeyStoreParser.test.d.ts +1 -0
  89. package/build/javaKeyStoreParser.test.js +16 -0
  90. package/build/jsonParser.d.ts +2 -0
  91. package/build/jsonParser.js +13 -15
  92. package/build/jsonParser.test.js +2 -2
  93. package/build/leb128Parser.d.ts +7 -0
  94. package/build/leb128Parser.js +82 -0
  95. package/build/leb128Parser.test.d.ts +1 -0
  96. package/build/leb128Parser.test.js +107 -0
  97. package/build/listParser.d.ts +1 -1
  98. package/build/listParser.js +5 -5
  99. package/build/lookaheadParser.d.ts +2 -0
  100. package/build/lookaheadParser.js +14 -0
  101. package/build/{negativeLookahead.d.ts → negativeLookaheadParser.d.ts} +1 -1
  102. package/build/negativeLookaheadParser.js +24 -0
  103. package/build/negativeLookaheadParser.test.d.ts +1 -0
  104. package/build/negativeLookaheadParser.test.js +30 -0
  105. package/build/nonEmptyArrayParser.d.ts +2 -0
  106. package/build/nonEmptyArrayParser.js +32 -0
  107. package/build/nonEmptyArrayParser.test.d.ts +1 -0
  108. package/build/nonEmptyArrayParser.test.js +16 -0
  109. package/build/optionalParser.d.ts +1 -1
  110. package/build/optionalParser.js +2 -2
  111. package/build/parser.d.ts +13 -4
  112. package/build/parser.js +67 -32
  113. package/build/parser.test.js +94 -27
  114. package/build/parserAccessorParser.d.ts +1 -1
  115. package/build/parserAccessorParser.js +9 -1
  116. package/build/parserConsumedSequenceParser.d.ts +2 -0
  117. package/build/parserConsumedSequenceParser.js +22 -0
  118. package/build/parserContext.d.ts +20 -6
  119. package/build/parserContext.js +70 -40
  120. package/build/parserContext.test.js +34 -7
  121. package/build/parserCreatorCompose.d.ts +4 -3
  122. package/build/parserCreatorCompose.js +9 -3
  123. package/build/parserError.d.ts +6 -0
  124. package/build/parserError.js +6 -6
  125. package/build/parserImplementationInvariant.d.ts +1 -1
  126. package/build/parserImplementationInvariant.js +2 -2
  127. package/build/parserInputCompanion.d.ts +35 -0
  128. package/build/parserInputCompanion.js +68 -0
  129. package/build/promiseCompose.d.ts +1 -1
  130. package/build/promiseCompose.js +12 -1
  131. package/build/promiseSettled.d.ts +1 -0
  132. package/build/promiseSettled.js +4 -0
  133. package/build/quantifierParser.d.ts +2 -0
  134. package/build/quantifierParser.js +17 -0
  135. package/build/separatedArrayParser.d.ts +2 -0
  136. package/build/separatedArrayParser.js +39 -0
  137. package/build/separatedArrayParser.test.d.ts +1 -0
  138. package/build/separatedArrayParser.test.js +21 -0
  139. package/build/sequenceBuffer.d.ts +13 -3
  140. package/build/sequenceBuffer.js +60 -8
  141. package/build/sequenceBuffer.test.js +59 -2
  142. package/build/sequenceTerminatedSequenceParser.d.ts +5 -0
  143. package/build/sequenceTerminatedSequenceParser.js +32 -0
  144. package/build/sequenceTerminatedSequenceParser.test.d.ts +1 -0
  145. package/build/sequenceTerminatedSequenceParser.test.js +37 -0
  146. package/build/sequenceUnparser.d.ts +2 -0
  147. package/build/sequenceUnparser.js +6 -0
  148. package/build/skipParser.d.ts +1 -1
  149. package/build/skipParser.js +4 -2
  150. package/build/skipToParser.d.ts +2 -0
  151. package/build/skipToParser.js +11 -0
  152. package/build/sliceBoundedParser.d.ts +2 -2
  153. package/build/sliceBoundedParser.js +8 -3
  154. package/build/sliceBoundedParser.test.js +37 -3
  155. package/build/smali.d.ts +1 -0
  156. package/build/smali.js +17 -0
  157. package/build/smaliParser.d.ts +12 -0
  158. package/build/smaliParser.js +656 -0
  159. package/build/smaliParser.test.d.ts +1 -0
  160. package/build/smaliParser.test.js +115 -0
  161. package/build/terminatedArrayParser.d.ts +4 -2
  162. package/build/terminatedArrayParser.js +82 -5
  163. package/build/terminatedArrayParser.test.d.ts +1 -0
  164. package/build/terminatedArrayParser.test.js +131 -0
  165. package/build/toAsyncIterable.d.ts +1 -0
  166. package/build/toAsyncIterable.js +7 -0
  167. package/build/toAsyncIterator.d.ts +1 -0
  168. package/build/toAsyncIterator.js +33 -0
  169. package/build/tupleParser.d.ts +4 -0
  170. package/build/tupleParser.js +1 -5
  171. package/build/uint8Array.d.ts +1 -0
  172. package/build/uint8Array.js +7 -0
  173. package/build/unionParser.d.ts +2 -1
  174. package/build/unionParser.js +27 -12
  175. package/build/unionParser.test.d.ts +1 -0
  176. package/build/unionParser.test.js +60 -0
  177. package/build/unparser.d.ts +8 -0
  178. package/build/unparser.js +104 -0
  179. package/build/unparser.test.d.ts +1 -0
  180. package/build/unparser.test.js +150 -0
  181. package/build/unparserContext.d.ts +31 -0
  182. package/build/unparserContext.js +74 -0
  183. package/build/unparserError.d.ts +9 -0
  184. package/build/unparserError.js +9 -0
  185. package/build/unparserImplementationInvariant.d.ts +2 -0
  186. package/build/unparserImplementationInvariant.js +5 -0
  187. package/build/unparserOutputCompanion.d.ts +15 -0
  188. package/build/unparserOutputCompanion.js +13 -0
  189. package/build/zip.d.ts +9 -17
  190. package/build/zipParser.d.ts +20 -12
  191. package/build/zipParser.js +83 -71
  192. package/build/zipParser.test.js +2 -7
  193. package/build/zipUnparser.d.ts +8 -0
  194. package/build/zipUnparser.js +200 -0
  195. package/build/zipUnparser.test.d.ts +1 -0
  196. package/build/zipUnparser.test.js +80 -0
  197. package/package.json +26 -8
  198. package/src/allSettledStream.test.ts +40 -0
  199. package/src/allSettledStream.ts +47 -15
  200. package/src/androidPackage.ts +48 -0
  201. package/src/{apkParser.test.ts → androidPackageParser.test.ts} +7 -8
  202. package/src/androidPackageParser.test.ts.md +271 -0
  203. package/src/androidPackageParser.test.ts.snap +0 -0
  204. package/src/androidPackageParser.ts +440 -0
  205. package/src/androidPackageUnparser.test.ts +36 -0
  206. package/src/androidPackageUnparser.ts +120 -0
  207. package/src/arbitrarilySlicedAsyncInterable.ts +7 -2
  208. package/src/arbitraryFileSystemEntry.ts +2 -4
  209. package/src/arbitraryZip.ts +20 -27
  210. package/src/arbitraryZipPermissions.ts +0 -25
  211. package/src/arbitraryZipStream.ts +4 -4
  212. package/src/arrayParser.test.ts +4 -4
  213. package/src/arrayParser.ts +3 -2
  214. package/src/arrayUnparser.ts +13 -0
  215. package/src/backsmali.ts +30 -0
  216. package/src/bsonParser.test.ts +2 -2
  217. package/src/bsonParser.ts +16 -5
  218. package/src/{parserInvariant.ts → customInvariant.ts} +2 -2
  219. package/src/dalvikBytecodeParser/formatParsers.ts +421 -0
  220. package/src/dalvikBytecodeParser.ts +2074 -0
  221. package/src/dalvikExecutable.ts +220 -0
  222. package/src/dalvikExecutableParser/stringSyntaxParser.ts +145 -0
  223. package/src/dalvikExecutableParser/typeParsers.ts +65 -0
  224. package/src/dalvikExecutableParser/typedNumbers.ts +57 -0
  225. package/src/dalvikExecutableParser.test.ts +89 -0
  226. package/src/dalvikExecutableParser.test.ts.md +634 -0
  227. package/src/dalvikExecutableParser.test.ts.snap +0 -0
  228. package/src/dalvikExecutableParser.ts +2768 -0
  229. package/src/dalvikExecutableParserAgainstSmaliParser.test.ts +346 -0
  230. package/src/debugLogInputParser.ts +28 -0
  231. package/src/debugLogParser.ts +20 -4
  232. package/src/disjunctionParser.ts +10 -5
  233. package/src/elementParser.ts +3 -3
  234. package/src/elementTerminatedArrayParser.test.ts +99 -0
  235. package/src/elementTerminatedArrayParser.ts +31 -0
  236. package/src/elementTerminatedSequenceArrayParser.test.ts +54 -0
  237. package/src/elementTerminatedSequenceArrayParser.ts +52 -0
  238. package/src/elementTerminatedSequenceParser.test.ts +54 -0
  239. package/src/elementTerminatedSequenceParser.ts +43 -0
  240. package/src/endOfInputParser.ts +4 -4
  241. package/src/exactElementParser.ts +18 -12
  242. package/src/exactSequenceParser.ts +24 -3
  243. package/src/fetchCid.ts +125 -0
  244. package/src/fixedLengthSequenceParser.test.ts +77 -0
  245. package/src/fixedLengthSequenceParser.ts +28 -1
  246. package/src/hasExecutable.ts +11 -0
  247. package/src/highResolutionTimer.ts +49 -0
  248. package/src/index.ts +15 -2
  249. package/src/inputReader.test.ts +216 -7
  250. package/src/inputReader.ts +80 -5
  251. package/src/inputReaderState.ts +33 -0
  252. package/src/inspect.ts +9 -0
  253. package/src/javaKeyStore.ts +0 -0
  254. package/src/javaKeyStoreParser.test.ts +22 -0
  255. package/src/javaKeyStoreParser.test.ts.md +103 -0
  256. package/src/javaKeyStoreParser.test.ts.snap +0 -0
  257. package/src/javaKeyStoreParser.ts +136 -0
  258. package/src/jsonParser.test.ts +2 -2
  259. package/src/jsonParser.ts +23 -34
  260. package/src/leb128Parser.test.ts +171 -0
  261. package/src/leb128Parser.ts +125 -0
  262. package/src/listParser.ts +6 -6
  263. package/src/lookaheadParser.ts +19 -0
  264. package/src/negativeLookaheadParser.test.ts +53 -0
  265. package/src/negativeLookaheadParser.ts +36 -0
  266. package/src/nonEmptyArrayParser.test.ts +20 -0
  267. package/src/nonEmptyArrayParser.ts +44 -0
  268. package/src/optionalParser.ts +4 -3
  269. package/src/parser.test.ts +148 -27
  270. package/src/parser.test.ts.md +21 -21
  271. package/src/parser.test.ts.snap +0 -0
  272. package/src/parser.ts +153 -49
  273. package/src/parserAccessorParser.ts +12 -2
  274. package/src/parserConsumedSequenceParser.ts +29 -0
  275. package/src/parserContext.test.ts +38 -7
  276. package/src/parserContext.ts +127 -51
  277. package/src/parserCreatorCompose.ts +25 -7
  278. package/src/parserError.ts +9 -6
  279. package/src/parserImplementationInvariant.ts +2 -2
  280. package/src/parserInputCompanion.ts +102 -0
  281. package/src/promiseCompose.ts +17 -3
  282. package/src/promiseSettled.ts +6 -0
  283. package/src/quantifierParser.ts +25 -0
  284. package/src/separatedArrayParser.test.ts +34 -0
  285. package/src/separatedArrayParser.ts +55 -0
  286. package/src/sequenceBuffer.test.ts +72 -2
  287. package/src/sequenceBuffer.ts +93 -7
  288. package/src/sequenceTerminatedSequenceParser.test.ts +60 -0
  289. package/src/sequenceTerminatedSequenceParser.ts +62 -0
  290. package/src/sequenceUnparser.ts +9 -0
  291. package/src/skipParser.ts +7 -5
  292. package/src/skipToParser.ts +16 -0
  293. package/src/sliceBoundedParser.test.ts +45 -3
  294. package/src/sliceBoundedParser.ts +21 -3
  295. package/src/smali.ts +24 -0
  296. package/src/smaliParser.test.ts +132 -0
  297. package/src/smaliParser.test.ts.md +2320 -0
  298. package/src/smaliParser.test.ts.snap +0 -0
  299. package/src/smaliParser.ts +1166 -0
  300. package/src/terminatedArrayParser.test.ts +258 -0
  301. package/src/terminatedArrayParser.ts +111 -6
  302. package/src/toAsyncIterable.ts +7 -0
  303. package/src/toAsyncIterator.ts +48 -0
  304. package/src/tupleParser.ts +8 -5
  305. package/src/uint8Array.ts +10 -0
  306. package/src/unionParser.test.ts +79 -0
  307. package/src/unionParser.ts +44 -16
  308. package/src/unparser.test.ts +221 -0
  309. package/src/unparser.ts +209 -0
  310. package/src/unparserContext.ts +127 -0
  311. package/src/unparserError.ts +12 -0
  312. package/src/unparserImplementationInvariant.ts +6 -0
  313. package/src/unparserOutputCompanion.ts +24 -0
  314. package/src/zip.ts +10 -22
  315. package/src/zipParser.test.ts +2 -8
  316. package/src/zipParser.ts +223 -146
  317. package/src/zipUnparser.test.ts +119 -0
  318. package/src/zipUnparser.ts +300 -0
  319. package/build/apk.d.ts +0 -13
  320. package/build/apkParser.d.ts +0 -3
  321. package/build/apkParser.js +0 -135
  322. package/build/arbitraryDosDate.d.ts +0 -2
  323. package/build/arbitraryDosDate.js +0 -8
  324. package/build/arbitraryZipEntry.d.ts +0 -3
  325. package/build/arbitraryZipEntry.js +0 -26
  326. package/build/createDisjunctionParser.d.ts +0 -2
  327. package/build/createDisjunctionParser.js +0 -47
  328. package/build/createExactParser.d.ts +0 -2
  329. package/build/createExactParser.js +0 -12
  330. package/build/createSequentialUnionParser.d.ts +0 -2
  331. package/build/createSequentialUnionParser.js +0 -69
  332. package/build/fixedLengthChunkParser.d.ts +0 -2
  333. package/build/fixedLengthChunkParser.js +0 -12
  334. package/build/fixedLengthParser.d.ts +0 -2
  335. package/build/fixedLengthParser.js +0 -12
  336. package/build/inputChunkBuffer.d.ts +0 -15
  337. package/build/inputChunkBuffer.js +0 -40
  338. package/build/inputChunkBuffer.test.js +0 -34
  339. package/build/inputCompanion.d.ts +0 -18
  340. package/build/inputCompanion.js +0 -28
  341. package/build/invariantDefined.d.ts +0 -1
  342. package/build/invariantDefined.js +0 -5
  343. package/build/invariantIdentity.d.ts +0 -3
  344. package/build/invariantIdentity.js +0 -5
  345. package/build/jsonParser2.d.ts +0 -3
  346. package/build/jsonParser2.js +0 -52
  347. package/build/jsonParser2.test.js +0 -22
  348. package/build/negativeLookahead.js +0 -20
  349. package/build/parserCompose.d.ts +0 -3
  350. package/build/parserCompose.js +0 -7
  351. package/build/parserImplementationInvariantInvariant.d.ts +0 -3
  352. package/build/parserImplementationInvariantInvariant.js +0 -15
  353. package/build/promiseFish.d.ts +0 -1
  354. package/build/promiseFish.js +0 -3
  355. package/build/sequenceParser.d.ts +0 -3
  356. package/build/sequenceParser.js +0 -10
  357. package/build/terminatedSequenceParser.d.ts +0 -2
  358. package/build/terminatedSequenceParser.js +0 -24
  359. package/build/zipEntry.d.ts +0 -28
  360. package/build/zipFile.d.ts +0 -32
  361. package/build/zipFileEntry.d.ts +0 -6
  362. package/src/apk.ts +0 -16
  363. package/src/apkParser.test.ts.md +0 -268
  364. package/src/apkParser.test.ts.snap +0 -0
  365. package/src/apkParser.ts +0 -327
  366. package/src/inputCompanion.ts +0 -43
  367. package/src/invariantDefined.ts +0 -6
  368. package/src/invariantIdentity.ts +0 -8
  369. package/src/negativeLookahead.ts +0 -26
  370. /package/build/{apk.js → androidPackage.js} +0 -0
  371. /package/build/{apkParser.test.d.ts → androidPackageParser.test.d.ts} +0 -0
  372. /package/build/{arbitraryDosPermissions.d.ts → androidPackageUnparser.test.d.ts} +0 -0
  373. /package/build/{arbitraryDosPermissions.js → dalvikExecutableParser.test.d.ts} +0 -0
  374. /package/build/{inputChunkBuffer.test.d.ts → dalvikExecutableParserAgainstSmaliParser.test.d.ts} +0 -0
  375. /package/build/{jsonParser2.test.d.ts → elementTerminatedArrayParser.test.d.ts} +0 -0
  376. /package/build/{parserParsingInvariant.d.ts → elementTerminatedSequenceArrayParser.test.d.ts} +0 -0
  377. /package/build/{parserParsingInvariant.js → elementTerminatedSequenceParser.test.d.ts} +0 -0
  378. /package/build/{zipEntry.js → fixedLengthSequenceParser.test.d.ts} +0 -0
  379. /package/build/{zipFile.js → javaKeyStore.d.ts} +0 -0
  380. /package/build/{zipFileEntry.js → javaKeyStore.js} +0 -0
@@ -0,0 +1,136 @@
1
+ import { createExactSequenceParser } from './exactSequenceParser.js';
2
+ import { createFixedLengthSequenceParser } from './fixedLengthSequenceParser.js';
3
+ import { type Parser, setParserName } from './parser.js';
4
+ import { parserCreatorCompose } from './parserCreatorCompose.js';
5
+ import { promiseCompose } from './promiseCompose.js';
6
+ import { createQuantifierParser } from './quantifierParser.js';
7
+ import { createTupleParser } from './tupleParser.js';
8
+ import { createUnionParser } from './unionParser.js';
9
+
10
+ // https://github.com/openjdk/jdk/blob/c517ffba7d9388e75b5d7bba77e565e71c0a7d76/src/java.base/share/classes/com/sun/crypto/provider/JceKeyStore.java#L512-L553
11
+
12
+ const uint64BEParser: Parser<bigint, Uint8Array> = promiseCompose(
13
+ createFixedLengthSequenceParser(8),
14
+ array => Buffer.from(array).readBigUInt64BE(),
15
+ );
16
+
17
+ setParserName(uint64BEParser, 'uint64BEParser');
18
+
19
+ const uint32BEParser: Parser<number, Uint8Array> = promiseCompose(
20
+ createFixedLengthSequenceParser(4),
21
+ array => Buffer.from(array).readUInt32BE(),
22
+ );
23
+
24
+ setParserName(uint32BEParser, 'uint32BEParser');
25
+
26
+ const uint16BEParser: Parser<number, Uint8Array> = promiseCompose(
27
+ createFixedLengthSequenceParser(2),
28
+ array => Buffer.from(array).readUInt16BE(),
29
+ );
30
+
31
+ setParserName(uint16BEParser, 'uint16BEParser');
32
+
33
+ const createUint32BECountPrefixedParser = <T>(elementParser: Parser<T, Uint8Array>): Parser<T[], Uint8Array> => parserCreatorCompose(
34
+ () => uint32BEParser,
35
+ count => createQuantifierParser(elementParser, count),
36
+ )();
37
+
38
+ const javaModifiedUTF8StringParser: Parser<string, Uint8Array> = promiseCompose(
39
+ parserCreatorCompose(
40
+ () => uint16BEParser,
41
+ length => createFixedLengthSequenceParser(length),
42
+ )(),
43
+ uint8Array => Buffer.from(uint8Array).toString('utf8'), // TODO?: Java Modified UTF-8 decoding
44
+ );
45
+
46
+ const uint32LengthPrefixedUint8ArrayParser = parserCreatorCompose(
47
+ () => uint32BEParser,
48
+ length => createFixedLengthSequenceParser(length),
49
+ )();
50
+
51
+ const javaKeyStoreImplementationParser: Parser<'JKS' | 'JCEKS', Uint8Array> = promiseCompose(
52
+ createUnionParser<Uint8Array, Uint8Array>([
53
+ createExactSequenceParser<Uint8Array>(Buffer.from('feedfeed', 'hex')),
54
+ createExactSequenceParser<Uint8Array>(Buffer.from('cececece', 'hex')),
55
+ ]),
56
+ uint8Array => uint8Array[0] === 0xFE ? 'JKS' : 'JCEKS',
57
+ );
58
+
59
+ const javaKeyStorePrivateKeyEntryPrivateKeyParser = uint32LengthPrefixedUint8ArrayParser;
60
+
61
+ const javaKeyStorePrivateKeyEntryCertificateParser = promiseCompose(
62
+ createTupleParser([
63
+ javaModifiedUTF8StringParser,
64
+ uint32LengthPrefixedUint8ArrayParser,
65
+ ]),
66
+ ([ type, certificate ]) => ({ type, certificate }),
67
+ );
68
+
69
+ const javaKeyStorePrivateKeyEntryCertificateChainParser = createUint32BECountPrefixedParser(
70
+ javaKeyStorePrivateKeyEntryCertificateParser,
71
+ );
72
+
73
+ const javaKeyStorePrivateKeyEntryParser = promiseCompose(
74
+ createTupleParser([
75
+ createExactSequenceParser<Uint8Array>(Buffer.from('00000001', 'hex')),
76
+ javaModifiedUTF8StringParser,
77
+ uint64BEParser,
78
+ javaKeyStorePrivateKeyEntryPrivateKeyParser,
79
+ javaKeyStorePrivateKeyEntryCertificateChainParser,
80
+ ]),
81
+ ([
82
+ _tag,
83
+ alias,
84
+ creationDate,
85
+ privateKey,
86
+ certificateChain,
87
+ ]) => ({
88
+ type: 'privateKey',
89
+ alias,
90
+ creationDate: new Date(Number(creationDate)),
91
+ privateKey,
92
+ certificateChain,
93
+ }),
94
+ );
95
+
96
+ const javaKeyStoreTrustedCertEntryParser = createTupleParser([
97
+ createExactSequenceParser<Uint8Array>(Buffer.from('00000002', 'hex')),
98
+ async parserContext => parserContext.invariant(false, 'Not implemented'),
99
+ ]);
100
+
101
+ const javaKeyStoreSecretKeyEntryParser = createTupleParser([
102
+ createExactSequenceParser<Uint8Array>(Buffer.from('00000003', 'hex')),
103
+ async parserContext => parserContext.invariant(false, 'Not implemented'),
104
+ ]);
105
+
106
+ const javaKeyStoreEntryParser = createUnionParser([
107
+ javaKeyStorePrivateKeyEntryParser,
108
+ javaKeyStoreTrustedCertEntryParser,
109
+ javaKeyStoreSecretKeyEntryParser,
110
+ ]);
111
+
112
+ const javaKeyStoreEntriesParser = createUint32BECountPrefixedParser(
113
+ javaKeyStoreEntryParser,
114
+ );
115
+
116
+ const javaKeyStoreParser_ = createTupleParser([
117
+ javaKeyStoreImplementationParser,
118
+ uint32BEParser,
119
+ javaKeyStoreEntriesParser,
120
+ createFixedLengthSequenceParser(20),
121
+ ]);
122
+
123
+ export const javaKeyStoreParser: Parser<unknown, Uint8Array> = promiseCompose(
124
+ javaKeyStoreParser_,
125
+ ([
126
+ implementation,
127
+ version,
128
+ entries,
129
+ hash,
130
+ ]) => ({
131
+ implementation,
132
+ version,
133
+ entries,
134
+ hash,
135
+ }),
136
+ );
@@ -2,7 +2,7 @@ import { testProp, fc } from '@fast-check/ava';
2
2
  import { jsonValueParser } from './jsonParser.js';
3
3
  import { runParser } from './parser.js';
4
4
  import { arbitrarilySlicedAsyncIterator } from './arbitrarilySlicedAsyncInterator.js';
5
- import { stringInputCompanion } from './inputCompanion.js';
5
+ import { stringParserInputCompanion } from './parserInputCompanion.js';
6
6
 
7
7
  testProp(
8
8
  'json',
@@ -13,7 +13,7 @@ testProp(
13
13
  ),
14
14
  ],
15
15
  async (t, [ jsonString, jsonStringChunkIterator ]) => {
16
- const actual = await runParser(jsonValueParser, jsonStringChunkIterator, stringInputCompanion, {
16
+ const actual = await runParser(jsonValueParser, jsonStringChunkIterator, stringParserInputCompanion, {
17
17
  errorJoinMode: 'none',
18
18
  });
19
19
  const expected = JSON.parse(jsonString);
package/src/jsonParser.ts CHANGED
@@ -13,6 +13,7 @@ import { createArrayParser } from './arrayParser.js';
13
13
  import { createParserAccessorParser } from './parserAccessorParser.js';
14
14
  import { createElementParser } from './elementParser.js';
15
15
  import { parserCreatorCompose } from './parserCreatorCompose.js';
16
+ import { createSeparatedArrayParser } from './separatedArrayParser.js';
16
17
 
17
18
  const whitespaceParser: Parser<unknown, string> = createArrayParser(
18
19
  createUnionParser([
@@ -65,7 +66,7 @@ const jsonStringCharacterParser: Parser<string, string> = createDisjunctionParse
65
66
  )(),
66
67
  ]);
67
68
 
68
- const jsonStringParser: Parser<string, string> = promiseCompose(
69
+ export const jsonStringParser: Parser<string, string> = promiseCompose(
69
70
  createTupleParser([
70
71
  createExactSequenceParser('"'),
71
72
  promiseCompose(
@@ -79,11 +80,11 @@ const jsonStringParser: Parser<string, string> = promiseCompose(
79
80
  ([ , string ]) => string,
80
81
  );
81
82
 
82
- const jsonNumberParser: Parser<number, string> = parserCreatorCompose(
83
+ export const jsonNumberParser: Parser<number, string> = parserCreatorCompose(
83
84
  () => createArrayParser(
84
85
  parserCreatorCompose(
85
86
  () => elementParser,
86
- (character) => async parserContext => {
87
+ character => async parserContext => {
87
88
  parserContext.invariant(
88
89
  (
89
90
  character === '-'
@@ -101,7 +102,7 @@ const jsonNumberParser: Parser<number, string> = parserCreatorCompose(
101
102
  },
102
103
  )(),
103
104
  ),
104
- (characters) => async parserContext => {
105
+ characters => async parserContext => {
105
106
  parserContext.invariant(characters.length > 0, 'Expected at least one character');
106
107
 
107
108
  return Number(characters.join(''));
@@ -116,6 +117,7 @@ const jsonFalseParser: Parser<false, string> = promiseCompose(createExactSequenc
116
117
 
117
118
  setParserName(jsonFalseParser, 'jsonFalseParser');
118
119
 
120
+ // eslint-disable-next-line @typescript-eslint/ban-types
119
121
  const jsonNullParser: Parser<null, string> = promiseCompose(createExactSequenceParser('null'), () => null);
120
122
 
121
123
  setParserName(jsonNullParser, 'jsonNullParser');
@@ -138,7 +140,7 @@ const jsonObjectEntryParser: Parser<[string, JsonValue], string> = promiseCompos
138
140
  whitespaceParser,
139
141
  createParserAccessorParser(() => jsonValueParser),
140
142
  ]),
141
- ([key, _whitespace1, _colon, _whitespace2, value]) => [key, value],
143
+ ([ key, _whitespace1, _colon, _whitespace2, value ]) => [ key, value ],
142
144
  );
143
145
 
144
146
  const jsonObjectParser: Parser<JsonObject, string> = promiseCompose(
@@ -155,25 +157,25 @@ const jsonObjectParser: Parser<JsonObject, string> = promiseCompose(
155
157
  createExactSequenceParser(','),
156
158
  whitespaceParser,
157
159
  ]),
158
- ([entry]) => entry,
160
+ ([ entry ]) => entry,
159
161
  ),
160
162
  promiseCompose(
161
163
  createTupleParser([
162
164
  createParserAccessorParser(() => jsonObjectEntryParser),
163
165
  whitespaceParser,
164
166
  ]),
165
- ([value]) => value,
167
+ ([ value ]) => value,
166
168
  ),
167
169
  ]),
168
170
  createExactSequenceParser('}'),
169
171
  ),
170
- ([entries]) => entries,
172
+ ([ entries ]) => entries,
171
173
  ),
172
174
  ]),
173
- ([ _brace, _whitespace, entries]) => {
175
+ ([ _brace, _whitespace, entries ]) => {
174
176
  const object: Writable<JsonObject> = {};
175
177
 
176
- for (const [key, value] of entries) {
178
+ for (const [ key, value ] of entries) {
177
179
  Object.defineProperty(object, key, {
178
180
  value,
179
181
  enumerable: true,
@@ -188,32 +190,19 @@ const jsonArrayParser: Parser<JsonArray, string> = promiseCompose(
188
190
  createTupleParser([
189
191
  createExactSequenceParser('['),
190
192
  whitespaceParser,
191
- promiseCompose(
192
- createTerminatedArrayParser(
193
- createDisjunctionParser<JsonValue, string>([
194
- promiseCompose(
195
- createTupleParser([
196
- createParserAccessorParser(() => jsonValueParser),
197
- whitespaceParser,
198
- createExactSequenceParser(','),
199
- whitespaceParser,
200
- ]),
201
- ([value]) => value,
202
- ),
203
- promiseCompose(
204
- createTupleParser([
205
- createParserAccessorParser(() => jsonValueParser),
206
- whitespaceParser,
207
- ]),
208
- ([value]) => value,
209
- ),
210
- ]),
211
- createExactSequenceParser(']'),
212
- ),
213
- ([values]) => values,
193
+ createSeparatedArrayParser(
194
+ createParserAccessorParser(() => jsonValueParser),
195
+ createTupleParser([
196
+ whitespaceParser,
197
+ createExactSequenceParser(','),
198
+ whitespaceParser,
199
+ ]),
214
200
  ),
201
+ whitespaceParser,
202
+ createExactSequenceParser(']'),
203
+ whitespaceParser,
215
204
  ]),
216
- ([_bracket, _whitespace, values]) => values,
205
+ ([ _bracket, _whitespace, values ]) => values,
217
206
  );
218
207
 
219
208
  export const jsonValueParser: Parser<JsonValue, string> = createUnionParser([
@@ -0,0 +1,171 @@
1
+ import { testProp, fc } from '@fast-check/ava';
2
+ import test from 'ava';
3
+ // @ts-expect-error
4
+ import leb128 from 'leb128';
5
+ import { uint8ArrayParserInputCompanion } from './parserInputCompanion.js';
6
+ import { runParser } from './parser.js';
7
+ import { uleb128Parser, sleb128Parser, uleb128NumberParser, sleb128NumberParser } from './leb128Parser.js';
8
+
9
+ test('sleb128, uleb128, uleb128p1', async t => {
10
+ for (const [
11
+ input, expectedSleb128, expectedUleb128,
12
+ ] of [
13
+ [ Buffer.from('00', 'hex'), 0n, 0n ],
14
+ [ Buffer.from('01', 'hex'), 1n, 1n ],
15
+ [ Buffer.from('7f', 'hex'), -1n, 127n ],
16
+ [ Buffer.from('807f', 'hex'), -128n, 16256n ],
17
+ ] as const) {
18
+ const actualSleb128 = await runParser(sleb128Parser, input, uint8ArrayParserInputCompanion);
19
+ const actualUleb128 = await runParser(uleb128Parser, input, uint8ArrayParserInputCompanion);
20
+
21
+ t.is(actualSleb128, expectedSleb128, 'sleb128');
22
+ t.is(actualUleb128, expectedUleb128, 'uleb128');
23
+ }
24
+
25
+ for (const [
26
+ input, expectedUleb128,
27
+ ] of [
28
+ [ new Uint8Array([ 2 ]), 2n ],
29
+ [ new Uint8Array([ 127 ]), 127n ],
30
+ [ new Uint8Array([ 0 + 0x80, 1 ]), 128n ],
31
+ [ new Uint8Array([ 1 + 0x80, 1 ]), 129n ],
32
+ [ new Uint8Array([ 57 + 0x80, 100 ]), 12857n ],
33
+ ] as const) {
34
+ const actualUleb128 = await runParser(uleb128Parser, input, uint8ArrayParserInputCompanion);
35
+
36
+ t.is(actualUleb128, expectedUleb128, 'uleb128');
37
+ }
38
+
39
+ for (const [
40
+ input, expectedSleb128,
41
+ ] of [
42
+ [ new Uint8Array([ 2 ]), 2n ],
43
+ [ new Uint8Array([ 0x7e ]), -2n ],
44
+ [ new Uint8Array([ 127 + 0x80, 0 ]), 127n ],
45
+ [ new Uint8Array([ 1 + 0x80, 0x7f ]), -127n ],
46
+ [ new Uint8Array([ 0 + 0x80, 1 ]), 128n ],
47
+ [ new Uint8Array([ 0 + 0x80, 0x7f ]), -128n ],
48
+ [ new Uint8Array([ 1 + 0x80, 1 ]), 129n ],
49
+ [ new Uint8Array([ 0x7f + 0x80, 0x7e ]), -129n ],
50
+ ] as const) {
51
+ const actualSleb128 = await runParser(sleb128Parser, input, uint8ArrayParserInputCompanion);
52
+
53
+ t.is(actualSleb128, expectedSleb128, 'sleb128');
54
+ }
55
+ });
56
+
57
+ testProp(
58
+ 'uleb128NumberParser on small number',
59
+ [
60
+ fc.nat(),
61
+ ],
62
+ async (t, natural) => {
63
+ const uleb128 = leb128.unsigned.encode(natural);
64
+
65
+ const actualUleb128 = await runParser(uleb128NumberParser, uleb128, uint8ArrayParserInputCompanion);
66
+
67
+ t.is(actualUleb128, natural, 'uleb128');
68
+ },
69
+ {
70
+ verbose: true,
71
+ },
72
+ );
73
+
74
+ testProp(
75
+ 'sleb128NumberParser on small number',
76
+ [
77
+ fc.integer(),
78
+ ],
79
+ async (t, integer) => {
80
+ const sleb128 = leb128.signed.encode(integer);
81
+
82
+ const actualSleb128 = await runParser(sleb128NumberParser, sleb128, uint8ArrayParserInputCompanion);
83
+
84
+ t.is(actualSleb128, integer, 'sleb128');
85
+ },
86
+ {
87
+ verbose: true,
88
+ },
89
+ );
90
+
91
+ // TODO?
92
+ testProp.skip(
93
+ 'uleb128NumberParser on large number',
94
+ [
95
+ fc.maxSafeNat(),
96
+ ],
97
+ async (t, natural) => {
98
+ const uleb128 = leb128.unsigned.encode(natural);
99
+
100
+ if (natural > (2 ** 32) - 1) {
101
+ await t.throwsAsync(() => runParser(uleb128NumberParser, uleb128, uint8ArrayParserInputCompanion));
102
+
103
+ return;
104
+ }
105
+
106
+ const actualUleb128 = await runParser(uleb128NumberParser, uleb128, uint8ArrayParserInputCompanion);
107
+
108
+ t.is(actualUleb128, natural, 'uleb128');
109
+ },
110
+ {
111
+ verbose: true,
112
+ },
113
+ );
114
+
115
+ // TODO?
116
+ testProp.skip(
117
+ 'sleb128NumberParser on large number',
118
+ [
119
+ fc.maxSafeInteger(),
120
+ ],
121
+ async (t, integer) => {
122
+ const sleb128 = leb128.signed.encode(integer);
123
+
124
+ if (integer > (2 ** 32) - 1 || integer < -(2 ** 32)) {
125
+ await t.throwsAsync(() => runParser(sleb128NumberParser, sleb128, uint8ArrayParserInputCompanion));
126
+
127
+ return;
128
+ }
129
+
130
+ const actualSleb128 = await runParser(sleb128NumberParser, sleb128, uint8ArrayParserInputCompanion);
131
+
132
+ t.is(actualSleb128, integer, 'sleb128');
133
+ },
134
+ {
135
+ verbose: true,
136
+ },
137
+ );
138
+
139
+ testProp(
140
+ 'uleb128Parser on bigint',
141
+ [
142
+ fc.bigInt({ min: 0n }),
143
+ ],
144
+ async (t, bigInt) => {
145
+ const uleb128 = leb128.unsigned.encode(bigInt);
146
+
147
+ const actualUleb128 = await runParser(uleb128Parser, uleb128, uint8ArrayParserInputCompanion);
148
+
149
+ t.is(actualUleb128, bigInt, 'uleb128');
150
+ },
151
+ {
152
+ verbose: true,
153
+ },
154
+ );
155
+
156
+ testProp(
157
+ 'sleb128Parser on bigint',
158
+ [
159
+ fc.bigInt(),
160
+ ],
161
+ async (t, bigInt) => {
162
+ const sleb128 = leb128.signed.encode(bigInt);
163
+
164
+ const actualSleb128 = await runParser(sleb128Parser, sleb128, uint8ArrayParserInputCompanion);
165
+
166
+ t.is(actualSleb128, bigInt, 'sleb128');
167
+ },
168
+ {
169
+ verbose: true,
170
+ },
171
+ );
@@ -0,0 +1,125 @@
1
+ import { Parser } from "./parser.js";
2
+
3
+ export const uleb128Parser: Parser<bigint, Uint8Array> = async (parserContext) => {
4
+ let leastSignificantValueBitIndex = 0n;
5
+ let value = 0n;
6
+
7
+ while (true) {
8
+ const byte = await parserContext.read(0);
9
+ const byteValue = BigInt(byte & 0b01111111);
10
+ const byteNotLast = BigInt(byte & 0b10000000);
11
+
12
+ value |= byteValue << leastSignificantValueBitIndex;
13
+
14
+ if (byteNotLast) {
15
+ leastSignificantValueBitIndex += 7n;
16
+ continue;
17
+ }
18
+
19
+ break;
20
+ }
21
+
22
+ return value;
23
+ }
24
+
25
+ export const sleb128Parser: Parser<bigint, Uint8Array> = async (parserContext) => {
26
+ let value = 0n;
27
+ let leastSignificantValueBitIndex = 0n;
28
+
29
+ while (true) {
30
+ const byte = await parserContext.read(0);
31
+ const byteValue = BigInt(byte & 0b01111111);
32
+ const byteNotLast = BigInt(byte & 0b10000000);
33
+
34
+ value |= byteValue << leastSignificantValueBitIndex;
35
+ leastSignificantValueBitIndex += 7n;
36
+
37
+ if (byteNotLast) {
38
+ continue;
39
+ }
40
+
41
+ const mostSignificantInputBit = byte & 0b01000000;
42
+
43
+ if (mostSignificantInputBit) {
44
+ value |= (~0n << leastSignificantValueBitIndex);
45
+ }
46
+
47
+ break;
48
+ }
49
+
50
+ return value;
51
+ };
52
+
53
+ export const uleb128NumberParser: Parser<number, Uint8Array> = async (parserContext) => {
54
+ const value = await uleb128Parser(parserContext);
55
+
56
+ parserContext.invariant(
57
+ Number(value) <= Number.MAX_SAFE_INTEGER,
58
+ 'Value is too large to be represented as a number: %s',
59
+ value,
60
+ );
61
+
62
+ return Number(value);
63
+ };
64
+
65
+ export const sleb128NumberParser: Parser<number, Uint8Array> = async (parserContext) => {
66
+ const value = await sleb128Parser(parserContext);
67
+
68
+ parserContext.invariant(
69
+ Number(value) >= Number.MIN_SAFE_INTEGER && Number(value) <= Number.MAX_SAFE_INTEGER,
70
+ 'Value is too large to be represented as a number: %s',
71
+ value,
72
+ );
73
+
74
+ return Number(value);
75
+ };
76
+
77
+ export const uleb128UnsafeNumberParser: Parser<number, Uint8Array> = async (parserContext) => {
78
+ let leastSignificantValueBitIndex = 0;
79
+ let value = 0;
80
+
81
+ while (true) {
82
+ const byte = await parserContext.read(0);
83
+ const byteValue = byte & 0b01111111;
84
+ const byteNotLast = byte & 0b10000000;
85
+
86
+ value |= byteValue << leastSignificantValueBitIndex;
87
+
88
+ if (byteNotLast) {
89
+ leastSignificantValueBitIndex += 7;
90
+ continue;
91
+ }
92
+
93
+ break;
94
+ }
95
+
96
+ return value;
97
+ }
98
+
99
+ export const sleb128UnsafeNumberParser: Parser<number, Uint8Array> = async (parserContext) => {
100
+ let value = 0;
101
+ let leastSignificantValueBitIndex = 0;
102
+
103
+ while (true) {
104
+ const byte = await parserContext.read(0);
105
+ const byteValue = byte & 0b01111111;
106
+ const byteNotLast = byte & 0b10000000;
107
+
108
+ value |= byteValue << leastSignificantValueBitIndex;
109
+ leastSignificantValueBitIndex += 7;
110
+
111
+ if (byteNotLast) {
112
+ continue;
113
+ }
114
+
115
+ const mostSignificantInputBit = byte & 0b01000000;
116
+
117
+ if (leastSignificantValueBitIndex < 32 && mostSignificantInputBit) {
118
+ value |= (~0 << leastSignificantValueBitIndex);
119
+ }
120
+
121
+ break;
122
+ }
123
+
124
+ return value;
125
+ };
package/src/listParser.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { createNegativeLookaheadParser } from "./negativeLookahead.js";
2
- import { Parser } from "./parser.js";
3
- import { createParserAccessorParser } from "./parserAccessorParser.js";
4
- import { promiseCompose } from "./promiseCompose.js";
5
- import { createTupleParser } from "./tupleParser.js";
6
- import { createUnionParser } from "./unionParser.js";
1
+ import { createNegativeLookaheadParser } from './negativeLookaheadParser.js';
2
+ import { type Parser } from './parser.js';
3
+ import { createParserAccessorParser } from './parserAccessorParser.js';
4
+ import { promiseCompose } from './promiseCompose.js';
5
+ import { createTupleParser } from './tupleParser.js';
6
+ import { createUnionParser } from './unionParser.js';
7
7
 
8
8
  class Nil {}
9
9
  class Cons<Head, Tail> {
@@ -0,0 +1,19 @@
1
+ import { getParserName, setParserName, type Parser } from './parser.js';
2
+
3
+ export const createLookaheadParser = <Output, Sequence>(
4
+ childParser: Parser<Output, Sequence>,
5
+ ): Parser<Output, Sequence> => {
6
+ const lookaheadParser: Parser<Output, Sequence> = async parserContext => {
7
+ const childParserContext = parserContext.lookahead();
8
+
9
+ try {
10
+ return await childParser(childParserContext);
11
+ } finally {
12
+ childParserContext.dispose();
13
+ }
14
+ };
15
+
16
+ setParserName(lookaheadParser, `(?=${getParserName(childParser)})`);
17
+
18
+ return lookaheadParser;
19
+ };
@@ -0,0 +1,53 @@
1
+ import * as fc from 'fast-check';
2
+ import { testProp } from '@fast-check/ava';
3
+ import { createNegativeLookaheadParser } from './negativeLookaheadParser.js';
4
+ import { createExactSequenceParser } from './exactSequenceParser.js';
5
+ import { runParser } from './parser.js';
6
+ import { stringParserInputCompanion } from './parserInputCompanion.js';
7
+ import { createTupleParser } from './tupleParser.js';
8
+ import { ParserParsingFailedError } from './parserError.js';
9
+
10
+ testProp(
11
+ 'negativeLookaheadParser',
12
+ [
13
+ fc.tuple(
14
+ fc.string({
15
+ minLength: 1,
16
+ }),
17
+ fc.string({
18
+ minLength: 1,
19
+ }),
20
+ ).filter(([ a, b ]) => !a.startsWith(b))
21
+ ],
22
+ async (t, [ stringA, stringB ]) => {
23
+ const result = await runParser(
24
+ createTupleParser([
25
+ createNegativeLookaheadParser(
26
+ createExactSequenceParser(stringB),
27
+ ),
28
+ createExactSequenceParser(stringA + stringB),
29
+ ]),
30
+ stringA + stringB,
31
+ stringParserInputCompanion,
32
+ );
33
+
34
+ t.deepEqual(result, [undefined, stringA + stringB]);
35
+
36
+ await t.throwsAsync(() => runParser(
37
+ createTupleParser([
38
+ createNegativeLookaheadParser(
39
+ createExactSequenceParser(stringA),
40
+ ),
41
+ createExactSequenceParser(stringA + stringB),
42
+ ]),
43
+ stringA + stringB,
44
+ stringParserInputCompanion,
45
+ ), {
46
+ instanceOf: ParserParsingFailedError,
47
+ message: /lookahead/,
48
+ });
49
+ },
50
+ {
51
+ verbose: true,
52
+ },
53
+ );