@bolt-foundry/gambit 0.8.1 → 0.8.5-rc.10

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 (293) hide show
  1. package/CHANGELOG.md +150 -2
  2. package/README.md +109 -23
  3. package/esm/_dnt.polyfills.d.ts +17 -0
  4. package/esm/_dnt.polyfills.d.ts.map +1 -1
  5. package/esm/_dnt.polyfills.js +123 -0
  6. package/esm/deps/jsr.io/@std/collections/1.1.6/deep_merge.d.ts +322 -0
  7. package/esm/deps/jsr.io/@std/collections/1.1.6/deep_merge.d.ts.map +1 -0
  8. package/esm/deps/jsr.io/@std/collections/1.1.6/deep_merge.js +105 -0
  9. package/esm/deps/jsr.io/@std/fs/1.0.23/_create_walk_entry.d.ts +14 -0
  10. package/esm/deps/jsr.io/@std/fs/1.0.23/_create_walk_entry.d.ts.map +1 -0
  11. package/esm/deps/jsr.io/@std/fs/1.0.23/_create_walk_entry.js +34 -0
  12. package/esm/deps/jsr.io/@std/fs/1.0.23/_get_file_info_type.d.ts +13 -0
  13. package/esm/deps/jsr.io/@std/fs/1.0.23/_get_file_info_type.d.ts.map +1 -0
  14. package/esm/deps/jsr.io/@std/fs/1.0.23/_get_file_info_type.js +18 -0
  15. package/esm/deps/jsr.io/@std/fs/1.0.23/_is_same_path.d.ts +10 -0
  16. package/esm/deps/jsr.io/@std/fs/1.0.23/_is_same_path.d.ts.map +1 -0
  17. package/esm/deps/jsr.io/@std/fs/1.0.23/_is_same_path.js +17 -0
  18. package/esm/deps/jsr.io/@std/fs/1.0.23/_is_subdir.d.ts +12 -0
  19. package/esm/deps/jsr.io/@std/fs/1.0.23/_is_subdir.d.ts.map +1 -0
  20. package/esm/deps/jsr.io/@std/fs/1.0.23/_is_subdir.js +25 -0
  21. package/esm/deps/jsr.io/@std/fs/1.0.23/_to_path_string.d.ts +9 -0
  22. package/esm/deps/jsr.io/@std/fs/1.0.23/_to_path_string.d.ts.map +1 -0
  23. package/esm/deps/jsr.io/@std/fs/1.0.23/_to_path_string.js +13 -0
  24. package/esm/deps/jsr.io/@std/fs/1.0.23/copy.d.ts +117 -0
  25. package/esm/deps/jsr.io/@std/fs/1.0.23/copy.d.ts.map +1 -0
  26. package/esm/deps/jsr.io/@std/fs/1.0.23/copy.js +313 -0
  27. package/esm/deps/jsr.io/@std/fs/1.0.23/empty_dir.d.ts +48 -0
  28. package/esm/deps/jsr.io/@std/fs/1.0.23/empty_dir.d.ts.map +1 -0
  29. package/esm/deps/jsr.io/@std/fs/1.0.23/empty_dir.js +87 -0
  30. package/esm/deps/jsr.io/@std/fs/1.0.23/ensure_dir.d.ts +49 -0
  31. package/esm/deps/jsr.io/@std/fs/1.0.23/ensure_dir.d.ts.map +1 -0
  32. package/esm/deps/jsr.io/@std/fs/1.0.23/ensure_dir.js +102 -0
  33. package/esm/deps/jsr.io/@std/fs/1.0.23/ensure_file.d.ts +47 -0
  34. package/esm/deps/jsr.io/@std/fs/1.0.23/ensure_file.d.ts.map +1 -0
  35. package/esm/deps/jsr.io/@std/fs/1.0.23/ensure_file.js +90 -0
  36. package/esm/deps/jsr.io/@std/fs/1.0.23/ensure_link.d.ts +49 -0
  37. package/esm/deps/jsr.io/@std/fs/1.0.23/ensure_link.d.ts.map +1 -0
  38. package/esm/deps/jsr.io/@std/fs/1.0.23/ensure_link.js +61 -0
  39. package/esm/deps/jsr.io/@std/fs/1.0.23/ensure_symlink.d.ts +70 -0
  40. package/esm/deps/jsr.io/@std/fs/1.0.23/ensure_symlink.d.ts.map +1 -0
  41. package/esm/deps/jsr.io/@std/fs/1.0.23/ensure_symlink.js +156 -0
  42. package/esm/deps/jsr.io/@std/fs/1.0.23/eol.d.ts +52 -0
  43. package/esm/deps/jsr.io/@std/fs/1.0.23/eol.d.ts.map +1 -0
  44. package/esm/deps/jsr.io/@std/fs/1.0.23/eol.js +67 -0
  45. package/esm/deps/jsr.io/@std/fs/1.0.23/exists.d.ts +218 -0
  46. package/esm/deps/jsr.io/@std/fs/1.0.23/exists.d.ts.map +1 -0
  47. package/esm/deps/jsr.io/@std/fs/1.0.23/exists.js +271 -0
  48. package/esm/deps/jsr.io/@std/fs/1.0.23/expand_glob.d.ts +267 -0
  49. package/esm/deps/jsr.io/@std/fs/1.0.23/expand_glob.d.ts.map +1 -0
  50. package/esm/deps/jsr.io/@std/fs/1.0.23/expand_glob.js +442 -0
  51. package/esm/deps/jsr.io/@std/fs/1.0.23/mod.d.ts +29 -0
  52. package/esm/deps/jsr.io/@std/fs/1.0.23/mod.d.ts.map +1 -0
  53. package/esm/deps/jsr.io/@std/fs/1.0.23/mod.js +29 -0
  54. package/esm/deps/jsr.io/@std/fs/1.0.23/move.d.ts +86 -0
  55. package/esm/deps/jsr.io/@std/fs/1.0.23/move.d.ts.map +1 -0
  56. package/esm/deps/jsr.io/@std/fs/1.0.23/move.js +142 -0
  57. package/esm/deps/jsr.io/@std/fs/1.0.23/walk.d.ts +777 -0
  58. package/esm/deps/jsr.io/@std/fs/1.0.23/walk.d.ts.map +1 -0
  59. package/esm/deps/jsr.io/@std/fs/1.0.23/walk.js +846 -0
  60. package/esm/deps/jsr.io/@std/json/1.0.3/types.d.ts +7 -0
  61. package/esm/deps/jsr.io/@std/json/1.0.3/types.d.ts.map +1 -0
  62. package/esm/deps/jsr.io/@std/json/1.0.3/types.js +3 -0
  63. package/esm/deps/jsr.io/@std/jsonc/1.0.2/mod.d.ts +20 -0
  64. package/esm/deps/jsr.io/@std/jsonc/1.0.2/mod.d.ts.map +1 -0
  65. package/esm/deps/jsr.io/@std/jsonc/1.0.2/mod.js +21 -0
  66. package/esm/deps/jsr.io/@std/jsonc/1.0.2/parse.d.ts +21 -0
  67. package/esm/deps/jsr.io/@std/jsonc/1.0.2/parse.d.ts.map +1 -0
  68. package/esm/deps/jsr.io/@std/jsonc/1.0.2/parse.js +320 -0
  69. package/esm/deps/jsr.io/@std/path/1.1.4/constants.d.ts +1 -1
  70. package/esm/deps/jsr.io/@std/toml/1.0.11/_parser.d.ts +93 -0
  71. package/esm/deps/jsr.io/@std/toml/1.0.11/_parser.d.ts.map +1 -0
  72. package/esm/deps/jsr.io/@std/toml/1.0.11/_parser.js +753 -0
  73. package/esm/deps/jsr.io/@std/toml/1.0.11/mod.d.ts +109 -0
  74. package/esm/deps/jsr.io/@std/toml/1.0.11/mod.d.ts.map +1 -0
  75. package/esm/deps/jsr.io/@std/toml/1.0.11/mod.js +110 -0
  76. package/esm/deps/jsr.io/@std/toml/1.0.11/parse.d.ts +21 -0
  77. package/esm/deps/jsr.io/@std/toml/1.0.11/parse.d.ts.map +1 -0
  78. package/esm/deps/jsr.io/@std/toml/1.0.11/parse.js +25 -0
  79. package/esm/deps/jsr.io/@std/toml/1.0.11/stringify.d.ts +35 -0
  80. package/esm/deps/jsr.io/@std/toml/1.0.11/stringify.d.ts.map +1 -0
  81. package/esm/deps/jsr.io/@std/toml/1.0.11/stringify.js +283 -0
  82. package/esm/gambit/simulator-ui/dist/bundle.js +12670 -5471
  83. package/esm/gambit/simulator-ui/dist/bundle.js.map +4 -4
  84. package/esm/gambit/simulator-ui/dist/favicon.ico +0 -0
  85. package/esm/mod.d.ts +21 -7
  86. package/esm/mod.d.ts.map +1 -1
  87. package/esm/mod.js +14 -4
  88. package/esm/src/cli_utils.d.ts +1 -0
  89. package/esm/src/cli_utils.d.ts.map +1 -1
  90. package/esm/src/cli_utils.js +52 -4
  91. package/esm/src/default_runtime.d.ts +46 -0
  92. package/esm/src/default_runtime.d.ts.map +1 -0
  93. package/esm/src/default_runtime.js +415 -0
  94. package/esm/src/durable_streams.js +26 -1
  95. package/esm/src/model_matchers.d.ts +10 -0
  96. package/esm/src/model_matchers.d.ts.map +1 -0
  97. package/esm/src/model_matchers.js +26 -0
  98. package/esm/src/openai_compat.d.ts +74 -0
  99. package/esm/src/openai_compat.d.ts.map +1 -0
  100. package/esm/src/openai_compat.js +329 -0
  101. package/esm/src/project_config.d.ts +47 -0
  102. package/esm/src/project_config.d.ts.map +1 -0
  103. package/esm/src/project_config.js +134 -0
  104. package/esm/src/providers/codex.d.ts +37 -0
  105. package/esm/src/providers/codex.d.ts.map +1 -0
  106. package/esm/src/providers/codex.js +810 -0
  107. package/esm/src/providers/google.d.ts +18 -0
  108. package/esm/src/providers/google.d.ts.map +1 -0
  109. package/esm/src/providers/google.js +428 -0
  110. package/esm/src/providers/ollama.d.ts +19 -0
  111. package/esm/src/providers/ollama.d.ts.map +1 -0
  112. package/esm/src/providers/ollama.js +789 -0
  113. package/esm/src/providers/openrouter.d.ts +26 -0
  114. package/esm/src/providers/openrouter.d.ts.map +1 -0
  115. package/esm/src/providers/openrouter.js +886 -0
  116. package/esm/src/providers/router.d.ts +19 -0
  117. package/esm/src/providers/router.d.ts.map +1 -0
  118. package/esm/src/providers/router.js +93 -0
  119. package/esm/src/server.d.ts +11 -0
  120. package/esm/src/server.d.ts.map +1 -1
  121. package/esm/src/server.js +3927 -689
  122. package/esm/src/server_feedback_grading_routes.d.ts +32 -0
  123. package/esm/src/server_feedback_grading_routes.d.ts.map +1 -0
  124. package/esm/src/server_feedback_grading_routes.js +305 -0
  125. package/esm/src/server_helpers.d.ts +4 -0
  126. package/esm/src/server_helpers.d.ts.map +1 -0
  127. package/esm/src/server_helpers.js +46 -0
  128. package/esm/src/server_session_store.d.ts +87 -0
  129. package/esm/src/server_session_store.d.ts.map +1 -0
  130. package/esm/src/server_session_store.js +873 -0
  131. package/esm/src/server_types.d.ts +110 -0
  132. package/esm/src/server_types.d.ts.map +1 -0
  133. package/esm/src/server_types.js +1 -0
  134. package/esm/src/server_ui_routes.d.ts +33 -0
  135. package/esm/src/server_ui_routes.d.ts.map +1 -0
  136. package/esm/src/server_ui_routes.js +136 -0
  137. package/esm/src/session_artifacts.d.ts +22 -0
  138. package/esm/src/session_artifacts.d.ts.map +1 -0
  139. package/esm/src/session_artifacts.js +243 -0
  140. package/esm/src/trace.d.ts.map +1 -1
  141. package/esm/src/trace.js +8 -5
  142. package/esm/src/workspace.d.ts +19 -0
  143. package/esm/src/workspace.d.ts.map +1 -0
  144. package/esm/src/workspace.js +162 -0
  145. package/esm/src/workspace_contract.d.ts +78 -0
  146. package/esm/src/workspace_contract.d.ts.map +1 -0
  147. package/esm/src/workspace_contract.js +76 -0
  148. package/package.json +3 -2
  149. package/script/_dnt.polyfills.d.ts +17 -0
  150. package/script/_dnt.polyfills.d.ts.map +1 -1
  151. package/script/_dnt.polyfills.js +123 -0
  152. package/script/deps/jsr.io/@std/collections/1.1.6/deep_merge.d.ts +322 -0
  153. package/script/deps/jsr.io/@std/collections/1.1.6/deep_merge.d.ts.map +1 -0
  154. package/script/deps/jsr.io/@std/collections/1.1.6/deep_merge.js +108 -0
  155. package/script/deps/jsr.io/@std/fs/1.0.23/_create_walk_entry.d.ts +14 -0
  156. package/script/deps/jsr.io/@std/fs/1.0.23/_create_walk_entry.d.ts.map +1 -0
  157. package/script/deps/jsr.io/@std/fs/1.0.23/_create_walk_entry.js +71 -0
  158. package/script/deps/jsr.io/@std/fs/1.0.23/_get_file_info_type.d.ts +13 -0
  159. package/script/deps/jsr.io/@std/fs/1.0.23/_get_file_info_type.d.ts.map +1 -0
  160. package/script/deps/jsr.io/@std/fs/1.0.23/_get_file_info_type.js +21 -0
  161. package/script/deps/jsr.io/@std/fs/1.0.23/_is_same_path.d.ts +10 -0
  162. package/script/deps/jsr.io/@std/fs/1.0.23/_is_same_path.d.ts.map +1 -0
  163. package/script/deps/jsr.io/@std/fs/1.0.23/_is_same_path.js +20 -0
  164. package/script/deps/jsr.io/@std/fs/1.0.23/_is_subdir.d.ts +12 -0
  165. package/script/deps/jsr.io/@std/fs/1.0.23/_is_subdir.d.ts.map +1 -0
  166. package/script/deps/jsr.io/@std/fs/1.0.23/_is_subdir.js +28 -0
  167. package/script/deps/jsr.io/@std/fs/1.0.23/_to_path_string.d.ts +9 -0
  168. package/script/deps/jsr.io/@std/fs/1.0.23/_to_path_string.d.ts.map +1 -0
  169. package/script/deps/jsr.io/@std/fs/1.0.23/_to_path_string.js +16 -0
  170. package/script/deps/jsr.io/@std/fs/1.0.23/copy.d.ts +117 -0
  171. package/script/deps/jsr.io/@std/fs/1.0.23/copy.d.ts.map +1 -0
  172. package/script/deps/jsr.io/@std/fs/1.0.23/copy.js +350 -0
  173. package/script/deps/jsr.io/@std/fs/1.0.23/empty_dir.d.ts +48 -0
  174. package/script/deps/jsr.io/@std/fs/1.0.23/empty_dir.d.ts.map +1 -0
  175. package/script/deps/jsr.io/@std/fs/1.0.23/empty_dir.js +124 -0
  176. package/script/deps/jsr.io/@std/fs/1.0.23/ensure_dir.d.ts +49 -0
  177. package/script/deps/jsr.io/@std/fs/1.0.23/ensure_dir.d.ts.map +1 -0
  178. package/script/deps/jsr.io/@std/fs/1.0.23/ensure_dir.js +139 -0
  179. package/script/deps/jsr.io/@std/fs/1.0.23/ensure_file.d.ts +47 -0
  180. package/script/deps/jsr.io/@std/fs/1.0.23/ensure_file.d.ts.map +1 -0
  181. package/script/deps/jsr.io/@std/fs/1.0.23/ensure_file.js +127 -0
  182. package/script/deps/jsr.io/@std/fs/1.0.23/ensure_link.d.ts +49 -0
  183. package/script/deps/jsr.io/@std/fs/1.0.23/ensure_link.d.ts.map +1 -0
  184. package/script/deps/jsr.io/@std/fs/1.0.23/ensure_link.js +98 -0
  185. package/script/deps/jsr.io/@std/fs/1.0.23/ensure_symlink.d.ts +70 -0
  186. package/script/deps/jsr.io/@std/fs/1.0.23/ensure_symlink.d.ts.map +1 -0
  187. package/script/deps/jsr.io/@std/fs/1.0.23/ensure_symlink.js +193 -0
  188. package/script/deps/jsr.io/@std/fs/1.0.23/eol.d.ts +52 -0
  189. package/script/deps/jsr.io/@std/fs/1.0.23/eol.d.ts.map +1 -0
  190. package/script/deps/jsr.io/@std/fs/1.0.23/eol.js +105 -0
  191. package/script/deps/jsr.io/@std/fs/1.0.23/exists.d.ts +218 -0
  192. package/script/deps/jsr.io/@std/fs/1.0.23/exists.d.ts.map +1 -0
  193. package/script/deps/jsr.io/@std/fs/1.0.23/exists.js +308 -0
  194. package/script/deps/jsr.io/@std/fs/1.0.23/expand_glob.d.ts +267 -0
  195. package/script/deps/jsr.io/@std/fs/1.0.23/expand_glob.d.ts.map +1 -0
  196. package/script/deps/jsr.io/@std/fs/1.0.23/expand_glob.js +479 -0
  197. package/script/deps/jsr.io/@std/fs/1.0.23/mod.d.ts +29 -0
  198. package/script/deps/jsr.io/@std/fs/1.0.23/mod.d.ts.map +1 -0
  199. package/script/deps/jsr.io/@std/fs/1.0.23/mod.js +45 -0
  200. package/script/deps/jsr.io/@std/fs/1.0.23/move.d.ts +86 -0
  201. package/script/deps/jsr.io/@std/fs/1.0.23/move.d.ts.map +1 -0
  202. package/script/deps/jsr.io/@std/fs/1.0.23/move.js +179 -0
  203. package/script/deps/jsr.io/@std/fs/1.0.23/walk.d.ts +777 -0
  204. package/script/deps/jsr.io/@std/fs/1.0.23/walk.d.ts.map +1 -0
  205. package/script/deps/jsr.io/@std/fs/1.0.23/walk.js +883 -0
  206. package/script/deps/jsr.io/@std/json/1.0.3/types.d.ts +7 -0
  207. package/script/deps/jsr.io/@std/json/1.0.3/types.d.ts.map +1 -0
  208. package/script/deps/jsr.io/@std/json/1.0.3/types.js +4 -0
  209. package/script/deps/jsr.io/@std/jsonc/1.0.2/mod.d.ts +20 -0
  210. package/script/deps/jsr.io/@std/jsonc/1.0.2/mod.d.ts.map +1 -0
  211. package/script/deps/jsr.io/@std/jsonc/1.0.2/mod.js +37 -0
  212. package/script/deps/jsr.io/@std/jsonc/1.0.2/parse.d.ts +21 -0
  213. package/script/deps/jsr.io/@std/jsonc/1.0.2/parse.d.ts.map +1 -0
  214. package/script/deps/jsr.io/@std/jsonc/1.0.2/parse.js +323 -0
  215. package/script/deps/jsr.io/@std/path/1.1.4/constants.d.ts +1 -1
  216. package/script/deps/jsr.io/@std/toml/1.0.11/_parser.d.ts +93 -0
  217. package/script/deps/jsr.io/@std/toml/1.0.11/_parser.d.ts.map +1 -0
  218. package/script/deps/jsr.io/@std/toml/1.0.11/_parser.js +781 -0
  219. package/script/deps/jsr.io/@std/toml/1.0.11/mod.d.ts +109 -0
  220. package/script/deps/jsr.io/@std/toml/1.0.11/mod.d.ts.map +1 -0
  221. package/script/deps/jsr.io/@std/toml/1.0.11/mod.js +126 -0
  222. package/script/deps/jsr.io/@std/toml/1.0.11/parse.d.ts +21 -0
  223. package/script/deps/jsr.io/@std/toml/1.0.11/parse.d.ts.map +1 -0
  224. package/script/deps/jsr.io/@std/toml/1.0.11/parse.js +28 -0
  225. package/script/deps/jsr.io/@std/toml/1.0.11/stringify.d.ts +35 -0
  226. package/script/deps/jsr.io/@std/toml/1.0.11/stringify.d.ts.map +1 -0
  227. package/script/deps/jsr.io/@std/toml/1.0.11/stringify.js +286 -0
  228. package/script/gambit/simulator-ui/dist/bundle.js +12670 -5471
  229. package/script/gambit/simulator-ui/dist/bundle.js.map +4 -4
  230. package/script/gambit/simulator-ui/dist/favicon.ico +0 -0
  231. package/script/mod.d.ts +21 -7
  232. package/script/mod.d.ts.map +1 -1
  233. package/script/mod.js +22 -7
  234. package/script/src/cli_utils.d.ts +1 -0
  235. package/script/src/cli_utils.d.ts.map +1 -1
  236. package/script/src/cli_utils.js +52 -3
  237. package/script/src/default_runtime.d.ts +46 -0
  238. package/script/src/default_runtime.d.ts.map +1 -0
  239. package/script/src/default_runtime.js +452 -0
  240. package/script/src/durable_streams.js +26 -1
  241. package/script/src/model_matchers.d.ts +10 -0
  242. package/script/src/model_matchers.d.ts.map +1 -0
  243. package/script/src/model_matchers.js +29 -0
  244. package/script/src/openai_compat.d.ts +74 -0
  245. package/script/src/openai_compat.d.ts.map +1 -0
  246. package/script/src/openai_compat.js +366 -0
  247. package/script/src/project_config.d.ts +47 -0
  248. package/script/src/project_config.d.ts.map +1 -0
  249. package/script/src/project_config.js +173 -0
  250. package/script/src/providers/codex.d.ts +37 -0
  251. package/script/src/providers/codex.d.ts.map +1 -0
  252. package/script/src/providers/codex.js +850 -0
  253. package/script/src/providers/google.d.ts +18 -0
  254. package/script/src/providers/google.d.ts.map +1 -0
  255. package/script/src/providers/google.js +435 -0
  256. package/script/src/providers/ollama.d.ts +19 -0
  257. package/script/src/providers/ollama.d.ts.map +1 -0
  258. package/script/src/providers/ollama.js +831 -0
  259. package/script/src/providers/openrouter.d.ts +26 -0
  260. package/script/src/providers/openrouter.d.ts.map +1 -0
  261. package/script/src/providers/openrouter.js +926 -0
  262. package/script/src/providers/router.d.ts +19 -0
  263. package/script/src/providers/router.d.ts.map +1 -0
  264. package/script/src/providers/router.js +96 -0
  265. package/script/src/server.d.ts +11 -0
  266. package/script/src/server.d.ts.map +1 -1
  267. package/script/src/server.js +3931 -693
  268. package/script/src/server_feedback_grading_routes.d.ts +32 -0
  269. package/script/src/server_feedback_grading_routes.d.ts.map +1 -0
  270. package/script/src/server_feedback_grading_routes.js +343 -0
  271. package/script/src/server_helpers.d.ts +4 -0
  272. package/script/src/server_helpers.d.ts.map +1 -0
  273. package/script/src/server_helpers.js +84 -0
  274. package/script/src/server_session_store.d.ts +87 -0
  275. package/script/src/server_session_store.d.ts.map +1 -0
  276. package/script/src/server_session_store.js +910 -0
  277. package/script/src/server_types.d.ts +110 -0
  278. package/script/src/server_types.d.ts.map +1 -0
  279. package/script/src/server_types.js +2 -0
  280. package/script/src/server_ui_routes.d.ts +33 -0
  281. package/script/src/server_ui_routes.d.ts.map +1 -0
  282. package/script/src/server_ui_routes.js +173 -0
  283. package/script/src/session_artifacts.d.ts +22 -0
  284. package/script/src/session_artifacts.d.ts.map +1 -0
  285. package/script/src/session_artifacts.js +279 -0
  286. package/script/src/trace.d.ts.map +1 -1
  287. package/script/src/trace.js +8 -5
  288. package/script/src/workspace.d.ts +19 -0
  289. package/script/src/workspace.d.ts.map +1 -0
  290. package/script/src/workspace.js +199 -0
  291. package/script/src/workspace_contract.d.ts +78 -0
  292. package/script/src/workspace_contract.d.ts.map +1 -0
  293. package/script/src/workspace_contract.js +84 -0
@@ -0,0 +1,753 @@
1
+ // Copyright 2018-2025 the Deno authors. MIT license.
2
+ // This module is browser compatible.
3
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
4
+ if (kind === "m") throw new TypeError("Private method is not writable");
5
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
6
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
7
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
8
+ };
9
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
10
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
11
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
12
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
13
+ };
14
+ var _Scanner_whitespace, _Scanner_position, _Scanner_source;
15
+ import { deepMerge } from "../../collections/1.1.6/deep_merge.js";
16
+ /**
17
+ * Copy of `import { isLeap } from "@std/datetime";` because it cannot be impoted as long as it is unstable.
18
+ */
19
+ function isLeap(yearNumber) {
20
+ return ((yearNumber % 4 === 0 && yearNumber % 100 !== 0) || yearNumber % 400 === 0);
21
+ }
22
+ export class Scanner {
23
+ constructor(source) {
24
+ _Scanner_whitespace.set(this, /[ \t]/);
25
+ _Scanner_position.set(this, 0);
26
+ _Scanner_source.set(this, void 0);
27
+ __classPrivateFieldSet(this, _Scanner_source, source, "f");
28
+ }
29
+ get position() {
30
+ return __classPrivateFieldGet(this, _Scanner_position, "f");
31
+ }
32
+ get source() {
33
+ return __classPrivateFieldGet(this, _Scanner_source, "f");
34
+ }
35
+ /**
36
+ * Get current character
37
+ * @param index - relative index from current position
38
+ */
39
+ char(index = 0) {
40
+ return __classPrivateFieldGet(this, _Scanner_source, "f")[__classPrivateFieldGet(this, _Scanner_position, "f") + index] ?? "";
41
+ }
42
+ /**
43
+ * Get sliced string
44
+ * @param start - start position relative from current position
45
+ * @param end - end position relative from current position
46
+ */
47
+ slice(start, end) {
48
+ return __classPrivateFieldGet(this, _Scanner_source, "f").slice(__classPrivateFieldGet(this, _Scanner_position, "f") + start, __classPrivateFieldGet(this, _Scanner_position, "f") + end);
49
+ }
50
+ /**
51
+ * Move position to next
52
+ */
53
+ next(count = 1) {
54
+ __classPrivateFieldSet(this, _Scanner_position, __classPrivateFieldGet(this, _Scanner_position, "f") + count, "f");
55
+ }
56
+ skipWhitespaces() {
57
+ while (__classPrivateFieldGet(this, _Scanner_whitespace, "f").test(this.char()) && !this.eof()) {
58
+ this.next();
59
+ }
60
+ // Invalid if current char is other kinds of whitespace
61
+ if (!this.isCurrentCharEOL() && /\s/.test(this.char())) {
62
+ const escaped = "\\u" + this.char().charCodeAt(0).toString(16);
63
+ const position = __classPrivateFieldGet(this, _Scanner_position, "f");
64
+ throw new SyntaxError(`Cannot parse the TOML: It contains invalid whitespace at position '${position}': \`${escaped}\``);
65
+ }
66
+ }
67
+ nextUntilChar(options = { skipComments: true }) {
68
+ while (!this.eof()) {
69
+ const char = this.char();
70
+ if (__classPrivateFieldGet(this, _Scanner_whitespace, "f").test(char) || this.isCurrentCharEOL()) {
71
+ this.next();
72
+ }
73
+ else if (options.skipComments && this.char() === "#") {
74
+ // entering comment
75
+ while (!this.isCurrentCharEOL() && !this.eof()) {
76
+ this.next();
77
+ }
78
+ }
79
+ else {
80
+ break;
81
+ }
82
+ }
83
+ }
84
+ /**
85
+ * Position reached EOF or not
86
+ */
87
+ eof() {
88
+ return __classPrivateFieldGet(this, _Scanner_position, "f") >= __classPrivateFieldGet(this, _Scanner_source, "f").length;
89
+ }
90
+ isCurrentCharEOL() {
91
+ return this.char() === "\n" || this.startsWith("\r\n");
92
+ }
93
+ startsWith(searchString) {
94
+ return __classPrivateFieldGet(this, _Scanner_source, "f").startsWith(searchString, __classPrivateFieldGet(this, _Scanner_position, "f"));
95
+ }
96
+ match(regExp) {
97
+ if (!regExp.sticky) {
98
+ throw new Error(`RegExp ${regExp} does not have a sticky 'y' flag`);
99
+ }
100
+ regExp.lastIndex = __classPrivateFieldGet(this, _Scanner_position, "f");
101
+ return __classPrivateFieldGet(this, _Scanner_source, "f").match(regExp);
102
+ }
103
+ }
104
+ _Scanner_whitespace = new WeakMap(), _Scanner_position = new WeakMap(), _Scanner_source = new WeakMap();
105
+ // -----------------------
106
+ // Utilities
107
+ // -----------------------
108
+ function success(body) {
109
+ return { ok: true, body };
110
+ }
111
+ function failure() {
112
+ return { ok: false };
113
+ }
114
+ /**
115
+ * Creates a nested object from the keys and values.
116
+ *
117
+ * e.g. `unflat(["a", "b", "c"], 1)` returns `{ a: { b: { c: 1 } } }`
118
+ */
119
+ export function unflat(keys, values = { __proto__: null }) {
120
+ return keys.reduceRight((acc, key) => ({ [key]: acc }), values);
121
+ }
122
+ function isObject(value) {
123
+ return typeof value === "object" && value !== null;
124
+ }
125
+ function getTargetValue(target, keys) {
126
+ const key = keys[0];
127
+ if (!key) {
128
+ throw new Error("Cannot parse the TOML: key length is not a positive number");
129
+ }
130
+ return target[key];
131
+ }
132
+ function deepAssignTable(target, table) {
133
+ const { keys, type, value } = table;
134
+ const currentValue = getTargetValue(target, keys);
135
+ if (currentValue === undefined) {
136
+ return Object.assign(target, unflat(keys, value));
137
+ }
138
+ if (Array.isArray(currentValue)) {
139
+ const last = currentValue.at(-1);
140
+ deepAssign(last, { type, keys: keys.slice(1), value });
141
+ return target;
142
+ }
143
+ if (isObject(currentValue)) {
144
+ deepAssign(currentValue, { type, keys: keys.slice(1), value });
145
+ return target;
146
+ }
147
+ throw new Error("Unexpected assign");
148
+ }
149
+ function deepAssignTableArray(target, table) {
150
+ const { type, keys, value } = table;
151
+ const currentValue = getTargetValue(target, keys);
152
+ if (currentValue === undefined) {
153
+ return Object.assign(target, unflat(keys, [value]));
154
+ }
155
+ if (Array.isArray(currentValue)) {
156
+ if (table.keys.length === 1) {
157
+ currentValue.push(value);
158
+ }
159
+ else {
160
+ const last = currentValue.at(-1);
161
+ deepAssign(last, {
162
+ type: table.type,
163
+ keys: table.keys.slice(1),
164
+ value: table.value,
165
+ });
166
+ }
167
+ return target;
168
+ }
169
+ if (isObject(currentValue)) {
170
+ deepAssign(currentValue, { type, keys: keys.slice(1), value });
171
+ return target;
172
+ }
173
+ throw new Error("Unexpected assign");
174
+ }
175
+ export function deepAssign(target, body) {
176
+ switch (body.type) {
177
+ case "Block":
178
+ return deepMerge(target, body.value);
179
+ case "Table":
180
+ return deepAssignTable(target, body);
181
+ case "TableArray":
182
+ return deepAssignTableArray(target, body);
183
+ }
184
+ }
185
+ // ---------------------------------
186
+ // Parser combinators and generators
187
+ // ---------------------------------
188
+ // deno-lint-ignore no-explicit-any
189
+ function or(parsers) {
190
+ return (scanner) => {
191
+ for (const parse of parsers) {
192
+ const result = parse(scanner);
193
+ if (result.ok)
194
+ return result;
195
+ }
196
+ return failure();
197
+ };
198
+ }
199
+ /** Join the parse results of the given parser into an array.
200
+ *
201
+ * If the parser fails at the first attempt, it will return an empty array.
202
+ */
203
+ function join(parser, separator) {
204
+ const Separator = character(separator);
205
+ return (scanner) => {
206
+ const out = [];
207
+ const first = parser(scanner);
208
+ if (!first.ok)
209
+ return success(out);
210
+ out.push(first.body);
211
+ while (!scanner.eof()) {
212
+ if (!Separator(scanner).ok)
213
+ break;
214
+ const result = parser(scanner);
215
+ if (!result.ok) {
216
+ throw new SyntaxError(`Invalid token after "${separator}"`);
217
+ }
218
+ out.push(result.body);
219
+ }
220
+ return success(out);
221
+ };
222
+ }
223
+ /** Join the parse results of the given parser into an array.
224
+ *
225
+ * This requires the parser to succeed at least once.
226
+ */
227
+ function join1(parser, separator) {
228
+ const Separator = character(separator);
229
+ return (scanner) => {
230
+ const first = parser(scanner);
231
+ if (!first.ok)
232
+ return failure();
233
+ const out = [first.body];
234
+ while (!scanner.eof()) {
235
+ if (!Separator(scanner).ok)
236
+ break;
237
+ const result = parser(scanner);
238
+ if (!result.ok) {
239
+ throw new SyntaxError(`Invalid token after "${separator}"`);
240
+ }
241
+ out.push(result.body);
242
+ }
243
+ return success(out);
244
+ };
245
+ }
246
+ function kv(keyParser, separator, valueParser) {
247
+ const Separator = character(separator);
248
+ return (scanner) => {
249
+ const position = scanner.position;
250
+ const key = keyParser(scanner);
251
+ if (!key.ok)
252
+ return failure();
253
+ const sep = Separator(scanner);
254
+ if (!sep.ok) {
255
+ throw new SyntaxError(`key/value pair doesn't have "${separator}"`);
256
+ }
257
+ const value = valueParser(scanner);
258
+ if (!value.ok) {
259
+ const lineEndIndex = scanner.source.indexOf("\n", scanner.position);
260
+ const endPosition = lineEndIndex > 0
261
+ ? lineEndIndex
262
+ : scanner.source.length;
263
+ const line = scanner.source.slice(position, endPosition);
264
+ throw new SyntaxError(`Cannot parse value on line '${line}'`);
265
+ }
266
+ return success(unflat(key.body, value.body));
267
+ };
268
+ }
269
+ function merge(parser) {
270
+ return (scanner) => {
271
+ const result = parser(scanner);
272
+ if (!result.ok)
273
+ return failure();
274
+ let body = { __proto__: null };
275
+ for (const record of result.body) {
276
+ if (typeof record === "object" && record !== null) {
277
+ body = deepMerge(body, record);
278
+ }
279
+ }
280
+ return success(body);
281
+ };
282
+ }
283
+ function repeat(parser) {
284
+ return (scanner) => {
285
+ const body = [];
286
+ while (!scanner.eof()) {
287
+ const result = parser(scanner);
288
+ if (!result.ok)
289
+ break;
290
+ body.push(result.body);
291
+ scanner.nextUntilChar();
292
+ }
293
+ if (body.length === 0)
294
+ return failure();
295
+ return success(body);
296
+ };
297
+ }
298
+ function surround(left, parser, right) {
299
+ const Left = character(left);
300
+ const Right = character(right);
301
+ return (scanner) => {
302
+ if (!Left(scanner).ok) {
303
+ return failure();
304
+ }
305
+ const result = parser(scanner);
306
+ if (!result.ok) {
307
+ throw new SyntaxError(`Invalid token after "${left}"`);
308
+ }
309
+ if (!Right(scanner).ok) {
310
+ throw new SyntaxError(`Not closed by "${right}" after started with "${left}"`);
311
+ }
312
+ return success(result.body);
313
+ };
314
+ }
315
+ function character(str) {
316
+ return (scanner) => {
317
+ scanner.skipWhitespaces();
318
+ if (!scanner.startsWith(str))
319
+ return failure();
320
+ scanner.next(str.length);
321
+ scanner.skipWhitespaces();
322
+ return success(undefined);
323
+ };
324
+ }
325
+ // -----------------------
326
+ // Parser components
327
+ // -----------------------
328
+ const BARE_KEY_REGEXP = /[A-Za-z0-9_-]+/y;
329
+ export function bareKey(scanner) {
330
+ scanner.skipWhitespaces();
331
+ const key = scanner.match(BARE_KEY_REGEXP)?.[0];
332
+ if (!key)
333
+ return failure();
334
+ scanner.next(key.length);
335
+ return success(key);
336
+ }
337
+ function escapeSequence(scanner) {
338
+ if (scanner.char() !== "\\")
339
+ return failure();
340
+ scanner.next();
341
+ // See https://toml.io/en/v1.0.0-rc.3#string
342
+ switch (scanner.char()) {
343
+ case "b":
344
+ scanner.next();
345
+ return success("\b");
346
+ case "t":
347
+ scanner.next();
348
+ return success("\t");
349
+ case "n":
350
+ scanner.next();
351
+ return success("\n");
352
+ case "f":
353
+ scanner.next();
354
+ return success("\f");
355
+ case "r":
356
+ scanner.next();
357
+ return success("\r");
358
+ case "u":
359
+ case "U": {
360
+ // Unicode character
361
+ const codePointLen = scanner.char() === "u" ? 4 : 6;
362
+ const codePoint = parseInt("0x" + scanner.slice(1, 1 + codePointLen), 16);
363
+ const str = String.fromCodePoint(codePoint);
364
+ scanner.next(codePointLen + 1);
365
+ return success(str);
366
+ }
367
+ case '"':
368
+ scanner.next();
369
+ return success('"');
370
+ case "\\":
371
+ scanner.next();
372
+ return success("\\");
373
+ default:
374
+ throw new SyntaxError(`Invalid escape sequence: \\${scanner.char()}`);
375
+ }
376
+ }
377
+ export function basicString(scanner) {
378
+ scanner.skipWhitespaces();
379
+ if (scanner.char() !== '"')
380
+ return failure();
381
+ scanner.next();
382
+ const acc = [];
383
+ while (scanner.char() !== '"' && !scanner.eof()) {
384
+ if (scanner.char() === "\n") {
385
+ throw new SyntaxError("Single-line string cannot contain EOL");
386
+ }
387
+ const escapedChar = escapeSequence(scanner);
388
+ if (escapedChar.ok) {
389
+ acc.push(escapedChar.body);
390
+ }
391
+ else {
392
+ acc.push(scanner.char());
393
+ scanner.next();
394
+ }
395
+ }
396
+ if (scanner.eof()) {
397
+ throw new SyntaxError(`Single-line string is not closed:\n${acc.join("")}`);
398
+ }
399
+ scanner.next(); // skip last '""
400
+ return success(acc.join(""));
401
+ }
402
+ export function literalString(scanner) {
403
+ scanner.skipWhitespaces();
404
+ if (scanner.char() !== "'")
405
+ return failure();
406
+ scanner.next();
407
+ const acc = [];
408
+ while (scanner.char() !== "'" && !scanner.eof()) {
409
+ if (scanner.char() === "\n") {
410
+ throw new SyntaxError("Single-line string cannot contain EOL");
411
+ }
412
+ acc.push(scanner.char());
413
+ scanner.next();
414
+ }
415
+ if (scanner.eof()) {
416
+ throw new SyntaxError(`Single-line string is not closed:\n${acc.join("")}`);
417
+ }
418
+ scanner.next(); // skip last "'"
419
+ return success(acc.join(""));
420
+ }
421
+ export function multilineBasicString(scanner) {
422
+ scanner.skipWhitespaces();
423
+ if (!scanner.startsWith('"""'))
424
+ return failure();
425
+ scanner.next(3);
426
+ if (scanner.char() === "\n") {
427
+ // The first newline (LF) is trimmed
428
+ scanner.next();
429
+ }
430
+ else if (scanner.startsWith("\r\n")) {
431
+ // The first newline (CRLF) is trimmed
432
+ scanner.next(2);
433
+ }
434
+ const acc = [];
435
+ while (!scanner.startsWith('"""') && !scanner.eof()) {
436
+ // line ending backslash
437
+ if (scanner.startsWith("\\\n")) {
438
+ scanner.next();
439
+ scanner.nextUntilChar({ skipComments: false });
440
+ continue;
441
+ }
442
+ else if (scanner.startsWith("\\\r\n")) {
443
+ scanner.next();
444
+ scanner.nextUntilChar({ skipComments: false });
445
+ continue;
446
+ }
447
+ const escapedChar = escapeSequence(scanner);
448
+ if (escapedChar.ok) {
449
+ acc.push(escapedChar.body);
450
+ }
451
+ else {
452
+ acc.push(scanner.char());
453
+ scanner.next();
454
+ }
455
+ }
456
+ if (scanner.eof()) {
457
+ throw new SyntaxError(`Multi-line string is not closed:\n${acc.join("")}`);
458
+ }
459
+ // if ends with 4 `"`, push the fist `"` to string
460
+ if (scanner.char(3) === '"') {
461
+ acc.push('"');
462
+ scanner.next();
463
+ }
464
+ scanner.next(3); // skip last '""""
465
+ return success(acc.join(""));
466
+ }
467
+ export function multilineLiteralString(scanner) {
468
+ scanner.skipWhitespaces();
469
+ if (!scanner.startsWith("'''"))
470
+ return failure();
471
+ scanner.next(3);
472
+ if (scanner.char() === "\n") {
473
+ // The first newline (LF) is trimmed
474
+ scanner.next();
475
+ }
476
+ else if (scanner.startsWith("\r\n")) {
477
+ // The first newline (CRLF) is trimmed
478
+ scanner.next(2);
479
+ }
480
+ const acc = [];
481
+ while (!scanner.startsWith("'''") && !scanner.eof()) {
482
+ acc.push(scanner.char());
483
+ scanner.next();
484
+ }
485
+ if (scanner.eof()) {
486
+ throw new SyntaxError(`Multi-line string is not closed:\n${acc.join("")}`);
487
+ }
488
+ // if ends with 4 `'`, push the fist `'` to string
489
+ if (scanner.char(3) === "'") {
490
+ acc.push("'");
491
+ scanner.next();
492
+ }
493
+ scanner.next(3); // skip last "'''"
494
+ return success(acc.join(""));
495
+ }
496
+ const BOOLEAN_REGEXP = /(?:true|false)\b/y;
497
+ export function boolean(scanner) {
498
+ scanner.skipWhitespaces();
499
+ const match = scanner.match(BOOLEAN_REGEXP);
500
+ if (!match)
501
+ return failure();
502
+ const string = match[0];
503
+ scanner.next(string.length);
504
+ const value = string === "true";
505
+ return success(value);
506
+ }
507
+ const INFINITY_MAP = new Map([
508
+ ["inf", Infinity],
509
+ ["+inf", Infinity],
510
+ ["-inf", -Infinity],
511
+ ]);
512
+ const INFINITY_REGEXP = /[+-]?inf\b/y;
513
+ export function infinity(scanner) {
514
+ scanner.skipWhitespaces();
515
+ const match = scanner.match(INFINITY_REGEXP);
516
+ if (!match)
517
+ return failure();
518
+ const string = match[0];
519
+ scanner.next(string.length);
520
+ const value = INFINITY_MAP.get(string);
521
+ return success(value);
522
+ }
523
+ const NAN_REGEXP = /[+-]?nan\b/y;
524
+ export function nan(scanner) {
525
+ scanner.skipWhitespaces();
526
+ const match = scanner.match(NAN_REGEXP);
527
+ if (!match)
528
+ return failure();
529
+ const string = match[0];
530
+ scanner.next(string.length);
531
+ const value = NaN;
532
+ return success(value);
533
+ }
534
+ export const dottedKey = join1(or([bareKey, basicString, literalString]), ".");
535
+ const BINARY_REGEXP = /0b[01]+(?:_[01]+)*\b/y;
536
+ export function binary(scanner) {
537
+ scanner.skipWhitespaces();
538
+ const match = scanner.match(BINARY_REGEXP)?.[0];
539
+ if (!match)
540
+ return failure();
541
+ scanner.next(match.length);
542
+ const value = match.slice(2).replaceAll("_", "");
543
+ const number = parseInt(value, 2);
544
+ return isNaN(number) ? failure() : success(number);
545
+ }
546
+ const OCTAL_REGEXP = /0o[0-7]+(?:_[0-7]+)*\b/y;
547
+ export function octal(scanner) {
548
+ scanner.skipWhitespaces();
549
+ const match = scanner.match(OCTAL_REGEXP)?.[0];
550
+ if (!match)
551
+ return failure();
552
+ scanner.next(match.length);
553
+ const value = match.slice(2).replaceAll("_", "");
554
+ const number = parseInt(value, 8);
555
+ return isNaN(number) ? failure() : success(number);
556
+ }
557
+ const HEX_REGEXP = /0x[0-9a-f]+(?:_[0-9a-f]+)*\b/yi;
558
+ export function hex(scanner) {
559
+ scanner.skipWhitespaces();
560
+ const match = scanner.match(HEX_REGEXP)?.[0];
561
+ if (!match)
562
+ return failure();
563
+ scanner.next(match.length);
564
+ const value = match.slice(2).replaceAll("_", "");
565
+ const number = parseInt(value, 16);
566
+ return isNaN(number) ? failure() : success(number);
567
+ }
568
+ const INTEGER_REGEXP = /[+-]?(?:0|[1-9][0-9]*(?:_[0-9]+)*)\b/y;
569
+ export function integer(scanner) {
570
+ scanner.skipWhitespaces();
571
+ const match = scanner.match(INTEGER_REGEXP)?.[0];
572
+ if (!match)
573
+ return failure();
574
+ scanner.next(match.length);
575
+ const value = match.replaceAll("_", "");
576
+ const int = parseInt(value, 10);
577
+ return success(int);
578
+ }
579
+ const FLOAT_REGEXP = /[+-]?(?:0|[1-9][0-9]*(?:_[0-9]+)*)(?:\.[0-9]+(?:_[0-9]+)*)?(?:e[+-]?[0-9]+(?:_[0-9]+)*)?\b/yi;
580
+ export function float(scanner) {
581
+ scanner.skipWhitespaces();
582
+ const match = scanner.match(FLOAT_REGEXP)?.[0];
583
+ if (!match)
584
+ return failure();
585
+ scanner.next(match.length);
586
+ const value = match.replaceAll("_", "");
587
+ const float = parseFloat(value);
588
+ if (isNaN(float))
589
+ return failure();
590
+ return success(float);
591
+ }
592
+ const DATE_TIME_REGEXP = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})(?:[ 0-9TZ.:+-]+)?\b/y;
593
+ export function dateTime(scanner) {
594
+ scanner.skipWhitespaces();
595
+ const match = scanner.match(DATE_TIME_REGEXP);
596
+ if (!match)
597
+ return failure();
598
+ const string = match[0];
599
+ scanner.next(string.length);
600
+ const groups = match.groups;
601
+ // special case if month is February
602
+ if (groups.month == "02") {
603
+ const days = parseInt(groups.day);
604
+ if (days > 29) {
605
+ throw new SyntaxError(`Invalid date string "${match}"`);
606
+ }
607
+ const year = parseInt(groups.year);
608
+ if (days > 28 && !isLeap(year)) {
609
+ throw new SyntaxError(`Invalid date string "${match}"`);
610
+ }
611
+ }
612
+ const date = new Date(string.trim());
613
+ // invalid date
614
+ if (isNaN(date.getTime())) {
615
+ throw new SyntaxError(`Invalid date string "${match}"`);
616
+ }
617
+ return success(date);
618
+ }
619
+ const LOCAL_TIME_REGEXP = /(\d{2}):(\d{2}):(\d{2})(?:\.[0-9]+)?\b/y;
620
+ export function localTime(scanner) {
621
+ scanner.skipWhitespaces();
622
+ const match = scanner.match(LOCAL_TIME_REGEXP)?.[0];
623
+ if (!match)
624
+ return failure();
625
+ scanner.next(match.length);
626
+ return success(match);
627
+ }
628
+ export function arrayValue(scanner) {
629
+ scanner.skipWhitespaces();
630
+ if (scanner.char() !== "[")
631
+ return failure();
632
+ scanner.next();
633
+ const array = [];
634
+ while (!scanner.eof()) {
635
+ scanner.nextUntilChar();
636
+ const result = value(scanner);
637
+ if (!result.ok)
638
+ break;
639
+ array.push(result.body);
640
+ scanner.skipWhitespaces();
641
+ // may have a next item, but trailing comma is allowed at array
642
+ if (scanner.char() !== ",")
643
+ break;
644
+ scanner.next();
645
+ }
646
+ scanner.nextUntilChar();
647
+ if (scanner.char() !== "]")
648
+ throw new SyntaxError("Array is not closed");
649
+ scanner.next();
650
+ return success(array);
651
+ }
652
+ export function inlineTable(scanner) {
653
+ scanner.nextUntilChar();
654
+ if (scanner.char(1) === "}") {
655
+ scanner.next(2);
656
+ return success({ __proto__: null });
657
+ }
658
+ const pairs = surround("{", join(pair, ","), "}")(scanner);
659
+ if (!pairs.ok)
660
+ return failure();
661
+ let table = { __proto__: null };
662
+ for (const pair of pairs.body) {
663
+ table = deepMerge(table, pair);
664
+ }
665
+ return success(table);
666
+ }
667
+ export const value = or([
668
+ multilineBasicString,
669
+ multilineLiteralString,
670
+ basicString,
671
+ literalString,
672
+ boolean,
673
+ infinity,
674
+ nan,
675
+ dateTime,
676
+ localTime,
677
+ binary,
678
+ octal,
679
+ hex,
680
+ float,
681
+ integer,
682
+ arrayValue,
683
+ inlineTable,
684
+ ]);
685
+ export const pair = kv(dottedKey, "=", value);
686
+ export function block(scanner) {
687
+ scanner.nextUntilChar();
688
+ const result = merge(repeat(pair))(scanner);
689
+ if (result.ok)
690
+ return success({ type: "Block", value: result.body });
691
+ return failure();
692
+ }
693
+ export const tableHeader = surround("[", dottedKey, "]");
694
+ export function table(scanner) {
695
+ scanner.nextUntilChar();
696
+ const header = tableHeader(scanner);
697
+ if (!header.ok)
698
+ return failure();
699
+ scanner.nextUntilChar();
700
+ const b = block(scanner);
701
+ return success({
702
+ type: "Table",
703
+ keys: header.body,
704
+ value: b.ok ? b.body.value : { __proto__: null },
705
+ });
706
+ }
707
+ export const tableArrayHeader = surround("[[", dottedKey, "]]");
708
+ export function tableArray(scanner) {
709
+ scanner.nextUntilChar();
710
+ const header = tableArrayHeader(scanner);
711
+ if (!header.ok)
712
+ return failure();
713
+ scanner.nextUntilChar();
714
+ const b = block(scanner);
715
+ return success({
716
+ type: "TableArray",
717
+ keys: header.body,
718
+ value: b.ok ? b.body.value : { __proto__: null },
719
+ });
720
+ }
721
+ export function toml(scanner) {
722
+ const blocks = repeat(or([block, tableArray, table]))(scanner);
723
+ if (!blocks.ok)
724
+ return success({ __proto__: null });
725
+ const body = blocks.body.reduce(deepAssign, { __proto__: null });
726
+ return success(body);
727
+ }
728
+ function createParseErrorMessage(scanner, message) {
729
+ const string = scanner.source.slice(0, scanner.position);
730
+ const lines = string.split("\n");
731
+ const row = lines.length;
732
+ const column = lines.at(-1)?.length ?? 0;
733
+ return `Parse error on line ${row}, column ${column}: ${message}`;
734
+ }
735
+ export function parserFactory(parser) {
736
+ return (tomlString) => {
737
+ const scanner = new Scanner(tomlString);
738
+ try {
739
+ const result = parser(scanner);
740
+ if (result.ok && scanner.eof())
741
+ return result.body;
742
+ const message = `Unexpected character: "${scanner.char()}"`;
743
+ throw new SyntaxError(createParseErrorMessage(scanner, message));
744
+ }
745
+ catch (error) {
746
+ if (error instanceof Error) {
747
+ throw new SyntaxError(createParseErrorMessage(scanner, error.message));
748
+ }
749
+ const message = "Invalid error type caught";
750
+ throw new SyntaxError(createParseErrorMessage(scanner, message));
751
+ }
752
+ };
753
+ }