@thomasfosterau/effect-rdf 0.0.0 → 0.1.0

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 (776) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2250 -1
  3. package/dist/Algebra-CGG4oae3.mjs +433 -0
  4. package/dist/Algebra-CGG4oae3.mjs.map +1 -0
  5. package/dist/Algebra-uGsIEOUA.d.mts +446 -0
  6. package/dist/Ast-CPRZmBvk.mjs +552 -0
  7. package/dist/Ast-CPRZmBvk.mjs.map +1 -0
  8. package/dist/Ast-vcw2W-lf.d.mts +827 -0
  9. package/dist/Bindings-Ck3m7JRC.mjs +249 -0
  10. package/dist/Bindings-Ck3m7JRC.mjs.map +1 -0
  11. package/dist/Bindings-DiKpBd7f.d.mts +153 -0
  12. package/dist/ClientErrors-CpXdFX5u.mjs +128 -0
  13. package/dist/ClientErrors-CpXdFX5u.mjs.map +1 -0
  14. package/dist/ClientErrors-D4IZHUM-.d.mts +101 -0
  15. package/dist/ClientFormats-CXomkXLV.mjs +73 -0
  16. package/dist/ClientFormats-CXomkXLV.mjs.map +1 -0
  17. package/dist/ClientFormats-Dm57ZPwR.d.mts +36 -0
  18. package/dist/Csv2Json-DynEcwCh.mjs +194 -0
  19. package/dist/Csv2Json-DynEcwCh.mjs.map +1 -0
  20. package/dist/Csv2Json-aXNVDoXQ.d.mts +40 -0
  21. package/dist/Csv2Rdf-8maXP6mt.d.mts +41 -0
  22. package/dist/Csv2Rdf-DuSEkaKE.mjs +161 -0
  23. package/dist/Csv2Rdf-DuSEkaKE.mjs.map +1 -0
  24. package/dist/Dataset-BlmlcI7J.mjs +782 -0
  25. package/dist/Dataset-BlmlcI7J.mjs.map +1 -0
  26. package/dist/Dataset-DS3ESOcO.d.mts +426 -0
  27. package/dist/Dataset.d.mts +2 -0
  28. package/dist/Dataset.mjs +1 -0
  29. package/dist/Datatype-CxMpamHC.d.mts +212 -0
  30. package/dist/Datatype-DQvkNkiH.mjs +1001 -0
  31. package/dist/Datatype-DQvkNkiH.mjs.map +1 -0
  32. package/dist/Dialect-8ChFj5EX.d.mts +113 -0
  33. package/dist/Dialect-CzVH38uo.mjs +165 -0
  34. package/dist/Dialect-CzVH38uo.mjs.map +1 -0
  35. package/dist/DocumentLoader-D3lZREnB.mjs +346 -0
  36. package/dist/DocumentLoader-D3lZREnB.mjs.map +1 -0
  37. package/dist/DocumentLoader-ZUCEVrW5.d.mts +178 -0
  38. package/dist/DublinCore-AnwqxRx6.mjs +137 -0
  39. package/dist/DublinCore-AnwqxRx6.mjs.map +1 -0
  40. package/dist/DublinCore-Dq-tVA5d.d.mts +119 -0
  41. package/dist/Engine-CYPB3g4h.d.mts +144 -0
  42. package/dist/Engine-DF8PN7g-.mjs +872 -0
  43. package/dist/Engine-DF8PN7g-.mjs.map +1 -0
  44. package/dist/Errors-CMdV1RhU.mjs +37 -0
  45. package/dist/Errors-CMdV1RhU.mjs.map +1 -0
  46. package/dist/Errors-u2bDjUeM.d.mts +30 -0
  47. package/dist/Evaluator-DEsU4d1o.d.mts +50 -0
  48. package/dist/Evaluator-DOY2-guC.mjs +281 -0
  49. package/dist/Evaluator-DOY2-guC.mjs.map +1 -0
  50. package/dist/Exif-CpqniYQd.d.mts +78 -0
  51. package/dist/Exif-DjkCfEB-.mjs +89 -0
  52. package/dist/Exif-DjkCfEB-.mjs.map +1 -0
  53. package/dist/Expression-BIMMvduQ.mjs +230 -0
  54. package/dist/Expression-BIMMvduQ.mjs.map +1 -0
  55. package/dist/Expression-W8A9cyX7.d.mts +89 -0
  56. package/dist/Extract-Bop85jES.mjs +220 -0
  57. package/dist/Extract-Bop85jES.mjs.map +1 -0
  58. package/dist/Extract-C_pCvuTC.d.mts +88 -0
  59. package/dist/Federation-BcNrozc1.d.mts +52 -0
  60. package/dist/Federation-CHScBkaK.mjs +130 -0
  61. package/dist/Federation-CHScBkaK.mjs.map +1 -0
  62. package/dist/Functions-AvjNcId_.mjs +1346 -0
  63. package/dist/Functions-AvjNcId_.mjs.map +1 -0
  64. package/dist/Functions-OQJZP-F6.d.mts +111 -0
  65. package/dist/Generator-C52mmq01.d.mts +50 -0
  66. package/dist/Generator-D3utCJC7.mjs +205 -0
  67. package/dist/Generator-D3utCJC7.mjs.map +1 -0
  68. package/dist/Grammar-CPlSxGH6.mjs +200 -0
  69. package/dist/Grammar-CPlSxGH6.mjs.map +1 -0
  70. package/dist/Grammar-CRhnRoCu.d.mts +148 -0
  71. package/dist/Grammar-D6jZdJQ3.d.mts +169 -0
  72. package/dist/Grammar-mQ8CgE1M.mjs +258 -0
  73. package/dist/Grammar-mQ8CgE1M.mjs.map +1 -0
  74. package/dist/GraphStore-DhUa4nFO.d.mts +45 -0
  75. package/dist/GraphStore-DvbqwKy1.mjs +212 -0
  76. package/dist/GraphStore-DvbqwKy1.mjs.map +1 -0
  77. package/dist/Iri-BB8Ks-BF.d.mts +84 -0
  78. package/dist/Iri-Cr92gsQV.mjs +232 -0
  79. package/dist/Iri-Cr92gsQV.mjs.map +1 -0
  80. package/dist/Iri.d.mts +2 -0
  81. package/dist/Iri.mjs +1 -0
  82. package/dist/Isomorphism-B6qTY-xy.d.mts +28 -0
  83. package/dist/Isomorphism-BmqxhKyJ.mjs +232 -0
  84. package/dist/Isomorphism-BmqxhKyJ.mjs.map +1 -0
  85. package/dist/Isomorphism-DInKnWIy.mjs +390 -0
  86. package/dist/Isomorphism-DInKnWIy.mjs.map +1 -0
  87. package/dist/Isomorphism-DvSfZXLR.d.mts +37 -0
  88. package/dist/Isomorphism.d.mts +2 -0
  89. package/dist/Isomorphism.mjs +1 -0
  90. package/dist/JsonLd-DOwS2FHg.mjs +2836 -0
  91. package/dist/JsonLd-DOwS2FHg.mjs.map +1 -0
  92. package/dist/JsonLd-DobFrQNa.d.mts +242 -0
  93. package/dist/JsonLdError-C9J-BxfG.mjs +106 -0
  94. package/dist/JsonLdError-C9J-BxfG.mjs.map +1 -0
  95. package/dist/JsonLdError-DSOfHkOy.d.mts +43 -0
  96. package/dist/LanguageTag-BCu8rcmX.d.mts +38 -0
  97. package/dist/LanguageTag-BcOpMGZ4.mjs +89 -0
  98. package/dist/LanguageTag-BcOpMGZ4.mjs.map +1 -0
  99. package/dist/LanguageTag.d.mts +2 -0
  100. package/dist/LanguageTag.mjs +1 -0
  101. package/dist/Lexical-Cg0JHrf6.mjs +243 -0
  102. package/dist/Lexical-Cg0JHrf6.mjs.map +1 -0
  103. package/dist/Lexical-D3zySYVS.d.mts +163 -0
  104. package/dist/Manifest-B6xf6mUc.mjs +148 -0
  105. package/dist/Manifest-B6xf6mUc.mjs.map +1 -0
  106. package/dist/Manifest-DQUMRBFr.d.mts +98 -0
  107. package/dist/Mapping-BgG74x3U.d.mts +63 -0
  108. package/dist/Mapping-Dc1ZGirk.mjs +259 -0
  109. package/dist/Mapping-Dc1ZGirk.mjs.map +1 -0
  110. package/dist/Mcp-1DwTTKOK.mjs +48 -0
  111. package/dist/Mcp-1DwTTKOK.mjs.map +1 -0
  112. package/dist/Mcp-d-pX9erx.d.mts +25 -0
  113. package/dist/Message-CK_DGQuu.mjs +95 -0
  114. package/dist/Message-CK_DGQuu.mjs.map +1 -0
  115. package/dist/Message-fIvTJSXM.d.mts +49 -0
  116. package/dist/Metadata-BbffwGDZ.mjs +445 -0
  117. package/dist/Metadata-BbffwGDZ.mjs.map +1 -0
  118. package/dist/Metadata-CEt3yc1-.d.mts +901 -0
  119. package/dist/Metadata-D4HsQNXr.mjs +1273 -0
  120. package/dist/Metadata-D4HsQNXr.mjs.map +1 -0
  121. package/dist/Metadata-nzS7QKRj.d.mts +350 -0
  122. package/dist/Model-DaMmxurZ.d.mts +293 -0
  123. package/dist/Model-DlPzRYhF.mjs +528 -0
  124. package/dist/Model-DlPzRYhF.mjs.map +1 -0
  125. package/dist/N3-BzyV-KIH.mjs +974 -0
  126. package/dist/N3-BzyV-KIH.mjs.map +1 -0
  127. package/dist/N3-DSLnonDn.d.mts +100 -0
  128. package/dist/NQuads-C1VBOJ3-.mjs +117 -0
  129. package/dist/NQuads-C1VBOJ3-.mjs.map +1 -0
  130. package/dist/NQuads-FjFZikFg.d.mts +76 -0
  131. package/dist/NTriples-D-kLSEAf.mjs +120 -0
  132. package/dist/NTriples-D-kLSEAf.mjs.map +1 -0
  133. package/dist/NTriples-D34OspfW.d.mts +76 -0
  134. package/dist/Namespace-ClTUO_ya.d.mts +42 -0
  135. package/dist/Namespace-DHFIsORd.mjs +75 -0
  136. package/dist/Namespace-DHFIsORd.mjs.map +1 -0
  137. package/dist/Namespace.d.mts +2 -0
  138. package/dist/Namespace.mjs +1 -0
  139. package/dist/Namespaces-Bz85vpjW.mjs +235 -0
  140. package/dist/Namespaces-Bz85vpjW.mjs.map +1 -0
  141. package/dist/Namespaces-C1jW6EDo.d.mts +178 -0
  142. package/dist/Optimizer-BWWQRQPY.mjs +168 -0
  143. package/dist/Optimizer-BWWQRQPY.mjs.map +1 -0
  144. package/dist/Optimizer-DUpUow6k.d.mts +26 -0
  145. package/dist/Options-BLBGL4HE.mjs +72 -0
  146. package/dist/Options-BLBGL4HE.mjs.map +1 -0
  147. package/dist/Options-BommQwP9.d.mts +127 -0
  148. package/dist/Packet-CA76wVX3.mjs +197 -0
  149. package/dist/Packet-CA76wVX3.mjs.map +1 -0
  150. package/dist/Packet-Cy5g6XuW.d.mts +130 -0
  151. package/dist/Parser-p1Gyr0QN.d.mts +85 -0
  152. package/dist/Parser-xARsOWXk.mjs +1317 -0
  153. package/dist/Parser-xARsOWXk.mjs.map +1 -0
  154. package/dist/Path-B20Yp8KE.mjs +284 -0
  155. package/dist/Path-B20Yp8KE.mjs.map +1 -0
  156. package/dist/Path-DRB8e-Zn.d.mts +181 -0
  157. package/dist/Pdf-B9RZn--8.d.mts +77 -0
  158. package/dist/Pdf-CKK6dkZn.mjs +89 -0
  159. package/dist/Pdf-CKK6dkZn.mjs.map +1 -0
  160. package/dist/PdfA-CUjSuntT.d.mts +109 -0
  161. package/dist/PdfA-CleOhuL6.mjs +124 -0
  162. package/dist/PdfA-CleOhuL6.mjs.map +1 -0
  163. package/dist/Photoshop-CiHo80qV.mjs +233 -0
  164. package/dist/Photoshop-CiHo80qV.mjs.map +1 -0
  165. package/dist/Photoshop-udKZ0I3N.d.mts +204 -0
  166. package/dist/PrefixMap-BHFPDLO-.mjs +103 -0
  167. package/dist/PrefixMap-BHFPDLO-.mjs.map +1 -0
  168. package/dist/PrefixMap-BMlXrWNd.d.mts +64 -0
  169. package/dist/PrefixMap.d.mts +2 -0
  170. package/dist/PrefixMap.mjs +1 -0
  171. package/dist/Processor-CMmecFsb.mjs +198 -0
  172. package/dist/Processor-CMmecFsb.mjs.map +1 -0
  173. package/dist/Processor-FJPvO0CB.d.mts +435 -0
  174. package/dist/Protocol-BA7OkNgp.mjs +202 -0
  175. package/dist/Protocol-BA7OkNgp.mjs.map +1 -0
  176. package/dist/Protocol-DlSoiIKB.d.mts +108 -0
  177. package/dist/ProtocolErrors-Ckfejnl6.d.mts +84 -0
  178. package/dist/ProtocolErrors-czDPVcX5.mjs +129 -0
  179. package/dist/ProtocolErrors-czDPVcX5.mjs.map +1 -0
  180. package/dist/Query-D9A6LOpP.mjs +364 -0
  181. package/dist/Query-D9A6LOpP.mjs.map +1 -0
  182. package/dist/Query-KqSkTYyG.d.mts +96 -0
  183. package/dist/QueryBuilder-BLK9Vfbz.mjs +674 -0
  184. package/dist/QueryBuilder-BLK9Vfbz.mjs.map +1 -0
  185. package/dist/QueryBuilder-DUqh4ECe.d.mts +529 -0
  186. package/dist/RdfJs-D6-49XB5.mjs +86 -0
  187. package/dist/RdfJs-D6-49XB5.mjs.map +1 -0
  188. package/dist/RdfJs-DXFqdWrd.d.mts +76 -0
  189. package/dist/RdfJs.d.mts +2 -0
  190. package/dist/RdfJs.mjs +1 -0
  191. package/dist/RdfJson-5aKPDlPS.d.mts +297 -0
  192. package/dist/RdfJson-BNocgW4f.mjs +548 -0
  193. package/dist/RdfJson-BNocgW4f.mjs.map +1 -0
  194. package/dist/RdfXml-DJ9G4gOq.mjs +1014 -0
  195. package/dist/RdfXml-DJ9G4gOq.mjs.map +1 -0
  196. package/dist/RdfXml-_N7yxWEp.d.mts +149 -0
  197. package/dist/Rdfs-BRVPsAjc.d.mts +84 -0
  198. package/dist/Rdfs-CyY2wVHI.mjs +167 -0
  199. package/dist/Rdfs-CyY2wVHI.mjs.map +1 -0
  200. package/dist/Rdfs.d.mts +2 -0
  201. package/dist/Rdfs.mjs +1 -0
  202. package/dist/Reasoner-BxYhx9s7.d.mts +94 -0
  203. package/dist/Reasoner-Cw90zrjv.mjs +798 -0
  204. package/dist/Reasoner-Cw90zrjv.mjs.map +1 -0
  205. package/dist/Reification-BmN4EfnM.d.mts +40 -0
  206. package/dist/Reification-dpqQvjDE.mjs +82 -0
  207. package/dist/Reification-dpqQvjDE.mjs.map +1 -0
  208. package/dist/Reification.d.mts +2 -0
  209. package/dist/Reification.mjs +1 -0
  210. package/dist/Report-XHs8htzK.mjs +121 -0
  211. package/dist/Report-XHs8htzK.mjs.map +1 -0
  212. package/dist/Report-hcXsc_19.d.mts +115 -0
  213. package/dist/Resource-B1cI8FyJ.d.mts +218 -0
  214. package/dist/Resource-sIEeNh15.mjs +374 -0
  215. package/dist/Resource-sIEeNh15.mjs.map +1 -0
  216. package/dist/Resource.d.mts +2 -0
  217. package/dist/Resource.mjs +1 -0
  218. package/dist/Results-BVNEC-Wt.d.mts +277 -0
  219. package/dist/Results-peJjGA2V.mjs +621 -0
  220. package/dist/Results-peJjGA2V.mjs.map +1 -0
  221. package/dist/ResultsStream-BhF0OcNn.mjs +639 -0
  222. package/dist/ResultsStream-BhF0OcNn.mjs.map +1 -0
  223. package/dist/ResultsStream-toYMXrOe.d.mts +100 -0
  224. package/dist/SemAct-CDchtk49.d.mts +96 -0
  225. package/dist/SemAct-CmyT4yI8.mjs +118 -0
  226. package/dist/SemAct-CmyT4yI8.mjs.map +1 -0
  227. package/dist/Serialization-DP9H5bYQ.mjs +514 -0
  228. package/dist/Serialization-DP9H5bYQ.mjs.map +1 -0
  229. package/dist/Serialization-Df8iVauT.d.mts +392 -0
  230. package/dist/Serialization.d.mts +2 -0
  231. package/dist/Serialization.mjs +1 -0
  232. package/dist/ServerFormats-CrRnjjf6.mjs +64 -0
  233. package/dist/ServerFormats-CrRnjjf6.mjs.map +1 -0
  234. package/dist/ServerFormats-DjC9NsO_.d.mts +36 -0
  235. package/dist/ServiceDescription-BERsvg-k.d.mts +54 -0
  236. package/dist/ServiceDescription-Dq5hxeGy.mjs +97 -0
  237. package/dist/ServiceDescription-Dq5hxeGy.mjs.map +1 -0
  238. package/dist/ShExC-Ctf-06CL.d.mts +67 -0
  239. package/dist/ShExC-DJbB19i3.mjs +1181 -0
  240. package/dist/ShExC-DJbB19i3.mjs.map +1 -0
  241. package/dist/ShExError-BeYFD9rv.d.mts +61 -0
  242. package/dist/ShExError-CVtq2NnM.mjs +64 -0
  243. package/dist/ShExError-CVtq2NnM.mjs.map +1 -0
  244. package/dist/ShExJ-C1u_wgyD.d.mts +531 -0
  245. package/dist/ShExJ-COiPd9Xw.mjs +532 -0
  246. package/dist/ShExJ-COiPd9Xw.mjs.map +1 -0
  247. package/dist/ShExR-ByR4mCh-.mjs +480 -0
  248. package/dist/ShExR-ByR4mCh-.mjs.map +1 -0
  249. package/dist/ShExR-CqONNNBz.d.mts +40 -0
  250. package/dist/ShapeMap-C422pxKl.d.mts +140 -0
  251. package/dist/ShapeMap-CsgKxB2G.mjs +181 -0
  252. package/dist/ShapeMap-CsgKxB2G.mjs.map +1 -0
  253. package/dist/Shapes-18GjfyBV.mjs +597 -0
  254. package/dist/Shapes-18GjfyBV.mjs.map +1 -0
  255. package/dist/Shapes-BQFDFc4Q.d.mts +306 -0
  256. package/dist/Sparql-BiYFMSpl.mjs +29 -0
  257. package/dist/Sparql-BiYFMSpl.mjs.map +1 -0
  258. package/dist/Sparql-DecpWTPh.d.mts +97 -0
  259. package/dist/SparqlClient-C_CjXbwj.mjs +333 -0
  260. package/dist/SparqlClient-C_CjXbwj.mjs.map +1 -0
  261. package/dist/SparqlClient-UPc88SHy.d.mts +290 -0
  262. package/dist/SparqlServer-CbUW-pVj.d.mts +71 -0
  263. package/dist/SparqlServer-Db7w7Cll.mjs +308 -0
  264. package/dist/SparqlServer-Db7w7Cll.mjs.map +1 -0
  265. package/dist/SqlStore-BBqFx-Wl.mjs +684 -0
  266. package/dist/SqlStore-BBqFx-Wl.mjs.map +1 -0
  267. package/dist/SqlStore-CCJo5I-e.d.mts +117 -0
  268. package/dist/Store-D0jmVfb3.d.mts +166 -0
  269. package/dist/Store-DH3Ow1GO.mjs +162 -0
  270. package/dist/Store-DH3Ow1GO.mjs.map +1 -0
  271. package/dist/Structure-BjMo4Bkc.mjs +334 -0
  272. package/dist/Structure-BjMo4Bkc.mjs.map +1 -0
  273. package/dist/Structure-n4CmDiab.d.mts +63 -0
  274. package/dist/Table-BGgm9nbM.mjs +538 -0
  275. package/dist/Table-BGgm9nbM.mjs.map +1 -0
  276. package/dist/Table-C3reiVrb.d.mts +261 -0
  277. package/dist/Term-B_4ezyXq.d.mts +619 -0
  278. package/dist/Term-CFLG1qu4.mjs +991 -0
  279. package/dist/Term-CFLG1qu4.mjs.map +1 -0
  280. package/dist/Term.d.mts +2 -0
  281. package/dist/Term.mjs +1 -0
  282. package/dist/TermCodec-CDZiEztW.mjs +397 -0
  283. package/dist/TermCodec-CDZiEztW.mjs.map +1 -0
  284. package/dist/TermCodec-_03bDXr0.d.mts +209 -0
  285. package/dist/TermCodec.d.mts +2 -0
  286. package/dist/TermCodec.mjs +1 -0
  287. package/dist/TermJson-BOPe0yve.d.mts +232 -0
  288. package/dist/TermJson-FAg3lvjl.mjs +142 -0
  289. package/dist/TermJson-FAg3lvjl.mjs.map +1 -0
  290. package/dist/TermJson.d.mts +2 -0
  291. package/dist/TermJson.mjs +1 -0
  292. package/dist/TermSchema-Bn9CoaYA.mjs +30 -0
  293. package/dist/TermSchema-Bn9CoaYA.mjs.map +1 -0
  294. package/dist/TermSchema-DBO6MroX.d.mts +6 -0
  295. package/dist/Testing-B-aPCpmu.mjs +63 -0
  296. package/dist/Testing-B-aPCpmu.mjs.map +1 -0
  297. package/dist/Testing-CF6s8P3O.d.mts +53 -0
  298. package/dist/Tiff-CR-2QeSI.d.mts +148 -0
  299. package/dist/Tiff-DlsOlZPM.mjs +169 -0
  300. package/dist/Tiff-DlsOlZPM.mjs.map +1 -0
  301. package/dist/Tools-7MdRKccr.d.mts +583 -0
  302. package/dist/Tools-ryxphZbI.mjs +329 -0
  303. package/dist/Tools-ryxphZbI.mjs.map +1 -0
  304. package/dist/Translate-B0YKKANS.d.mts +37 -0
  305. package/dist/Translate-gzWPq0Ia.mjs +308 -0
  306. package/dist/Translate-gzWPq0Ia.mjs.map +1 -0
  307. package/dist/Translation-DC9rLm2y.mjs +1535 -0
  308. package/dist/Translation-DC9rLm2y.mjs.map +1 -0
  309. package/dist/Translation-K4L9XBqX.d.mts +103 -0
  310. package/dist/TriG-BkqtqZ6Y.mjs +125 -0
  311. package/dist/TriG-BkqtqZ6Y.mjs.map +1 -0
  312. package/dist/TriG-xDjdDatp.d.mts +86 -0
  313. package/dist/Turtle-Bv1_bisW.d.mts +85 -0
  314. package/dist/Turtle-CZVUOtwl.mjs +133 -0
  315. package/dist/Turtle-CZVUOtwl.mjs.map +1 -0
  316. package/dist/ValidationReport-DBdJshW5.mjs +285 -0
  317. package/dist/ValidationReport-DBdJshW5.mjs.map +1 -0
  318. package/dist/ValidationReport-Dx3WxY0h.d.mts +192 -0
  319. package/dist/Validator-227ff9Rn.d.mts +179 -0
  320. package/dist/Validator-BzXMKDeJ.mjs +1162 -0
  321. package/dist/Validator-BzXMKDeJ.mjs.map +1 -0
  322. package/dist/Validator-Dl8cih5V.d.mts +207 -0
  323. package/dist/Validator-DmUfMbpL.mjs +568 -0
  324. package/dist/Validator-DmUfMbpL.mjs.map +1 -0
  325. package/dist/Vocab-DceKywpq.mjs +168 -0
  326. package/dist/Vocab-DceKywpq.mjs.map +1 -0
  327. package/dist/Vocab-Df-L-IwZ.d.mts +46 -0
  328. package/dist/Vocab-Do56UgBX.d.mts +81 -0
  329. package/dist/Vocab-TfpWG1Ne.mjs +118 -0
  330. package/dist/Vocab-TfpWG1Ne.mjs.map +1 -0
  331. package/dist/Vocab.d.mts +2 -0
  332. package/dist/Vocab.mjs +1 -0
  333. package/dist/Vocabulary-C6-GPOy4.d.mts +22 -0
  334. package/dist/Vocabulary-CnQl-_Z4.mjs +179 -0
  335. package/dist/Vocabulary-CnQl-_Z4.mjs.map +1 -0
  336. package/dist/Xml-B7iihYCS.mjs +976 -0
  337. package/dist/Xml-B7iihYCS.mjs.map +1 -0
  338. package/dist/Xml-CmfHS7SW.d.mts +267 -0
  339. package/dist/Xmp-D7CKA7MZ.d.mts +111 -0
  340. package/dist/Xmp-DCGN9pOD.mjs +307 -0
  341. package/dist/Xmp-DCGN9pOD.mjs.map +1 -0
  342. package/dist/XmpBasic-CP38jpR_.mjs +73 -0
  343. package/dist/XmpBasic-CP38jpR_.mjs.map +1 -0
  344. package/dist/XmpBasic-Cmbe53rQ.d.mts +64 -0
  345. package/dist/XmpMM-BfL_TgJF.mjs +73 -0
  346. package/dist/XmpMM-BfL_TgJF.mjs.map +1 -0
  347. package/dist/XmpMM-Dqm3IX8p.d.mts +63 -0
  348. package/dist/XmpRights-BKPtoI5L.mjs +73 -0
  349. package/dist/XmpRights-BKPtoI5L.mjs.map +1 -0
  350. package/dist/XmpRights-CaALZQz2.d.mts +63 -0
  351. package/dist/Xsd-Cdgx5zRB.mjs +405 -0
  352. package/dist/Xsd-Cdgx5zRB.mjs.map +1 -0
  353. package/dist/Xsd-D2elNhSm.d.mts +187 -0
  354. package/dist/Xsd.d.mts +2 -0
  355. package/dist/Xsd.mjs +1 -0
  356. package/dist/accessors-CEjaojuQ.mjs +28 -0
  357. package/dist/accessors-CEjaojuQ.mjs.map +1 -0
  358. package/dist/codec-Lb2T96rv.d.mts +20 -0
  359. package/dist/codec-QNo7IdJF.mjs +389 -0
  360. package/dist/codec-QNo7IdJF.mjs.map +1 -0
  361. package/dist/csvw/Csv2Json.d.mts +2 -0
  362. package/dist/csvw/Csv2Json.mjs +1 -0
  363. package/dist/csvw/Csv2Rdf.d.mts +2 -0
  364. package/dist/csvw/Csv2Rdf.mjs +1 -0
  365. package/dist/csvw/Datatype.d.mts +2 -0
  366. package/dist/csvw/Datatype.mjs +1 -0
  367. package/dist/csvw/Metadata.d.mts +2 -0
  368. package/dist/csvw/Metadata.mjs +1 -0
  369. package/dist/csvw/Processor.d.mts +2 -0
  370. package/dist/csvw/Processor.mjs +1 -0
  371. package/dist/csvw/Report.d.mts +2 -0
  372. package/dist/csvw/Report.mjs +1 -0
  373. package/dist/csvw/Table.d.mts +2 -0
  374. package/dist/csvw/Table.mjs +1 -0
  375. package/dist/csvw/index.d.mts +8 -0
  376. package/dist/csvw/index.mjs +8 -0
  377. package/dist/index-Cms2TYfC.d.mts +16 -0
  378. package/dist/index-Ct8xFmRs.d.mts +7 -0
  379. package/dist/index-D4QFwOjm.d.mts +28 -0
  380. package/dist/index.d.mts +18 -0
  381. package/dist/index.mjs +17 -0
  382. package/dist/jsonld/DocumentLoader.d.mts +2 -0
  383. package/dist/jsonld/DocumentLoader.mjs +1 -0
  384. package/dist/jsonld/JsonLd.d.mts +2 -0
  385. package/dist/jsonld/JsonLd.mjs +1 -0
  386. package/dist/jsonld/JsonLdError.d.mts +2 -0
  387. package/dist/jsonld/JsonLdError.mjs +1 -0
  388. package/dist/jsonld/index.d.mts +4 -0
  389. package/dist/jsonld/index.mjs +4 -0
  390. package/dist/lists-D-OpQ0Ir.mjs +77 -0
  391. package/dist/lists-D-OpQ0Ir.mjs.map +1 -0
  392. package/dist/loop-D5-gNx9K.mjs +21 -0
  393. package/dist/loop-D5-gNx9K.mjs.map +1 -0
  394. package/dist/loop-DZ2hXlr_.mjs +21 -0
  395. package/dist/loop-DZ2hXlr_.mjs.map +1 -0
  396. package/dist/n3/Isomorphism.d.mts +2 -0
  397. package/dist/n3/Isomorphism.mjs +1 -0
  398. package/dist/n3/Mapping.d.mts +2 -0
  399. package/dist/n3/Mapping.mjs +1 -0
  400. package/dist/n3/Model.d.mts +2 -0
  401. package/dist/n3/Model.mjs +1 -0
  402. package/dist/n3/N3.d.mts +2 -0
  403. package/dist/n3/N3.mjs +1 -0
  404. package/dist/n3/Reasoner.d.mts +2 -0
  405. package/dist/n3/Reasoner.mjs +2 -0
  406. package/dist/n3/Vocab.d.mts +2 -0
  407. package/dist/n3/Vocab.mjs +1 -0
  408. package/dist/n3/index.d.mts +7 -0
  409. package/dist/n3/index.mjs +7 -0
  410. package/dist/ntriples/Grammar.d.mts +2 -0
  411. package/dist/ntriples/Grammar.mjs +1 -0
  412. package/dist/ntriples/Lexical.d.mts +2 -0
  413. package/dist/ntriples/Lexical.mjs +1 -0
  414. package/dist/ntriples/NQuads.d.mts +2 -0
  415. package/dist/ntriples/NQuads.mjs +1 -0
  416. package/dist/ntriples/NTriples.d.mts +2 -0
  417. package/dist/ntriples/NTriples.mjs +1 -0
  418. package/dist/ntriples/index.d.mts +5 -0
  419. package/dist/ntriples/index.mjs +5 -0
  420. package/dist/rdfjson/RdfJson.d.mts +2 -0
  421. package/dist/rdfjson/RdfJson.mjs +1 -0
  422. package/dist/rdfjson/index.d.mts +2 -0
  423. package/dist/rdfjson/index.mjs +1 -0
  424. package/dist/rdfxml/RdfXml.d.mts +2 -0
  425. package/dist/rdfxml/RdfXml.mjs +1 -0
  426. package/dist/rdfxml/Xml.d.mts +2 -0
  427. package/dist/rdfxml/Xml.mjs +1 -0
  428. package/dist/rdfxml/index.d.mts +3 -0
  429. package/dist/rdfxml/index.mjs +3 -0
  430. package/dist/rolldown-runtime-D8jQpDG7.mjs +12 -0
  431. package/dist/serialize-96KBvKaf.mjs +1463 -0
  432. package/dist/serialize-96KBvKaf.mjs.map +1 -0
  433. package/dist/serialize-DsoXdM6n.d.mts +37 -0
  434. package/dist/shacl/Message.d.mts +2 -0
  435. package/dist/shacl/Message.mjs +1 -0
  436. package/dist/shacl/Path.d.mts +2 -0
  437. package/dist/shacl/Path.mjs +1 -0
  438. package/dist/shacl/Shapes.d.mts +2 -0
  439. package/dist/shacl/Shapes.mjs +1 -0
  440. package/dist/shacl/Sparql.d.mts +2 -0
  441. package/dist/shacl/Sparql.mjs +1 -0
  442. package/dist/shacl/ValidationReport.d.mts +2 -0
  443. package/dist/shacl/ValidationReport.mjs +1 -0
  444. package/dist/shacl/Validator.d.mts +2 -0
  445. package/dist/shacl/Validator.mjs +1 -0
  446. package/dist/shacl/Vocabulary.d.mts +2 -0
  447. package/dist/shacl/Vocabulary.mjs +1 -0
  448. package/dist/shacl/index.d.mts +9 -0
  449. package/dist/shacl/index.mjs +8 -0
  450. package/dist/shex/SemAct.d.mts +2 -0
  451. package/dist/shex/SemAct.mjs +1 -0
  452. package/dist/shex/ShExC.d.mts +2 -0
  453. package/dist/shex/ShExC.mjs +1 -0
  454. package/dist/shex/ShExError.d.mts +2 -0
  455. package/dist/shex/ShExError.mjs +1 -0
  456. package/dist/shex/ShExJ.d.mts +2 -0
  457. package/dist/shex/ShExJ.mjs +2 -0
  458. package/dist/shex/ShExR.d.mts +2 -0
  459. package/dist/shex/ShExR.mjs +1 -0
  460. package/dist/shex/ShapeMap.d.mts +2 -0
  461. package/dist/shex/ShapeMap.mjs +1 -0
  462. package/dist/shex/Structure.d.mts +2 -0
  463. package/dist/shex/Structure.mjs +2 -0
  464. package/dist/shex/Validator.d.mts +2 -0
  465. package/dist/shex/Validator.mjs +4 -0
  466. package/dist/shex/index.d.mts +9 -0
  467. package/dist/shex/index.mjs +9 -0
  468. package/dist/sparql/Algebra.d.mts +2 -0
  469. package/dist/sparql/Algebra.mjs +1 -0
  470. package/dist/sparql/Ast.d.mts +2 -0
  471. package/dist/sparql/Ast.mjs +1 -0
  472. package/dist/sparql/Bindings.d.mts +2 -0
  473. package/dist/sparql/Bindings.mjs +1 -0
  474. package/dist/sparql/ClientErrors.d.mts +2 -0
  475. package/dist/sparql/ClientErrors.mjs +1 -0
  476. package/dist/sparql/ClientFormats.d.mts +2 -0
  477. package/dist/sparql/ClientFormats.mjs +1 -0
  478. package/dist/sparql/Engine.d.mts +2 -0
  479. package/dist/sparql/Engine.mjs +1 -0
  480. package/dist/sparql/Errors.d.mts +2 -0
  481. package/dist/sparql/Errors.mjs +1 -0
  482. package/dist/sparql/Expression.d.mts +2 -0
  483. package/dist/sparql/Expression.mjs +1 -0
  484. package/dist/sparql/Federation.d.mts +2 -0
  485. package/dist/sparql/Federation.mjs +1 -0
  486. package/dist/sparql/Functions.d.mts +2 -0
  487. package/dist/sparql/Functions.mjs +1 -0
  488. package/dist/sparql/Generator.d.mts +2 -0
  489. package/dist/sparql/Generator.mjs +1 -0
  490. package/dist/sparql/GraphStore.d.mts +2 -0
  491. package/dist/sparql/GraphStore.mjs +1 -0
  492. package/dist/sparql/Optimizer.d.mts +2 -0
  493. package/dist/sparql/Optimizer.mjs +1 -0
  494. package/dist/sparql/Options.d.mts +2 -0
  495. package/dist/sparql/Options.mjs +1 -0
  496. package/dist/sparql/Parser.d.mts +2 -0
  497. package/dist/sparql/Parser.mjs +1 -0
  498. package/dist/sparql/Protocol.d.mts +2 -0
  499. package/dist/sparql/Protocol.mjs +1 -0
  500. package/dist/sparql/ProtocolErrors.d.mts +2 -0
  501. package/dist/sparql/ProtocolErrors.mjs +1 -0
  502. package/dist/sparql/QueryBuilder.d.mts +2 -0
  503. package/dist/sparql/QueryBuilder.mjs +1 -0
  504. package/dist/sparql/Results.d.mts +2 -0
  505. package/dist/sparql/Results.mjs +1 -0
  506. package/dist/sparql/ResultsStream.d.mts +2 -0
  507. package/dist/sparql/ResultsStream.mjs +1 -0
  508. package/dist/sparql/ServerFormats.d.mts +2 -0
  509. package/dist/sparql/ServerFormats.mjs +1 -0
  510. package/dist/sparql/ServiceDescription.d.mts +2 -0
  511. package/dist/sparql/ServiceDescription.mjs +1 -0
  512. package/dist/sparql/SparqlClient.d.mts +2 -0
  513. package/dist/sparql/SparqlClient.mjs +1 -0
  514. package/dist/sparql/SparqlServer.d.mts +2 -0
  515. package/dist/sparql/SparqlServer.mjs +1 -0
  516. package/dist/sparql/Store.d.mts +2 -0
  517. package/dist/sparql/Store.mjs +1 -0
  518. package/dist/sparql/TermSchema.d.mts +3 -0
  519. package/dist/sparql/TermSchema.mjs +2 -0
  520. package/dist/sparql/Testing.d.mts +2 -0
  521. package/dist/sparql/Testing.mjs +1 -0
  522. package/dist/sparql/Translate.d.mts +2 -0
  523. package/dist/sparql/Translate.mjs +1 -0
  524. package/dist/sparql/ai/Mcp.d.mts +2 -0
  525. package/dist/sparql/ai/Mcp.mjs +1 -0
  526. package/dist/sparql/ai/Tools.d.mts +2 -0
  527. package/dist/sparql/ai/Tools.mjs +1 -0
  528. package/dist/sparql/ai/index.d.mts +3 -0
  529. package/dist/sparql/ai/index.mjs +3 -0
  530. package/dist/sparql/index.d.mts +30 -0
  531. package/dist/sparql/index.mjs +29 -0
  532. package/dist/sparql/shacl/Evaluator.d.mts +2 -0
  533. package/dist/sparql/shacl/Evaluator.mjs +1 -0
  534. package/dist/sparql/shacl/Query.d.mts +2 -0
  535. package/dist/sparql/shacl/Query.mjs +1 -0
  536. package/dist/sparql/shacl/index.d.mts +3 -0
  537. package/dist/sparql/shacl/index.mjs +3 -0
  538. package/dist/sparql/sql/Dialect.d.mts +2 -0
  539. package/dist/sparql/sql/Dialect.mjs +1 -0
  540. package/dist/sparql/sql/SqlStore.d.mts +2 -0
  541. package/dist/sparql/sql/SqlStore.mjs +1 -0
  542. package/dist/sparql/sql/Translation.d.mts +2 -0
  543. package/dist/sparql/sql/Translation.mjs +1 -0
  544. package/dist/sparql/sql/index.d.mts +4 -0
  545. package/dist/sparql/sql/index.mjs +4 -0
  546. package/dist/stringMap-D5YIpYtR.mjs +38 -0
  547. package/dist/stringMap-D5YIpYtR.mjs.map +1 -0
  548. package/dist/tokens-C6BzeodQ.mjs +24 -0
  549. package/dist/tokens-C6BzeodQ.mjs.map +1 -0
  550. package/dist/turtle/Grammar.d.mts +3 -0
  551. package/dist/turtle/Grammar.mjs +3 -0
  552. package/dist/turtle/Manifest.d.mts +2 -0
  553. package/dist/turtle/Manifest.mjs +1 -0
  554. package/dist/turtle/TriG.d.mts +2 -0
  555. package/dist/turtle/TriG.mjs +1 -0
  556. package/dist/turtle/Turtle.d.mts +2 -0
  557. package/dist/turtle/Turtle.mjs +1 -0
  558. package/dist/turtle/index.d.mts +5 -0
  559. package/dist/turtle/index.mjs +5 -0
  560. package/dist/xmp/DublinCore.d.mts +2 -0
  561. package/dist/xmp/DublinCore.mjs +1 -0
  562. package/dist/xmp/Exif.d.mts +2 -0
  563. package/dist/xmp/Exif.mjs +1 -0
  564. package/dist/xmp/Extract.d.mts +2 -0
  565. package/dist/xmp/Extract.mjs +1 -0
  566. package/dist/xmp/Metadata.d.mts +2 -0
  567. package/dist/xmp/Metadata.mjs +1 -0
  568. package/dist/xmp/Namespaces.d.mts +2 -0
  569. package/dist/xmp/Namespaces.mjs +1 -0
  570. package/dist/xmp/Packet.d.mts +2 -0
  571. package/dist/xmp/Packet.mjs +1 -0
  572. package/dist/xmp/Pdf.d.mts +2 -0
  573. package/dist/xmp/Pdf.mjs +1 -0
  574. package/dist/xmp/PdfA.d.mts +2 -0
  575. package/dist/xmp/PdfA.mjs +1 -0
  576. package/dist/xmp/Photoshop.d.mts +2 -0
  577. package/dist/xmp/Photoshop.mjs +1 -0
  578. package/dist/xmp/Tiff.d.mts +2 -0
  579. package/dist/xmp/Tiff.mjs +1 -0
  580. package/dist/xmp/Xmp.d.mts +2 -0
  581. package/dist/xmp/Xmp.mjs +3 -0
  582. package/dist/xmp/XmpBasic.d.mts +2 -0
  583. package/dist/xmp/XmpBasic.mjs +1 -0
  584. package/dist/xmp/XmpMM.d.mts +2 -0
  585. package/dist/xmp/XmpMM.mjs +1 -0
  586. package/dist/xmp/XmpRights.d.mts +2 -0
  587. package/dist/xmp/XmpRights.mjs +1 -0
  588. package/dist/xmp/index.d.mts +15 -0
  589. package/dist/xmp/index.mjs +15 -0
  590. package/package.json +187 -3
  591. package/src/Dataset.ts +1085 -0
  592. package/src/Iri.ts +322 -0
  593. package/src/Isomorphism.ts +319 -0
  594. package/src/LanguageTag.ts +98 -0
  595. package/src/Namespace.ts +100 -0
  596. package/src/PrefixMap.ts +117 -0
  597. package/src/RdfJs.ts +146 -0
  598. package/src/Rdfs.ts +241 -0
  599. package/src/Reification.ts +103 -0
  600. package/src/Resource.ts +873 -0
  601. package/src/Serialization.ts +775 -0
  602. package/src/Term.ts +1300 -0
  603. package/src/TermCodec.ts +505 -0
  604. package/src/TermJson.ts +313 -0
  605. package/src/Vocab.ts +161 -0
  606. package/src/Xsd.ts +573 -0
  607. package/src/csvw/Csv2Json.ts +265 -0
  608. package/src/csvw/Csv2Rdf.ts +268 -0
  609. package/src/csvw/Datatype.ts +589 -0
  610. package/src/csvw/Metadata.ts +1523 -0
  611. package/src/csvw/Processor.ts +276 -0
  612. package/src/csvw/Report.ts +135 -0
  613. package/src/csvw/Table.ts +759 -0
  614. package/src/csvw/index.ts +22 -0
  615. package/src/csvw/internal/dateFormat.ts +202 -0
  616. package/src/csvw/internal/json.ts +104 -0
  617. package/src/csvw/internal/numberFormat.ts +369 -0
  618. package/src/csvw/internal/object.ts +23 -0
  619. package/src/csvw/internal/uriTemplate.ts +130 -0
  620. package/src/csvw/internal/url.ts +93 -0
  621. package/src/csvw/internal/vocab.ts +282 -0
  622. package/src/index.ts +40 -0
  623. package/src/internal/arbitrary.ts +148 -0
  624. package/src/internal/loop.ts +24 -0
  625. package/src/internal/pending.ts +20 -0
  626. package/src/internal/textDecoder.ts +183 -0
  627. package/src/jsonld/DocumentLoader.ts +512 -0
  628. package/src/jsonld/JsonLd.ts +847 -0
  629. package/src/jsonld/JsonLdError.ts +105 -0
  630. package/src/jsonld/index.ts +13 -0
  631. package/src/jsonld/internal/compact.ts +852 -0
  632. package/src/jsonld/internal/context.ts +781 -0
  633. package/src/jsonld/internal/expand.ts +614 -0
  634. package/src/jsonld/internal/flatten.ts +243 -0
  635. package/src/jsonld/internal/frame.ts +559 -0
  636. package/src/jsonld/internal/iri.ts +52 -0
  637. package/src/jsonld/internal/json.ts +19 -0
  638. package/src/jsonld/internal/linkHeader.ts +60 -0
  639. package/src/jsonld/internal/rdf.ts +481 -0
  640. package/src/jsonld/internal/util.ts +367 -0
  641. package/src/n3/Isomorphism.ts +476 -0
  642. package/src/n3/Mapping.ts +332 -0
  643. package/src/n3/Model.ts +696 -0
  644. package/src/n3/N3.ts +237 -0
  645. package/src/n3/Reasoner.ts +568 -0
  646. package/src/n3/Vocab.ts +111 -0
  647. package/src/n3/index.ts +21 -0
  648. package/src/n3/internal/builtins.ts +668 -0
  649. package/src/n3/internal/guards.ts +23 -0
  650. package/src/n3/internal/lists.ts +106 -0
  651. package/src/n3/internal/loop.ts +28 -0
  652. package/src/n3/internal/parser.ts +1032 -0
  653. package/src/n3/internal/writer.ts +344 -0
  654. package/src/ntriples/Grammar.ts +317 -0
  655. package/src/ntriples/Lexical.ts +321 -0
  656. package/src/ntriples/NQuads.ts +140 -0
  657. package/src/ntriples/NTriples.ts +143 -0
  658. package/src/ntriples/index.ts +14 -0
  659. package/src/ntriples/internal/codec.ts +229 -0
  660. package/src/ntriples/internal/lineParser.ts +326 -0
  661. package/src/ntriples/internal/loop.ts +14 -0
  662. package/src/rdfjson/RdfJson.ts +806 -0
  663. package/src/rdfjson/index.ts +9 -0
  664. package/src/rdfjson/internal/json.ts +19 -0
  665. package/src/rdfxml/RdfXml.ts +1408 -0
  666. package/src/rdfxml/Xml.ts +419 -0
  667. package/src/rdfxml/index.ts +11 -0
  668. package/src/rdfxml/internal/chars.ts +73 -0
  669. package/src/rdfxml/internal/loop.ts +24 -0
  670. package/src/rdfxml/internal/parser.ts +1265 -0
  671. package/src/shacl/Message.ts +102 -0
  672. package/src/shacl/Path.ts +483 -0
  673. package/src/shacl/Shapes.ts +913 -0
  674. package/src/shacl/Sparql.ts +128 -0
  675. package/src/shacl/ValidationReport.ts +438 -0
  676. package/src/shacl/Validator.ts +1156 -0
  677. package/src/shacl/Vocabulary.ts +180 -0
  678. package/src/shacl/index.ts +22 -0
  679. package/src/shacl/internal/compare.ts +128 -0
  680. package/src/shacl/internal/regex.ts +56 -0
  681. package/src/shex/SemAct.ts +197 -0
  682. package/src/shex/ShExC.ts +415 -0
  683. package/src/shex/ShExError.ts +71 -0
  684. package/src/shex/ShExJ.ts +893 -0
  685. package/src/shex/ShExR.ts +640 -0
  686. package/src/shex/ShapeMap.ts +385 -0
  687. package/src/shex/Structure.ts +467 -0
  688. package/src/shex/Validator.ts +395 -0
  689. package/src/shex/index.ts +24 -0
  690. package/src/shex/internal/engine.ts +682 -0
  691. package/src/shex/internal/iterate.ts +14 -0
  692. package/src/shex/internal/json.ts +12 -0
  693. package/src/shex/internal/lexer.ts +56 -0
  694. package/src/shex/internal/nodeConstraint.ts +368 -0
  695. package/src/shex/internal/shexcLexer.ts +387 -0
  696. package/src/shex/internal/shexcParser.ts +1312 -0
  697. package/src/shex/internal/tokens.ts +41 -0
  698. package/src/shex/internal/xpathRegex.ts +290 -0
  699. package/src/sparql/Algebra.ts +914 -0
  700. package/src/sparql/Ast.ts +1344 -0
  701. package/src/sparql/Bindings.ts +272 -0
  702. package/src/sparql/ClientErrors.ts +156 -0
  703. package/src/sparql/ClientFormats.ts +70 -0
  704. package/src/sparql/Engine.ts +699 -0
  705. package/src/sparql/Errors.ts +30 -0
  706. package/src/sparql/Expression.ts +360 -0
  707. package/src/sparql/Federation.ts +187 -0
  708. package/src/sparql/Functions.ts +689 -0
  709. package/src/sparql/Generator.ts +426 -0
  710. package/src/sparql/GraphStore.ts +341 -0
  711. package/src/sparql/Optimizer.ts +230 -0
  712. package/src/sparql/Options.ts +191 -0
  713. package/src/sparql/Parser.ts +173 -0
  714. package/src/sparql/Protocol.ts +342 -0
  715. package/src/sparql/ProtocolErrors.ts +113 -0
  716. package/src/sparql/QueryBuilder.ts +953 -0
  717. package/src/sparql/Results.ts +844 -0
  718. package/src/sparql/ResultsStream.ts +771 -0
  719. package/src/sparql/ServerFormats.ts +75 -0
  720. package/src/sparql/ServiceDescription.ts +130 -0
  721. package/src/sparql/SparqlClient.ts +947 -0
  722. package/src/sparql/SparqlServer.ts +528 -0
  723. package/src/sparql/Store.ts +311 -0
  724. package/src/sparql/TermSchema.ts +20 -0
  725. package/src/sparql/Testing.ts +114 -0
  726. package/src/sparql/Translate.ts +407 -0
  727. package/src/sparql/ai/Mcp.ts +43 -0
  728. package/src/sparql/ai/Tools.ts +481 -0
  729. package/src/sparql/ai/index.ts +11 -0
  730. package/src/sparql/index.ts +64 -0
  731. package/src/sparql/internal/evaluator.ts +947 -0
  732. package/src/sparql/internal/hash.ts +418 -0
  733. package/src/sparql/internal/json.ts +12 -0
  734. package/src/sparql/internal/lexer.ts +488 -0
  735. package/src/sparql/internal/loop.ts +24 -0
  736. package/src/sparql/internal/parser.ts +2215 -0
  737. package/src/sparql/internal/prefetch.ts +46 -0
  738. package/src/sparql/internal/stringMap.ts +39 -0
  739. package/src/sparql/internal/textResults.ts +226 -0
  740. package/src/sparql/internal/values.ts +550 -0
  741. package/src/sparql/shacl/Evaluator.ts +478 -0
  742. package/src/sparql/shacl/Query.ts +574 -0
  743. package/src/sparql/shacl/index.ts +12 -0
  744. package/src/sparql/sql/Dialect.ts +246 -0
  745. package/src/sparql/sql/SqlStore.ts +1080 -0
  746. package/src/sparql/sql/Translation.ts +1898 -0
  747. package/src/sparql/sql/index.ts +17 -0
  748. package/src/sparql/sql/internal/encoding.ts +313 -0
  749. package/src/turtle/Grammar.ts +286 -0
  750. package/src/turtle/Manifest.ts +215 -0
  751. package/src/turtle/TriG.ts +158 -0
  752. package/src/turtle/Turtle.ts +166 -0
  753. package/src/turtle/index.ts +14 -0
  754. package/src/turtle/internal/loop.ts +23 -0
  755. package/src/turtle/internal/parse.ts +112 -0
  756. package/src/turtle/internal/parser.ts +1303 -0
  757. package/src/turtle/internal/serialize.ts +79 -0
  758. package/src/turtle/internal/streamWriter.ts +128 -0
  759. package/src/turtle/internal/writer.ts +898 -0
  760. package/src/xmp/DublinCore.ts +147 -0
  761. package/src/xmp/Exif.ts +109 -0
  762. package/src/xmp/Extract.ts +351 -0
  763. package/src/xmp/Metadata.ts +703 -0
  764. package/src/xmp/Namespaces.ts +228 -0
  765. package/src/xmp/Packet.ts +297 -0
  766. package/src/xmp/Pdf.ts +99 -0
  767. package/src/xmp/PdfA.ts +280 -0
  768. package/src/xmp/Photoshop.ts +275 -0
  769. package/src/xmp/Tiff.ts +196 -0
  770. package/src/xmp/Xmp.ts +430 -0
  771. package/src/xmp/XmpBasic.ts +90 -0
  772. package/src/xmp/XmpMM.ts +82 -0
  773. package/src/xmp/XmpRights.ts +83 -0
  774. package/src/xmp/index.ts +36 -0
  775. package/src/xmp/internal/accessors.ts +72 -0
  776. package/src/xmp/internal/xml.ts +63 -0
@@ -0,0 +1,1265 @@
1
+ /**
2
+ * The XML 1.0 parser behind `Xml.parse`: a compiled
3
+ * `@thomasfosterau/effect-parse` grammar over the (line-end normalised)
4
+ * input, building the document tree as it reads.
5
+ *
6
+ * Element content is read by one loop over start tags, end tags, text and
7
+ * the other markup, with the open elements on an explicit stack, so deeply
8
+ * nested documents cannot exhaust the call stack. Errors are thrown (as a
9
+ * `Failure` at an offset) out of the grammar.
10
+ *
11
+ * The parser guards against hostile documents:
12
+ *
13
+ * - external entities and parameter entities are never loaded;
14
+ * - the replacement text of entity references may add up to at most
15
+ * `MAX_ENTITY_EXPANSION` characters (which defeats "billion laughs");
16
+ * - entity references nest at most `MAX_ENTITY_DEPTH` deep, and elements at
17
+ * most `MAX_ELEMENT_DEPTH` deep;
18
+ * - the replacement text of an entity that contains markup is parsed with
19
+ * the document's tables, not copies of them, so that many such entities
20
+ * and references cost time in proportion to the text expanded.
21
+ *
22
+ * @internal
23
+ */
24
+ import * as Compiler from '@thomasfosterau/effect-parse/Compiler';
25
+ import * as Parser from '@thomasfosterau/effect-parse/Parser';
26
+ import * as Token from '@thomasfosterau/effect-parse/Token';
27
+ import * as Arr from 'effect/Array';
28
+ import { constFalse } from 'effect/Function';
29
+ import * as HashSet from 'effect/HashSet';
30
+ import * as MutableHashMap from 'effect/MutableHashMap';
31
+ import * as MutableHashSet from 'effect/MutableHashSet';
32
+ import * as Option from 'effect/Option';
33
+ import * as Predicate from 'effect/Predicate';
34
+ import * as Result from 'effect/Result';
35
+ import type * as Xml from '../Xml.ts';
36
+ import {
37
+ INVALID_CHAR_RE,
38
+ isName,
39
+ isNCName,
40
+ isValidText,
41
+ nameChar,
42
+ nameStart,
43
+ NMTOKEN_RE,
44
+ PUBID_RE,
45
+ space,
46
+ } from './chars.ts';
47
+ import { loop } from './loop.ts';
48
+
49
+ const XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
50
+ const XMLNS_NAMESPACE = 'http://www.w3.org/2000/xmlns/';
51
+
52
+ /** The most replacement text that entity references may add to a document. */
53
+ export const MAX_ENTITY_EXPANSION = 1_000_000;
54
+
55
+ /** How deeply entity references may nest. */
56
+ export const MAX_ENTITY_DEPTH = 64;
57
+
58
+ /** How deeply elements may nest. */
59
+ export const MAX_ELEMENT_DEPTH = 1024;
60
+
61
+ /** A well-formedness error at an offset, thrown out of the grammar. */
62
+ export class Failure {
63
+ readonly message: string;
64
+ readonly offset: number;
65
+ /** Where in the document the error is: set by `parseText`, from `offset`. */
66
+ position: Xml.Position;
67
+ constructor(message: string, offset: number) {
68
+ this.message = message;
69
+ this.offset = offset;
70
+ this.position = { offset, line: 0, column: 0 };
71
+ }
72
+ }
73
+
74
+ type P<A> = Parser.Parser<A>;
75
+
76
+ interface AttributeDefault {
77
+ readonly name: string;
78
+ readonly value: string;
79
+ readonly tokenized: boolean;
80
+ }
81
+
82
+ interface RawAttribute {
83
+ readonly name: string;
84
+ value: string;
85
+ readonly offset: number;
86
+ readonly defaulted: boolean;
87
+ }
88
+
89
+ /** An open element (or the content an entity's replacement text adds). */
90
+ interface Frame {
91
+ readonly qname: string;
92
+ /** Where its start tag is (found as it is read, when the last position found is near). */
93
+ readonly position: Xml.Position;
94
+ readonly prefix: string;
95
+ readonly localName: string;
96
+ readonly namespace: Option.Option<string>;
97
+ readonly attributes: ReadonlyArray<Xml.Attribute>;
98
+ readonly declarations: ReadonlyArray<Xml.NamespaceDeclaration>;
99
+ readonly inScope: ReadonlyMap<string, string>;
100
+ readonly children: Array<Xml.Node>;
101
+ text: string;
102
+ textStart: number;
103
+ /** Whether the last of `children` is a text node (so `text` may merge into it). */
104
+ endsWithText: boolean;
105
+ /** How many children precede the last child taken by a `RootChildHook`: text never merges into them. */
106
+ floor: number;
107
+ }
108
+
109
+ /** The replacement text of a predefined entity, or `''` if `entity` is not one. */
110
+ const predefined = (entity: string): string =>
111
+ entity === 'lt'
112
+ ? '<'
113
+ : entity === 'gt'
114
+ ? '>'
115
+ : entity === 'amp'
116
+ ? '&'
117
+ : entity === 'apos'
118
+ ? "'"
119
+ : entity === 'quot'
120
+ ? '"'
121
+ : '';
122
+
123
+ /** The types (tokenized or not) and defaults an `<!ATTLIST>` declares for an element. */
124
+ interface AttributeList {
125
+ readonly types: MutableHashMap.MutableHashMap<string, boolean>;
126
+ readonly defaults: Array<AttributeDefault>;
127
+ }
128
+
129
+ const baseFrame = (inScope: ReadonlyMap<string, string>): Frame => ({
130
+ qname: '',
131
+ position: { offset: 0, line: 0, column: 0 },
132
+ prefix: '',
133
+ localName: '',
134
+ namespace: Option.none(),
135
+ attributes: [],
136
+ declarations: [],
137
+ inScope,
138
+ children: [],
139
+ text: '',
140
+ textStart: -1,
141
+ endsWithText: false,
142
+ floor: 0,
143
+ });
144
+
145
+ /** Whether `offset` is on line `l` (from 0) of the text whose line starts are `starts`. */
146
+ const onLine = (starts: ReadonlyArray<number>, l: number, offset: number): boolean =>
147
+ (starts[l] ?? Infinity) <= offset && offset < (starts[l + 1] ?? Infinity);
148
+
149
+ /** The line (from 0) of `offset` among lines `lo … hi` of the text whose line starts are `starts`. */
150
+ const lineIndex = (
151
+ starts: ReadonlyArray<number>,
152
+ offset: number,
153
+ lo: number,
154
+ hi: number,
155
+ ): number => {
156
+ if (lo >= hi) return lo;
157
+ const mid = (lo + hi + 1) >> 1;
158
+ return (starts[mid] ?? 0) <= offset
159
+ ? lineIndex(starts, offset, mid, hi)
160
+ : lineIndex(starts, offset, lo, mid - 1);
161
+ };
162
+
163
+ /**
164
+ * Receives each child element of the root as soon as it is closed, with the
165
+ * root element as read so far (its `children` are those not taken). Returns
166
+ * `true` to take the child, which is then left out of the document.
167
+ *
168
+ * @internal
169
+ */
170
+ export type RootChildHook = (child: Xml.Element, root: Xml.Element) => boolean;
171
+
172
+ const keepChild: RootChildHook = () => false;
173
+
174
+ /** Up to how many attributes a start tag's duplicates are found by searching its list. */
175
+ const SMALL = 16;
176
+
177
+ /** Stands for the declarations of an `<!ATTLIST>` until one is read. */
178
+ const NO_ATTRIBUTE_LIST: AttributeList = { types: MutableHashMap.empty(), defaults: [] };
179
+
180
+ /** Stands for the set of a start tag's expanded names while it has too few to need one. */
181
+ const UNUSED: MutableHashSet.MutableHashSet<string> = MutableHashSet.empty();
182
+
183
+ /** The document being parsed. */
184
+ class Context {
185
+ /** The text being parsed: the document, or an entity's replacement text. */
186
+ src: string;
187
+ lineStarts: ReadonlyArray<number>;
188
+ readonly entities = MutableHashMap.empty<string, string>();
189
+ readonly externalEntities = MutableHashSet.empty<string>();
190
+ /** The `<!ATTLIST>` declarations, by element name. */
191
+ readonly attributeLists = MutableHashMap.empty<string, AttributeList>();
192
+ expanded = 0;
193
+ hasExternalSubset = false;
194
+
195
+ /** Takes a finished child of the root element instead of adding it to the root (`true`). */
196
+ onRootChild: RootChildHook = keepChild;
197
+
198
+ /** The frames of the open elements; those below `base` belong to enclosing text. */
199
+ stack: Arr.NonEmptyArray<Frame>;
200
+ base = 1;
201
+ /** The entities whose replacement text is being parsed. */
202
+ entityStack: HashSet.HashSet<string> = HashSet.empty();
203
+
204
+ // The parts of the document
205
+ version: Option.Option<string> = Option.none();
206
+ encoding: Option.Option<string> = Option.none();
207
+ standalone: Option.Option<boolean> = Option.none();
208
+ doctype: Option.Option<Xml.DocumentType> = Option.none();
209
+ readonly prolog: Array<Xml.Comment | Xml.ProcessingInstruction> = [];
210
+ readonly epilog: Array<Xml.Comment | Xml.ProcessingInstruction> = [];
211
+ root: Option.Option<Xml.Element> = Option.none();
212
+
213
+ // Registers for the markup being read (none of it nests)
214
+ tagStart = 0;
215
+ qname = '';
216
+ raw: Array<RawAttribute> = [];
217
+ /** The qualified names read so far, split (`nameParts`). */
218
+ readonly qnames = MutableHashMap.empty<string, readonly [prefix: string, local: string]>();
219
+ /** The names in `namesOf`, once it is too long to search. */
220
+ readonly names = MutableHashSet.empty<string>();
221
+ /** The attributes whose names `names` holds (cleared and refilled for each long start tag). */
222
+ namesOf: ReadonlyArray<RawAttribute> = [];
223
+ /** The declarations of the `<!ATTLIST>` being read (set as each is begun). */
224
+ attributeList: AttributeList = NO_ATTRIBUTE_LIST;
225
+ attributeName = '';
226
+ attributeType = '';
227
+ tokenized = false;
228
+
229
+ constructor(src: string, lineStarts: ReadonlyArray<number>) {
230
+ this.src = src;
231
+ this.lineStarts = lineStarts;
232
+ // `inScopeNamespaces` is a public `ReadonlyMap`
233
+ this.stack = [baseFrame(new Map())];
234
+ }
235
+
236
+ /** The line of the last position, where the next one usually is (offsets mostly increase). */
237
+ private line = 0;
238
+
239
+ position(offset: number): Xml.Position {
240
+ const starts = this.lineStarts;
241
+ // The last position's line, or the one after or before it (where the text before a tag
242
+ // starts), before a binary search
243
+ const line = this.line;
244
+ const lo = onLine(starts, line, offset)
245
+ ? line
246
+ : onLine(starts, line + 1, offset)
247
+ ? line + 1
248
+ : line > 0 && onLine(starts, line - 1, offset)
249
+ ? line - 1
250
+ : lineIndex(starts, offset, 0, starts.length - 1);
251
+ this.line = lo;
252
+ return { offset, line: lo + 1, column: offset - (starts[lo] ?? 0) + 1 };
253
+ }
254
+
255
+ /** Whether the start tag being read has an attribute `name` (adding it if not). */
256
+ hasAttribute(attribute: string): boolean {
257
+ if (this.raw.length < SMALL) return this.raw.some((a) => a.name === attribute);
258
+ const names = this.names;
259
+ if (this.namesOf !== this.raw) {
260
+ MutableHashSet.clear(names);
261
+ this.raw.forEach((a) => MutableHashSet.add(names, a.name));
262
+ this.namesOf = this.raw;
263
+ }
264
+ if (MutableHashSet.has(names, attribute)) return true;
265
+ MutableHashSet.add(names, attribute);
266
+ return false;
267
+ }
268
+
269
+ top(): Frame {
270
+ return Arr.lastNonEmpty(this.stack);
271
+ }
272
+ }
273
+
274
+ let x = new Context('', [0]);
275
+
276
+ const fail: (message: string, offset: number) => never = (message, offset) => {
277
+ throw new Failure(message, offset);
278
+ };
279
+
280
+ // -----------------------------------------------------------------------------
281
+ // Helpers
282
+ // -----------------------------------------------------------------------------
283
+
284
+ const lit = Token.literal;
285
+
286
+ /** Runs `f` at the current offset, consuming nothing. */
287
+ const act = (f: (pos: number) => void): P<number> => Parser.tap(Parser.location, f);
288
+
289
+ /** Throws `message` at the current offset. */
290
+ const failHere = <A = never>(message: string): P<A> =>
291
+ Parser.map(Parser.location, (pos): A => fail(message, pos));
292
+
293
+ const at = (s: string): P<unknown> => Parser.peek(lit(s));
294
+
295
+ const ws: P<string> = Token.takeWhile(space);
296
+ const requireWs: P<unknown> = Parser.alt(
297
+ Token.takeWhile(space, { min: 1 }),
298
+ failHere('Expected white space'),
299
+ );
300
+
301
+ /** Fails unless white space was just read (`ws` may have read none). */
302
+ const afterWs: P<void> = Parser.make<void>((state) => {
303
+ const c = state.input.charCodeAt(state.pos - 1);
304
+ if (c !== 0x20 && c !== 0x09 && c !== 0x0a && c !== 0x0d) fail('Expected white space', state.pos);
305
+ return undefined;
306
+ });
307
+
308
+ const expect = (s: string): P<unknown> => Parser.alt(lit(s), failHere(`Expected "${s}"`));
309
+
310
+ const xmlName: P<string> = Parser.alt(
311
+ Parser.taken(Parser.seq(Token.oneOf(nameStart), Token.takeWhile(nameChar))),
312
+ failHere('Expected a name'),
313
+ );
314
+
315
+ const eq: P<unknown> = Parser.seq(ws, expect('='), ws);
316
+
317
+ /** A quoted string, without its quotes. */
318
+ const quoted: P<string> = Parser.alt(
319
+ Parser.preceded(
320
+ Parser.peek(Token.oneOf('"\'')),
321
+ Parser.alt(
322
+ Parser.delimited(lit('"'), Token.takeTill('"'), lit('"')),
323
+ Parser.delimited(lit("'"), Token.takeTill("'"), lit("'")),
324
+ failHere('Unterminated quoted string'),
325
+ ),
326
+ ),
327
+ failHere('Expected a quoted string'),
328
+ );
329
+
330
+ /** `p`, then `check` with its value and the offset after it. */
331
+ const checked = <A>(p: P<A>, check: (a: A, pos: number) => void): P<A> =>
332
+ Parser.seq(p, Parser.location).pipe(
333
+ Parser.tap(([a, pos]) => check(a, pos)),
334
+ Parser.map(([a]) => a),
335
+ );
336
+
337
+ const collapse = (value: string): string => value.replace(/ +/g, ' ').replace(/^ | $/g, '');
338
+
339
+ const CHAR_REF_RE = /^#(x[0-9a-fA-F]+|[0-9]+)$/;
340
+
341
+ // -----------------------------------------------------------------------------
342
+ // References
343
+ // -----------------------------------------------------------------------------
344
+
345
+ const charRef = (body: string, offset: number): string => {
346
+ const code = body.startsWith('#x') ? parseInt(body.slice(2), 16) : parseInt(body.slice(1), 10);
347
+ if (!(code <= 0x10ffff)) fail('Invalid character reference', offset);
348
+ const ch = String.fromCodePoint(code);
349
+ if (!isValidText(ch)) fail('Character reference to an invalid character', offset);
350
+ return ch;
351
+ };
352
+
353
+ /** Expands the character references in an entity value, leaving entity references. */
354
+ const expandCharRefs = (raw: string, offset: number): string =>
355
+ // `body` is unset only when the bare `&` (the only one-character match) was matched
356
+ raw.replace(/&(#x[0-9a-fA-F]+|#[0-9]+|[^;]*);|&/g, (m: string, body: string, i: number) => {
357
+ if (m.length === 1) fail('Invalid reference', offset + i);
358
+ if (body.startsWith('#')) return charRef(body, offset + i);
359
+ if (!isName(body)) fail('Invalid entity reference', offset + i);
360
+ return m;
361
+ });
362
+
363
+ /** The replacement text of a reference to `entity`, counted against the expansion limit. */
364
+ const entityText = (entity: string, offset: number, stack: HashSet.HashSet<string>): string => {
365
+ if (!isName(entity)) fail('Invalid entity reference', offset);
366
+ const builtIn = predefined(entity);
367
+ if (builtIn !== '') return builtIn === '<' ? '&#60;' : builtIn === '&' ? '&#38;' : builtIn;
368
+ if (MutableHashSet.has(x.externalEntities, entity)) {
369
+ fail(`External entity "${entity}" is not supported`, offset);
370
+ }
371
+ const value = Option.getOrElse(MutableHashMap.get(x.entities, entity), () =>
372
+ fail(`Undefined entity "${entity}"`, offset),
373
+ );
374
+ if (HashSet.has(stack, entity)) fail(`Recursive entity "${entity}"`, offset);
375
+ if (HashSet.size(stack) >= MAX_ENTITY_DEPTH) {
376
+ fail('Entity references are nested too deeply', offset);
377
+ }
378
+ x.expanded += value.length;
379
+ if (x.expanded > MAX_ENTITY_EXPANSION) fail('Entity expansion limit exceeded', offset);
380
+ return value;
381
+ };
382
+
383
+ /**
384
+ * What attribute-value normalisation replaces: a reference (to the first `;`
385
+ * after its `&`), an `&` with no `;` after it, `<`, and white space other
386
+ * than a space. The matches are found before any is replaced, so the nested
387
+ * normalisation of an entity's replacement text may reuse it.
388
+ */
389
+ const ATTRIBUTE_SPECIAL_RE = /&([^;]*);|[&<\t\n\r]/g;
390
+ const ATTRIBUTE_SPECIAL_TEST_RE = /[&<\t\n\r]/;
391
+
392
+ /** Normalises an attribute value (XML 1.0 §3.3.3). */
393
+ const normalizeAttribute = (raw: string, offset: number, stack: HashSet.HashSet<string>): string =>
394
+ !ATTRIBUTE_SPECIAL_TEST_RE.test(raw)
395
+ ? raw
396
+ : // `body` is set for every match longer than one character (a reference)
397
+ raw.replace(ATTRIBUTE_SPECIAL_RE, (m: string, body: string, i: number): string => {
398
+ if (m === '<') return fail('"<" is not allowed in attribute values', offset + i);
399
+ if (m === '&') return fail('Unterminated reference', offset + i);
400
+ if (m.length === 1) return ' ';
401
+ if (body.startsWith('#')) {
402
+ if (!CHAR_REF_RE.test(body)) fail('Invalid character reference', offset + i);
403
+ return charRef(body, offset + i);
404
+ }
405
+ const replacement = entityText(body, offset + i, stack);
406
+ return normalizeAttribute(replacement, offset + i, HashSet.add(stack, body));
407
+ });
408
+
409
+ /** An attribute value literal, normalised. */
410
+ const attributeValue: P<string> = Parser.alt(
411
+ Parser.preceded(
412
+ Parser.peek(Token.oneOf('"\'')),
413
+ Parser.alt(
414
+ Parser.seq(Parser.location, Parser.delimited(lit('"'), Token.takeTill('"'), lit('"'))),
415
+ Parser.seq(Parser.location, Parser.delimited(lit("'"), Token.takeTill("'"), lit("'"))),
416
+ failHere<readonly [number, string]>('Unterminated attribute value'),
417
+ ),
418
+ ),
419
+ failHere<readonly [number, string]>('Expected a quoted attribute value'),
420
+ ).pipe(Parser.map(([quote, raw]) => normalizeAttribute(raw, quote + 1, HashSet.empty())));
421
+
422
+ // -----------------------------------------------------------------------------
423
+ // Comments and processing instructions
424
+ // -----------------------------------------------------------------------------
425
+
426
+ const comment: P<Xml.Comment> = Parser.terminated(
427
+ Parser.seq(
428
+ Parser.location,
429
+ Parser.preceded(lit('<!--'), Parser.opt(Token.takeUntil('--'))),
430
+ Parser.location,
431
+ ).pipe(
432
+ Parser.map(([start, body, end]): Xml.Comment => {
433
+ const value = Option.getOrElse(body, () => fail('Unterminated comment', start));
434
+ if (x.src.charCodeAt(end + 2) !== 0x3e) fail('"--" is not allowed in comments', end);
435
+ return { _tag: 'Comment', value, position: x.position(start) };
436
+ }),
437
+ ),
438
+ lit('-->'),
439
+ );
440
+
441
+ const pi: P<Xml.ProcessingInstruction> = Parser.terminated(
442
+ Parser.seq(
443
+ Parser.location,
444
+ Parser.preceded(
445
+ lit('<?'),
446
+ checked(xmlName, (target, pos) => {
447
+ if (target.toLowerCase() === 'xml')
448
+ fail('Reserved processing instruction target', pos - target.length - 2);
449
+ if (target.includes(':')) fail('Processing instruction targets cannot contain ":"', pos);
450
+ }),
451
+ ),
452
+ Parser.alt(
453
+ Parser.preceded(at('?>'), Parser.succeed(Option.some(''))),
454
+ Parser.preceded(requireWs, Parser.opt(Token.takeUntil('?>'))),
455
+ ),
456
+ ).pipe(
457
+ Parser.map(([start, target, data]): Xml.ProcessingInstruction => ({
458
+ _tag: 'ProcessingInstruction',
459
+ target,
460
+ data: Option.getOrElse(data, () => fail('Unterminated processing instruction', start)),
461
+ position: x.position(start),
462
+ })),
463
+ ),
464
+ lit('?>'),
465
+ );
466
+
467
+ // -----------------------------------------------------------------------------
468
+ // The document type declaration
469
+ // -----------------------------------------------------------------------------
470
+
471
+ /** `ExternalID`: `[publicId, systemId]`. */
472
+ const externalId: P<readonly [Option.Option<string>, Option.Option<string>]> = Parser.alt(
473
+ Parser.preceded(Parser.seq(lit('SYSTEM'), requireWs), quoted).pipe(
474
+ Parser.map((system) => [Option.none(), Option.some(system)] as const),
475
+ ),
476
+ Parser.preceded(
477
+ Parser.seq(expect('PUBLIC'), requireWs),
478
+ Parser.seq(
479
+ checked(quoted, (pub, pos) => {
480
+ if (!PUBID_RE.test(pub)) fail('Invalid public identifier', pos);
481
+ }),
482
+ Parser.preceded(Parser.seq(ws, afterWs), quoted),
483
+ ).pipe(Parser.map(([pub, system]) => [Option.some(pub), Option.some(system)] as const)),
484
+ ),
485
+ );
486
+
487
+ const skipParens: P<unknown> = Parser.preceded(
488
+ expect('('),
489
+ Parser.seq(Parser.location, Token.takeTill(')'), Parser.opt(lit(')'))).pipe(
490
+ Parser.tap(([pos, tokens, close]) => {
491
+ if (Option.isNone(close)) fail('Unterminated enumeration', pos);
492
+ if (tokens.split('|').some((t) => !NMTOKEN_RE.test(t.trim()))) {
493
+ fail('Invalid enumeration', pos);
494
+ }
495
+ }),
496
+ ),
497
+ );
498
+
499
+ const TOKENIZED_TYPES: HashSet.HashSet<string> = HashSet.make(
500
+ 'ID',
501
+ 'IDREF',
502
+ 'IDREFS',
503
+ 'ENTITY',
504
+ 'ENTITIES',
505
+ 'NMTOKEN',
506
+ 'NMTOKENS',
507
+ );
508
+
509
+ const defaultDecl: P<Option.Option<string>> = Parser.alt(
510
+ Parser.preceded(lit('#REQUIRED'), Parser.succeed(Option.none<string>())),
511
+ Parser.preceded(lit('#IMPLIED'), Parser.succeed(Option.none<string>())),
512
+ Parser.preceded(
513
+ Parser.opt(Parser.seq(lit('#FIXED'), requireWs)),
514
+ Parser.map(attributeValue, Option.some),
515
+ ),
516
+ );
517
+
518
+ const notation: P<void> = Parser.make<void>((state) =>
519
+ x.attributeType === 'NOTATION' ? undefined : state.backtrack('Verify', ['NOTATION']),
520
+ );
521
+
522
+ const attributeDef: P<unknown> = Parser.seq(
523
+ Parser.tap(xmlName, (n) => {
524
+ x.attributeName = n;
525
+ x.tokenized = true;
526
+ }),
527
+ requireWs,
528
+ Parser.alt(
529
+ Parser.preceded(at('('), skipParens),
530
+ Parser.seq(
531
+ checked(xmlName, (type, pos) => {
532
+ x.attributeType = type;
533
+ if (type === 'CDATA') x.tokenized = false;
534
+ else if (type !== 'NOTATION' && !HashSet.has(TOKENIZED_TYPES, type)) {
535
+ fail(`Unknown attribute type "${type}"`, pos);
536
+ }
537
+ }),
538
+ Parser.opt(Parser.preceded(notation, Parser.seq(requireWs, skipParens))),
539
+ ),
540
+ ),
541
+ requireWs,
542
+ defaultDecl,
543
+ ).pipe(
544
+ Parser.tap(([, , , , defaultValue]) => {
545
+ const { types, defaults } = x.attributeList;
546
+ const attribute = x.attributeName;
547
+ if (MutableHashMap.has(types, attribute)) return; // first wins
548
+ const tokenized = x.tokenized;
549
+ MutableHashMap.set(types, attribute, tokenized);
550
+ if (Option.isSome(defaultValue)) {
551
+ const value = defaultValue.value;
552
+ defaults.push({ name: attribute, value: tokenized ? collapse(value) : value, tokenized });
553
+ }
554
+ }),
555
+ );
556
+
557
+ const attlistDecl: P<unknown> = Parser.preceded(
558
+ Parser.seq(lit('<!ATTLIST'), requireWs),
559
+ Parser.seq(
560
+ Parser.tap(xmlName, (element) => {
561
+ const known = MutableHashMap.get(x.attributeLists, element);
562
+ if (Option.isSome(known)) x.attributeList = known.value;
563
+ else {
564
+ const list: AttributeList = { types: MutableHashMap.empty(), defaults: [] };
565
+ MutableHashMap.set(x.attributeLists, element, list);
566
+ x.attributeList = list;
567
+ }
568
+ }),
569
+ Parser.repeat(Parser.preceded(Parser.seq(ws, Parser.not(lit('>')), afterWs), attributeDef)),
570
+ ws,
571
+ lit('>'),
572
+ ),
573
+ );
574
+
575
+ const entityDecl: P<unknown> = Parser.preceded(
576
+ Parser.seq(lit('<!ENTITY'), requireWs),
577
+ Parser.seq(
578
+ Parser.alt(
579
+ Parser.preceded(Parser.seq(lit('%'), requireWs), Parser.succeed(true)),
580
+ Parser.succeed(false),
581
+ ),
582
+ checked(xmlName, (n, pos) => {
583
+ if (n.includes(':')) fail('Entity names cannot contain ":"', pos);
584
+ }),
585
+ requireWs,
586
+ Parser.alt(
587
+ Parser.preceded(
588
+ Parser.peek(Token.oneOf('"\'')),
589
+ Parser.seq(Parser.location, quoted).pipe(
590
+ Parser.map(([quote, raw]) => {
591
+ if (raw.includes('%')) fail('Parameter entity references are not supported', quote + 1);
592
+ return Option.some(expandCharRefs(raw, quote + 1));
593
+ }),
594
+ ),
595
+ ),
596
+ Parser.preceded(
597
+ externalId,
598
+ Parser.opt(
599
+ Parser.preceded(
600
+ Parser.seq(Token.takeWhile(space, { min: 1 }), lit('NDATA')),
601
+ Parser.seq(requireWs, xmlName),
602
+ ),
603
+ ),
604
+ ).pipe(Parser.as(Option.none<string>())),
605
+ ),
606
+ ws,
607
+ expect('>'),
608
+ ),
609
+ ).pipe(
610
+ Parser.tap(([parameter, entity, , value]) => {
611
+ if (parameter) return;
612
+ if (MutableHashMap.has(x.entities, entity) || MutableHashSet.has(x.externalEntities, entity)) {
613
+ return; // first wins
614
+ }
615
+ if (Option.isSome(value)) MutableHashMap.set(x.entities, entity, value.value);
616
+ else MutableHashSet.add(x.externalEntities, entity);
617
+ }),
618
+ );
619
+
620
+ /** `<!ELEMENT …>` and `<!NOTATION …>`, skipped. */
621
+ const skippedDecl: P<unknown> = Parser.seq(
622
+ Parser.repeat(
623
+ Parser.alt(
624
+ Parser.preceded(Parser.peek(Token.oneOf('"\'')), quoted),
625
+ Token.takeTill('>"\'', { min: 1 }),
626
+ ),
627
+ ),
628
+ Parser.alt(lit('>'), failHere('Unterminated markup declaration')),
629
+ );
630
+
631
+ const internalSubset: P<unknown> = Parser.terminated(
632
+ Parser.repeat(
633
+ Parser.preceded(
634
+ Parser.seq(ws, Parser.not(lit(']'))),
635
+ Parser.alt(
636
+ Parser.preceded(Parser.eof, failHere('Unterminated internal subset')),
637
+ Parser.preceded(at('<!ENTITY'), entityDecl),
638
+ Parser.preceded(at('<!ATTLIST'), attlistDecl),
639
+ Parser.preceded(Parser.alt(at('<!ELEMENT'), at('<!NOTATION')), skippedDecl),
640
+ Parser.preceded(at('<!--'), comment),
641
+ Parser.preceded(at('<?'), pi),
642
+ Parser.preceded(at('%'), failHere('Parameter entity references are not supported')),
643
+ failHere('Invalid markup in the internal subset'),
644
+ ),
645
+ ),
646
+ ),
647
+ Parser.seq(ws, lit(']')),
648
+ );
649
+
650
+ const doctype: P<unknown> = Parser.seq(
651
+ Parser.preceded(Parser.seq(lit('<!DOCTYPE'), requireWs), xmlName),
652
+ Parser.alt(
653
+ Parser.preceded(
654
+ Parser.seq(ws, Parser.peek(Parser.alt(lit('SYSTEM'), lit('PUBLIC'))), afterWs),
655
+ Parser.terminated(externalId, ws),
656
+ ).pipe(
657
+ Parser.tap(() => {
658
+ x.hasExternalSubset = true;
659
+ }),
660
+ ),
661
+ Parser.preceded(ws, Parser.succeed([Option.none<string>(), Option.none<string>()] as const)),
662
+ ),
663
+ Parser.opt(Parser.preceded(lit('['), Parser.terminated(internalSubset, ws))),
664
+ expect('>'),
665
+ ).pipe(
666
+ Parser.tap(([doctypeName, [publicId, systemId]]) => {
667
+ x.doctype = Option.some({
668
+ name: doctypeName,
669
+ publicId: Option.getOrUndefined(publicId),
670
+ systemId: Option.getOrUndefined(systemId),
671
+ // `DocumentType.entities` is a public `ReadonlyMap`
672
+ entities: new Map(x.entities),
673
+ });
674
+ }),
675
+ );
676
+
677
+ // -----------------------------------------------------------------------------
678
+ // Elements
679
+ // -----------------------------------------------------------------------------
680
+
681
+ const pushText = (frame: Frame, s: string, offset: number): void => {
682
+ if (s === '') return;
683
+ if (frame.textStart === -1) frame.textStart = offset;
684
+ frame.text += s;
685
+ };
686
+
687
+ const isText = Predicate.isTagged('Text');
688
+
689
+ const flush = (frame: Frame): void => {
690
+ if (frame.text !== '') {
691
+ const children = frame.children;
692
+ const prev = frame.endsWithText && children.length > frame.floor ? children.at(-1) : undefined;
693
+ if (isText(prev)) {
694
+ children[children.length - 1] = { ...prev, value: prev.value + frame.text };
695
+ } else {
696
+ children.push({ _tag: 'Text', value: frame.text, position: x.position(frame.textStart) });
697
+ frame.endsWithText = true;
698
+ }
699
+ }
700
+ frame.text = '';
701
+ frame.textStart = -1;
702
+ };
703
+
704
+ /** Adds a child that is not text to `frame`, after its text. */
705
+ const pushChild = (frame: Frame, node: Xml.Node): void => {
706
+ flush(frame);
707
+ frame.children.push(node);
708
+ frame.endsWithText = false;
709
+ };
710
+
711
+ /** A child that is not text. */
712
+ const pushNode = (node: Xml.Node): void => {
713
+ pushChild(x.top(), node);
714
+ };
715
+
716
+ /**
717
+ * The prefix (`''` if none) and local part of a valid qualified name. The
718
+ * names of a document repeat, so each is checked and split once, and its
719
+ * parts are the same strings each time.
720
+ */
721
+ const splitName = (qname: string, offset: number): readonly [prefix: string, local: string] => {
722
+ const i = qname.indexOf(':');
723
+ if (i === -1) {
724
+ if (!isNCName(qname)) fail(`Invalid name "${qname}"`, offset);
725
+ return ['', qname];
726
+ }
727
+ const prefix = qname.slice(0, i);
728
+ const local = qname.slice(i + 1);
729
+ if (!isNCName(prefix) || !isNCName(local)) fail(`Invalid qualified name "${qname}"`, offset);
730
+ if (prefix === 'xmlns') fail('Elements and attributes cannot use the "xmlns" prefix', offset);
731
+ return [prefix, local];
732
+ };
733
+
734
+ const nameParts = (qname: string, offset: number): readonly [prefix: string, local: string] => {
735
+ const known = MutableHashMap.get(x.qnames, qname);
736
+ if (Option.isSome(known)) return known.value;
737
+ const parts = splitName(qname, offset);
738
+ MutableHashMap.set(x.qnames, qname, parts);
739
+ return parts;
740
+ };
741
+
742
+ const XML_NAMESPACE_OPTION = Option.some(XML_NAMESPACE);
743
+
744
+ /** The namespace of a name with `prefix` (an element's default namespace if `''`). */
745
+ const namespaceOf = (
746
+ prefix: string,
747
+ ns: ReadonlyMap<string, string>,
748
+ isElement: boolean,
749
+ offset: number,
750
+ ): Option.Option<string> => {
751
+ if (prefix === '') return isElement ? Option.fromUndefinedOr(ns.get('')) : Option.none();
752
+ if (prefix === 'xml') return XML_NAMESPACE_OPTION;
753
+ const uri = ns.get(prefix);
754
+ if (uri === undefined) fail(`Unbound namespace prefix "${prefix}"`, offset);
755
+ return Option.some(uri);
756
+ };
757
+
758
+ /** The namespace prefix an `xmlns` / `xmlns:…` attribute declares, or none for any other attribute. */
759
+ const declaredPrefix = (attribute: string): Option.Option<string> =>
760
+ attribute === 'xmlns'
761
+ ? Option.some('')
762
+ : attribute.startsWith('xmlns:')
763
+ ? Option.some(attribute.slice(6))
764
+ : Option.none();
765
+
766
+ const isDeclaration = (attribute: string): boolean =>
767
+ attribute === 'xmlns' || attribute.startsWith('xmlns:');
768
+
769
+ /** The namespaces in scope of an element that makes `declarations` (which are not empty). */
770
+ const declare = (
771
+ parentNs: ReadonlyMap<string, string>,
772
+ declarations: ReadonlyArray<Xml.NamespaceDeclaration>,
773
+ ): ReadonlyMap<string, string> => {
774
+ // `inScopeNamespaces` is a public `ReadonlyMap`
775
+ const own = new Map(parentNs);
776
+ declarations.forEach((d) => {
777
+ if (d.namespace === '') own.delete('');
778
+ else own.set(d.prefix, d.namespace);
779
+ });
780
+ return own;
781
+ };
782
+
783
+ /** Checks a namespace declaration, which declares `prefix` to be `uri`. */
784
+ const checkDeclaration = (prefix: string, uri: string, offset: number): void => {
785
+ if (prefix !== '' && !isNCName(prefix)) fail('Invalid namespace prefix', offset);
786
+ if (prefix === 'xmlns') fail('The "xmlns" prefix cannot be declared', offset);
787
+ if (prefix === 'xml' && uri !== XML_NAMESPACE) fail('The "xml" prefix cannot be rebound', offset);
788
+ if (prefix !== 'xml' && uri === XML_NAMESPACE) {
789
+ fail('The XML namespace cannot be bound to another prefix', offset);
790
+ }
791
+ if (uri === XMLNS_NAMESPACE) fail('The xmlns namespace cannot be declared', offset);
792
+ if (prefix !== '' && uri === '') fail('Prefixed namespace declarations cannot be empty', offset);
793
+ };
794
+
795
+ /** Opens the element whose start tag was just read (closing it too if it was empty). */
796
+ const openElement = (empty: boolean): void => {
797
+ const start = x.tagStart;
798
+ const qname = x.qname;
799
+ const raw = x.raw;
800
+ // attribute types and defaults from the internal subset
801
+ if (!MutableHashMap.isEmpty(x.attributeLists)) {
802
+ const list = MutableHashMap.get(x.attributeLists, qname);
803
+ if (Option.isSome(list)) {
804
+ const { types, defaults } = list.value;
805
+ raw.forEach((a) => {
806
+ if (Option.getOrElse(MutableHashMap.get(types, a.name), constFalse)) {
807
+ a.value = collapse(a.value);
808
+ }
809
+ });
810
+ defaults.forEach((d) => {
811
+ if (!x.hasAttribute(d.name)) {
812
+ raw.push({ name: d.name, value: d.value, offset: start, defaulted: true });
813
+ }
814
+ });
815
+ }
816
+ }
817
+
818
+ // namespace declarations
819
+ const parent = x.top();
820
+ const parentNs = parent.inScope;
821
+ const declarations: Array<Xml.NamespaceDeclaration> = [];
822
+ raw.forEach((a) => {
823
+ const declared = declaredPrefix(a.name);
824
+ if (Option.isNone(declared)) return;
825
+ const prefix = declared.value;
826
+ checkDeclaration(prefix, a.value, a.offset);
827
+ if (prefix !== 'xml') declarations.push({ prefix, namespace: a.value });
828
+ });
829
+ const inScope = Arr.isArrayNonEmpty(declarations) ? declare(parentNs, declarations) : parentNs;
830
+
831
+ const [prefix, localName] = nameParts(qname, start + 1);
832
+ const namespace = namespaceOf(prefix, inScope, true, start + 1);
833
+ const attributes: Array<Xml.Attribute> = [];
834
+ const large = raw.length >= SMALL;
835
+ const expanded = large ? MutableHashSet.empty<string>() : UNUSED;
836
+ raw.forEach((a) => {
837
+ if (isDeclaration(a.name)) return;
838
+ const [ap, al] = nameParts(a.name, a.offset);
839
+ const ans = Option.getOrUndefined(namespaceOf(ap, inScope, false, a.offset));
840
+ const key = `${ans ?? ''} ${al}`;
841
+ const duplicate = large
842
+ ? MutableHashSet.has(expanded, key)
843
+ : attributes.some((b) => b.localName === al && b.namespace === ans);
844
+ if (duplicate) fail(`Duplicate attribute "{${ans ?? ''}}${al}"`, a.offset);
845
+ if (large) MutableHashSet.add(expanded, key);
846
+ attributes.push({
847
+ _tag: 'Attribute',
848
+ name: a.name,
849
+ prefix: ap,
850
+ localName: al,
851
+ namespace: ans,
852
+ value: a.value,
853
+ defaulted: a.defaulted,
854
+ position: x.position(a.offset),
855
+ });
856
+ });
857
+
858
+ flush(parent);
859
+ const frame: Frame = {
860
+ qname,
861
+ position: x.position(start),
862
+ prefix,
863
+ localName,
864
+ namespace,
865
+ attributes,
866
+ declarations,
867
+ inScope,
868
+ children: [],
869
+ text: '',
870
+ textStart: -1,
871
+ endsWithText: false,
872
+ floor: 0,
873
+ };
874
+ if (empty) {
875
+ closeElement(frame);
876
+ return;
877
+ }
878
+ if (x.stack.length - x.base >= MAX_ELEMENT_DEPTH) fail('Elements are nested too deeply', start);
879
+ x.stack.push(frame);
880
+ };
881
+
882
+ /** The element an open frame stands for (with the children it has so far). */
883
+ const elementOf = (frame: Frame): Xml.Element => ({
884
+ _tag: 'Element',
885
+ name: frame.qname,
886
+ prefix: frame.prefix,
887
+ localName: frame.localName,
888
+ namespace: Option.getOrUndefined(frame.namespace),
889
+ attributes: frame.attributes,
890
+ namespaceDeclarations: frame.declarations,
891
+ inScopeNamespaces: frame.inScope,
892
+ children: frame.children,
893
+ position: frame.position,
894
+ });
895
+
896
+ /** Adds a finished element to its parent. */
897
+ const closeElement = (frame: Frame): void => {
898
+ flush(frame);
899
+ const element = elementOf(frame);
900
+ const inDocument = HashSet.isEmpty(x.entityStack);
901
+ // The document element (not one in an entity's replacement text) is the root
902
+ if (x.stack.length === 1 && inDocument) {
903
+ x.root = Option.some(element);
904
+ return;
905
+ }
906
+ // A child of the root (not inside an entity's replacement text) may be taken as it closes
907
+ if (x.stack.length === 2 && inDocument && x.onRootChild(element, elementOf(x.top()))) {
908
+ const root = x.top();
909
+ root.floor = root.children.length;
910
+ return;
911
+ }
912
+ pushChild(x.top(), element);
913
+ };
914
+
915
+ const attribute: P<unknown> = Parser.seq(Parser.location, xmlName, eq, attributeValue).pipe(
916
+ Parser.tap(([offset, attributeName, , value]) => {
917
+ if (x.hasAttribute(attributeName)) fail(`Duplicate attribute "${attributeName}"`, offset);
918
+ x.raw.push({ name: attributeName, value, offset, defaulted: false });
919
+ }),
920
+ );
921
+
922
+ const startTag: P<unknown> = Parser.seq(
923
+ Parser.tap(Parser.seq(Parser.location, Parser.preceded(lit('<'), xmlName)), ([start, qname]) => {
924
+ x.tagStart = start;
925
+ x.qname = qname;
926
+ x.raw = [];
927
+ }),
928
+ Parser.repeat(
929
+ Parser.preceded(
930
+ Parser.seq(ws, Parser.not(Parser.alt(lit('>'), lit('/>')))),
931
+ Parser.preceded(
932
+ Parser.make<void>((state) => {
933
+ const c = state.input.charCodeAt(state.pos - 1);
934
+ if (c !== 0x20 && c !== 0x09 && c !== 0x0a && c !== 0x0d) {
935
+ fail('Expected white space between attributes', state.pos);
936
+ }
937
+ return undefined;
938
+ }),
939
+ attribute,
940
+ ),
941
+ ),
942
+ ),
943
+ Parser.preceded(
944
+ ws,
945
+ Parser.alt(
946
+ Parser.tap(lit('/>'), () => openElement(true)),
947
+ Parser.tap(lit('>'), () => openElement(false)),
948
+ ),
949
+ ),
950
+ );
951
+
952
+ const endTag: P<unknown> = Parser.seq(
953
+ Parser.seq(
954
+ act((offset) => {
955
+ if (x.stack.length === x.base) fail('Unbalanced end tag in entity replacement text', offset);
956
+ }),
957
+ Parser.preceded(lit('</'), xmlName),
958
+ ).pipe(
959
+ Parser.tap(([offset, endName]) => {
960
+ const frame = x.top();
961
+ if (endName !== frame.qname) {
962
+ fail(`Mismatched end tag: expected </${frame.qname}> but found </${endName}>`, offset);
963
+ }
964
+ }),
965
+ ),
966
+ ws,
967
+ expect('>'),
968
+ ).pipe(
969
+ Parser.tap(() => {
970
+ const frame = x.top();
971
+ x.stack.pop();
972
+ closeElement(frame);
973
+ }),
974
+ );
975
+
976
+ const cdata: P<unknown> = Parser.seq(
977
+ Parser.location,
978
+ Parser.preceded(
979
+ lit('<![CDATA['),
980
+ Parser.opt(Parser.terminated(Token.takeUntil(']]>'), lit(']]>'))),
981
+ ),
982
+ ).pipe(
983
+ Parser.tap(([start, text]) => {
984
+ pushText(
985
+ x.top(),
986
+ Option.getOrElse(text, () => fail('Unterminated CDATA section', start)),
987
+ start,
988
+ );
989
+ }),
990
+ );
991
+
992
+ const charData: P<unknown> = Parser.seq(Parser.location, Token.takeTill('<&', { min: 1 })).pipe(
993
+ Parser.tap(([start, text]) => {
994
+ const bad = text.indexOf(']]>');
995
+ if (bad !== -1) fail('"]]>" is not allowed in character data', start + bad);
996
+ pushText(x.top(), text, start);
997
+ }),
998
+ );
999
+
1000
+ /** The content an entity's replacement text adds (parsed interpreted: it may nest). */
1001
+ const entityContent: P<unknown> = Parser.suspend(() =>
1002
+ Parser.terminated(
1003
+ Parser.repeat(Parser.preceded(Parser.not(Parser.eof), contentItem)),
1004
+ act((pos) => {
1005
+ if (x.stack.length > x.base) fail('Unexpected end of input: unclosed element', pos);
1006
+ }),
1007
+ ),
1008
+ );
1009
+
1010
+ /** Parses the replacement text of an entity that contains markup. */
1011
+ const replacementNodes = (body: string, replacement: string, start: number): Array<Xml.Node> => {
1012
+ const { src, lineStarts, stack, base, entityStack } = x;
1013
+ const frame = baseFrame(x.top().inScope);
1014
+ x.src = replacement;
1015
+ x.lineStarts = [0];
1016
+ x.stack = [frame];
1017
+ x.base = 1;
1018
+ x.entityStack = HashSet.add(entityStack, body);
1019
+ const outcome = Result.try({
1020
+ try: () => {
1021
+ const result = Parser.parse(entityContent, replacement);
1022
+ if (Result.isFailure(result)) fail('Invalid markup', result.failure.offset);
1023
+ flush(frame);
1024
+ return frame.children;
1025
+ },
1026
+ catch: (e) => e,
1027
+ });
1028
+ x.src = src;
1029
+ x.lineStarts = lineStarts;
1030
+ x.stack = stack;
1031
+ x.base = base;
1032
+ x.entityStack = entityStack;
1033
+ if (Result.isSuccess(outcome)) return outcome.success;
1034
+ if (outcome.failure instanceof Failure) {
1035
+ fail(`In entity "${body}": ${outcome.failure.message}`, start);
1036
+ }
1037
+ throw outcome.failure;
1038
+ };
1039
+
1040
+ const reference: P<unknown> = Parser.seq(
1041
+ Parser.location,
1042
+ Parser.preceded(lit('&'), Token.takeTill(';')),
1043
+ Parser.opt(lit(';')),
1044
+ ).pipe(
1045
+ Parser.tap(([start, body, semi]) => {
1046
+ if (Option.isNone(semi)) fail('Unterminated reference', start);
1047
+ const frame = x.top();
1048
+ if (body.startsWith('#')) {
1049
+ if (!CHAR_REF_RE.test(body)) fail('Invalid character reference', start);
1050
+ pushText(frame, charRef(body, start), start);
1051
+ return;
1052
+ }
1053
+ const builtIn = predefined(body);
1054
+ if (builtIn !== '') {
1055
+ pushText(frame, builtIn, start);
1056
+ return;
1057
+ }
1058
+ const replacement = entityText(body, start, x.entityStack);
1059
+ if (!replacement.includes('<') && !replacement.includes('&')) {
1060
+ pushText(frame, replacement, start);
1061
+ return;
1062
+ }
1063
+ flush(frame);
1064
+ const position = x.position(start);
1065
+ replacementNodes(body, replacement, start).forEach((n) => {
1066
+ if (isText(n)) pushText(frame, n.value, start);
1067
+ else pushChild(frame, { ...n, position });
1068
+ });
1069
+ }),
1070
+ );
1071
+
1072
+ const contentItem: P<unknown> = Parser.alt(
1073
+ Parser.preceded(at('</'), endTag),
1074
+ Parser.preceded(at('<!--'), Parser.tap(comment, pushNode)),
1075
+ Parser.preceded(at('<![CDATA['), cdata),
1076
+ Parser.preceded(at('<?'), Parser.tap(pi, pushNode)),
1077
+ Parser.preceded(at('<!'), failHere('Unexpected markup declaration in content')),
1078
+ Parser.preceded(at('<'), startTag),
1079
+ Parser.preceded(at('&'), reference),
1080
+ charData,
1081
+ );
1082
+
1083
+ /** The root element: its start tag, then content until it is closed. */
1084
+ const rootElement: P<unknown> = Parser.asVoid(
1085
+ Parser.seq(
1086
+ startTag,
1087
+ Parser.repeat(
1088
+ Parser.preceded(
1089
+ Parser.make<void>((state) =>
1090
+ x.stack.length > x.base ? undefined : state.backtrack('Verify', ['content']),
1091
+ ),
1092
+ Parser.alt(
1093
+ Parser.preceded(Parser.eof, failHere('Unexpected end of input: unclosed element')),
1094
+ contentItem,
1095
+ ),
1096
+ ),
1097
+ ),
1098
+ ),
1099
+ );
1100
+
1101
+ // -----------------------------------------------------------------------------
1102
+ // The document
1103
+ // -----------------------------------------------------------------------------
1104
+
1105
+ const xmlDecl: P<unknown> = Parser.preceded(
1106
+ Parser.seq(lit('<?xml'), Parser.peek(Token.oneOf(space))),
1107
+ Parser.seq(
1108
+ requireWs,
1109
+ expect('version'),
1110
+ eq,
1111
+ checked(quoted, (version, pos) => {
1112
+ if (!/^1\.[0-9]+$/.test(version)) fail(`Unsupported XML version "${version}"`, pos);
1113
+ x.version = Option.some(version);
1114
+ }),
1115
+ ws,
1116
+ Parser.opt(
1117
+ Parser.preceded(
1118
+ Parser.seq(at('encoding'), afterWs, lit('encoding'), eq),
1119
+ Parser.terminated(
1120
+ checked(quoted, (encoding, pos) => {
1121
+ if (!/^[A-Za-z][A-Za-z0-9._-]*$/.test(encoding)) fail('Invalid encoding name', pos);
1122
+ x.encoding = Option.some(encoding);
1123
+ }),
1124
+ ws,
1125
+ ),
1126
+ ),
1127
+ ),
1128
+ Parser.opt(
1129
+ Parser.preceded(
1130
+ Parser.seq(at('standalone'), afterWs, lit('standalone'), eq),
1131
+ Parser.terminated(
1132
+ checked(quoted, (sd, pos) => {
1133
+ if (sd !== 'yes' && sd !== 'no') fail('standalone must be "yes" or "no"', pos);
1134
+ x.standalone = Option.some(sd === 'yes');
1135
+ }),
1136
+ ws,
1137
+ ),
1138
+ ),
1139
+ ),
1140
+ expect('?>'),
1141
+ ),
1142
+ );
1143
+
1144
+ const prologOrEpilog = (node: Xml.Comment | Xml.ProcessingInstruction): void => {
1145
+ (Option.isNone(x.root) ? x.prolog : x.epilog).push(node);
1146
+ };
1147
+
1148
+ const document: P<unknown> = Compiler.jit(
1149
+ Parser.asVoid(
1150
+ Parser.seq(
1151
+ Parser.opt(xmlDecl),
1152
+ Parser.repeat(
1153
+ Parser.preceded(
1154
+ Parser.not(Parser.eof),
1155
+ Parser.alt(
1156
+ Token.takeWhile(space, { min: 1 }),
1157
+ Parser.preceded(at('<!--'), Parser.tap(comment, prologOrEpilog)),
1158
+ Parser.preceded(at('<?'), Parser.tap(pi, prologOrEpilog)),
1159
+ Parser.preceded(
1160
+ at('<!DOCTYPE'),
1161
+ Parser.preceded(
1162
+ act((pos) => {
1163
+ if (Option.isSome(x.doctype) || Option.isSome(x.root)) {
1164
+ fail('Unexpected DOCTYPE', pos);
1165
+ }
1166
+ }),
1167
+ doctype,
1168
+ ),
1169
+ ),
1170
+ Parser.preceded(
1171
+ at('<'),
1172
+ Parser.preceded(
1173
+ act((pos) => {
1174
+ if (Option.isSome(x.root)) fail('Only one root element is allowed', pos);
1175
+ }),
1176
+ rootElement,
1177
+ ),
1178
+ ),
1179
+ act((pos) =>
1180
+ fail(
1181
+ Option.isNone(x.root)
1182
+ ? 'Expected the root element'
1183
+ : 'Content after the root element',
1184
+ pos,
1185
+ ),
1186
+ ),
1187
+ ),
1188
+ ),
1189
+ ),
1190
+ act((pos) => {
1191
+ if (Option.isNone(x.root)) fail('No root element', pos);
1192
+ }),
1193
+ ),
1194
+ ),
1195
+ );
1196
+
1197
+ /** Parses a (line-end normalised) document, throwing a `Failure`. */
1198
+ const parse = (
1199
+ text: string,
1200
+ lineStarts: ReadonlyArray<number>,
1201
+ onRootChild: RootChildHook,
1202
+ ): Xml.Document => {
1203
+ x = new Context(text, lineStarts);
1204
+ x.onRootChild = onRootChild;
1205
+ const result = Parser.parse(document, text);
1206
+ if (Result.isFailure(result)) fail('Invalid XML', result.failure.offset);
1207
+ return {
1208
+ _tag: 'Document',
1209
+ version: Option.getOrUndefined(x.version),
1210
+ encoding: Option.getOrUndefined(x.encoding),
1211
+ standalone: Option.getOrUndefined(x.standalone),
1212
+ doctype: Option.getOrUndefined(x.doctype),
1213
+ prolog: x.prolog,
1214
+ root: Option.getOrElse(x.root, () => fail('No root element', text.length)),
1215
+ epilog: x.epilog,
1216
+ };
1217
+ };
1218
+
1219
+ /** The line and column of an offset, given the offsets at which lines start. */
1220
+ const positionAt = (lineStarts: ReadonlyArray<number>, offset: number): Xml.Position => {
1221
+ const lo = lineIndex(lineStarts, offset, 0, lineStarts.length - 1);
1222
+ return { offset, line: lo + 1, column: offset - (lineStarts[lo] ?? 0) + 1 };
1223
+ };
1224
+
1225
+ const lineStartsOf = (text: string): Array<number> => {
1226
+ const starts = [0];
1227
+ let i = text.indexOf('\n');
1228
+ loop(() => {
1229
+ if (i === -1) return false;
1230
+ starts.push(i + 1);
1231
+ i = text.indexOf('\n', i + 1);
1232
+ return true;
1233
+ });
1234
+ return starts;
1235
+ };
1236
+
1237
+ /** @internal */
1238
+ export const normalizeInput = (input: string): string => {
1239
+ const noBom = input.charCodeAt(0) === 0xfeff ? input.slice(1) : input;
1240
+ return noBom.includes('\r') ? noBom.replace(/\r\n?/g, '\n') : noBom;
1241
+ };
1242
+
1243
+ /**
1244
+ * Parses a document (normalising its line ends first), throwing a `Failure`
1245
+ * with its position. `onRootChild` may take the root's children as they are
1246
+ * read.
1247
+ *
1248
+ * @internal
1249
+ */
1250
+ export const parseText = (input: string, onRootChild: RootChildHook = keepChild): Xml.Document => {
1251
+ const text = normalizeInput(input);
1252
+ const lineStarts = lineStartsOf(text);
1253
+ const outcome = Result.try({
1254
+ try: () => {
1255
+ const bad = INVALID_CHAR_RE.exec(text);
1256
+ if (bad !== null) fail('Invalid XML character', bad.index);
1257
+ return parse(text, lineStarts, onRootChild);
1258
+ },
1259
+ catch: (e) => e,
1260
+ });
1261
+ if (Result.isSuccess(outcome)) return outcome.success;
1262
+ const e = outcome.failure;
1263
+ if (e instanceof Failure) e.position = positionAt(lineStarts, Math.min(e.offset, text.length));
1264
+ throw e;
1265
+ };