openalgo-script 0.2.0 → 0.5.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 (357) hide show
  1. package/CHANGELOG.md +1198 -0
  2. package/README.md +127 -40
  3. package/dist/adapters/charts/driving.d.ts +50 -0
  4. package/dist/adapters/charts/driving.d.ts.map +1 -0
  5. package/dist/adapters/charts/driving.js +57 -0
  6. package/dist/adapters/charts/driving.js.map +1 -0
  7. package/dist/adapters/charts/run.d.ts +20 -0
  8. package/dist/adapters/charts/run.d.ts.map +1 -1
  9. package/dist/adapters/charts/run.js +83 -16
  10. package/dist/adapters/charts/run.js.map +1 -1
  11. package/dist/adapters/charts/surfaces.d.ts +17 -0
  12. package/dist/adapters/charts/surfaces.d.ts.map +1 -1
  13. package/dist/adapters/charts/tables.js +82 -0
  14. package/dist/adapters/charts/tables.js.map +1 -1
  15. package/dist/adapters/charts/venue.d.ts +73 -0
  16. package/dist/adapters/charts/venue.d.ts.map +1 -0
  17. package/dist/adapters/charts/venue.js +104 -0
  18. package/dist/adapters/charts/venue.js.map +1 -0
  19. package/dist/adapters/codemirror/commands.d.ts +14 -0
  20. package/dist/adapters/codemirror/commands.d.ts.map +1 -0
  21. package/dist/adapters/codemirror/commands.js +52 -0
  22. package/dist/adapters/codemirror/commands.js.map +1 -0
  23. package/dist/adapters/codemirror/completion.d.ts +15 -0
  24. package/dist/adapters/codemirror/completion.d.ts.map +1 -0
  25. package/dist/adapters/codemirror/completion.js +64 -0
  26. package/dist/adapters/codemirror/completion.js.map +1 -0
  27. package/dist/adapters/codemirror/contract.d.ts +156 -0
  28. package/dist/adapters/codemirror/contract.d.ts.map +1 -0
  29. package/dist/adapters/codemirror/contract.js +42 -0
  30. package/dist/adapters/codemirror/contract.js.map +1 -0
  31. package/dist/adapters/codemirror/index.d.ts +43 -0
  32. package/dist/adapters/codemirror/index.d.ts.map +1 -0
  33. package/dist/adapters/codemirror/index.js +8 -0
  34. package/dist/adapters/codemirror/index.js.map +1 -0
  35. package/dist/adapters/codemirror/lint.d.ts +17 -0
  36. package/dist/adapters/codemirror/lint.d.ts.map +1 -0
  37. package/dist/adapters/codemirror/lint.js +62 -0
  38. package/dist/adapters/codemirror/lint.js.map +1 -0
  39. package/dist/adapters/codemirror/positions.d.ts +16 -0
  40. package/dist/adapters/codemirror/positions.d.ts.map +1 -0
  41. package/dist/adapters/codemirror/positions.js +65 -0
  42. package/dist/adapters/codemirror/positions.js.map +1 -0
  43. package/dist/adapters/codemirror/stream.d.ts +23 -0
  44. package/dist/adapters/codemirror/stream.d.ts.map +1 -0
  45. package/dist/adapters/codemirror/stream.js +70 -0
  46. package/dist/adapters/codemirror/stream.js.map +1 -0
  47. package/dist/adapters/codemirror/tokens.d.ts +44 -0
  48. package/dist/adapters/codemirror/tokens.d.ts.map +1 -0
  49. package/dist/adapters/codemirror/tokens.js +34 -0
  50. package/dist/adapters/codemirror/tokens.js.map +1 -0
  51. package/dist/adapters/codemirror/tooltips.d.ts +35 -0
  52. package/dist/adapters/codemirror/tooltips.d.ts.map +1 -0
  53. package/dist/adapters/codemirror/tooltips.js +108 -0
  54. package/dist/adapters/codemirror/tooltips.js.map +1 -0
  55. package/dist/core/accounting/analysis.d.ts +111 -0
  56. package/dist/core/accounting/analysis.d.ts.map +1 -0
  57. package/dist/core/accounting/analysis.js +123 -0
  58. package/dist/core/accounting/analysis.js.map +1 -0
  59. package/dist/core/accounting/charges.d.ts +136 -0
  60. package/dist/core/accounting/charges.d.ts.map +1 -0
  61. package/dist/core/accounting/charges.js +362 -0
  62. package/dist/core/accounting/charges.js.map +1 -0
  63. package/dist/core/accounting/equity.d.ts +191 -0
  64. package/dist/core/accounting/equity.d.ts.map +1 -0
  65. package/dist/core/accounting/equity.js +167 -0
  66. package/dist/core/accounting/equity.js.map +1 -0
  67. package/dist/core/accounting/index.d.ts +46 -0
  68. package/dist/core/accounting/index.d.ts.map +1 -0
  69. package/dist/core/accounting/index.js +37 -0
  70. package/dist/core/accounting/index.js.map +1 -0
  71. package/dist/core/accounting/markers.d.ts +43 -0
  72. package/dist/core/accounting/markers.d.ts.map +1 -0
  73. package/dist/core/accounting/markers.js +64 -0
  74. package/dist/core/accounting/markers.js.map +1 -0
  75. package/dist/core/accounting/monthly.d.ts +52 -0
  76. package/dist/core/accounting/monthly.d.ts.map +1 -0
  77. package/dist/core/accounting/monthly.js +99 -0
  78. package/dist/core/accounting/monthly.js.map +1 -0
  79. package/dist/core/accounting/report.d.ts +41 -0
  80. package/dist/core/accounting/report.d.ts.map +1 -0
  81. package/dist/core/accounting/report.js +65 -0
  82. package/dist/core/accounting/report.js.map +1 -0
  83. package/dist/core/accounting/shapes.d.ts +70 -0
  84. package/dist/core/accounting/shapes.d.ts.map +1 -0
  85. package/dist/core/accounting/shapes.js +21 -0
  86. package/dist/core/accounting/shapes.js.map +1 -0
  87. package/dist/core/accounting/statistics.d.ts +87 -0
  88. package/dist/core/accounting/statistics.d.ts.map +1 -0
  89. package/dist/core/accounting/statistics.js +268 -0
  90. package/dist/core/accounting/statistics.js.map +1 -0
  91. package/dist/core/accounting/trades.d.ts +118 -0
  92. package/dist/core/accounting/trades.d.ts.map +1 -0
  93. package/dist/core/accounting/trades.js +186 -0
  94. package/dist/core/accounting/trades.js.map +1 -0
  95. package/dist/core/backtest/case.d.ts +60 -0
  96. package/dist/core/backtest/case.d.ts.map +1 -0
  97. package/dist/core/backtest/case.js +319 -0
  98. package/dist/core/backtest/case.js.map +1 -0
  99. package/dist/core/backtest/compare.d.ts +38 -0
  100. package/dist/core/backtest/compare.d.ts.map +1 -0
  101. package/dist/core/backtest/compare.js +191 -0
  102. package/dist/core/backtest/compare.js.map +1 -0
  103. package/dist/core/backtest/declaration.d.ts +52 -0
  104. package/dist/core/backtest/declaration.d.ts.map +1 -0
  105. package/dist/core/backtest/declaration.js +48 -0
  106. package/dist/core/backtest/declaration.js.map +1 -0
  107. package/dist/core/backtest/deliver.d.ts +93 -0
  108. package/dist/core/backtest/deliver.d.ts.map +1 -0
  109. package/dist/core/backtest/deliver.js +94 -0
  110. package/dist/core/backtest/deliver.js.map +1 -0
  111. package/dist/core/backtest/drive.d.ts +87 -0
  112. package/dist/core/backtest/drive.d.ts.map +1 -0
  113. package/dist/core/backtest/drive.js +312 -0
  114. package/dist/core/backtest/drive.js.map +1 -0
  115. package/dist/core/backtest/index.d.ts +58 -0
  116. package/dist/core/backtest/index.d.ts.map +1 -0
  117. package/dist/core/backtest/index.js +47 -0
  118. package/dist/core/backtest/index.js.map +1 -0
  119. package/dist/core/backtest/range.d.ts +84 -0
  120. package/dist/core/backtest/range.d.ts.map +1 -0
  121. package/dist/core/backtest/range.js +90 -0
  122. package/dist/core/backtest/range.js.map +1 -0
  123. package/dist/core/backtest/record.d.ts +299 -0
  124. package/dist/core/backtest/record.d.ts.map +1 -0
  125. package/dist/core/backtest/record.js +243 -0
  126. package/dist/core/backtest/record.js.map +1 -0
  127. package/dist/core/backtest/replay.d.ts +48 -0
  128. package/dist/core/backtest/replay.d.ts.map +1 -0
  129. package/dist/core/backtest/replay.js +137 -0
  130. package/dist/core/backtest/replay.js.map +1 -0
  131. package/dist/core/backtest/resting.d.ts +62 -0
  132. package/dist/core/backtest/resting.d.ts.map +1 -0
  133. package/dist/core/backtest/resting.js +59 -0
  134. package/dist/core/backtest/resting.js.map +1 -0
  135. package/dist/core/backtest/settings.d.ts +117 -0
  136. package/dist/core/backtest/settings.d.ts.map +1 -0
  137. package/dist/core/backtest/settings.js +207 -0
  138. package/dist/core/backtest/settings.js.map +1 -0
  139. package/dist/core/backtest/simulate.d.ts +258 -0
  140. package/dist/core/backtest/simulate.d.ts.map +1 -0
  141. package/dist/core/backtest/simulate.js +335 -0
  142. package/dist/core/backtest/simulate.js.map +1 -0
  143. package/dist/core/catalogue/catalogue.generated.d.ts +66 -0
  144. package/dist/core/catalogue/catalogue.generated.d.ts.map +1 -1
  145. package/dist/core/catalogue/catalogue.generated.js +6 -0
  146. package/dist/core/catalogue/catalogue.generated.js.map +1 -1
  147. package/dist/core/catalogue/values.generated.d.ts +24 -0
  148. package/dist/core/catalogue/values.generated.d.ts.map +1 -1
  149. package/dist/core/check/index.d.ts +2 -1
  150. package/dist/core/check/index.d.ts.map +1 -1
  151. package/dist/core/check/index.js +1 -1
  152. package/dist/core/check/index.js.map +1 -1
  153. package/dist/core/check/library-orders.js +2 -2
  154. package/dist/core/check/library-orders.js.map +1 -1
  155. package/dist/core/check/library-prose.generated.d.ts +16 -0
  156. package/dist/core/check/library-prose.generated.d.ts.map +1 -0
  157. package/dist/core/check/library-prose.generated.js +353 -0
  158. package/dist/core/check/library-prose.generated.js.map +1 -0
  159. package/dist/core/check/surface.d.ts +24 -0
  160. package/dist/core/check/surface.d.ts.map +1 -1
  161. package/dist/core/check/surface.js +29 -0
  162. package/dist/core/check/surface.js.map +1 -1
  163. package/dist/core/emit/canonical.d.ts +22 -8
  164. package/dist/core/emit/canonical.d.ts.map +1 -1
  165. package/dist/core/emit/canonical.js +67 -6
  166. package/dist/core/emit/canonical.js.map +1 -1
  167. package/dist/core/emit/defaults.d.ts +35 -16
  168. package/dist/core/emit/defaults.d.ts.map +1 -1
  169. package/dist/core/emit/defaults.js +66 -0
  170. package/dist/core/emit/defaults.js.map +1 -1
  171. package/dist/core/emit/index.d.ts +2 -0
  172. package/dist/core/emit/index.d.ts.map +1 -1
  173. package/dist/core/emit/index.js +2 -0
  174. package/dist/core/emit/index.js.map +1 -1
  175. package/dist/core/engine/arithmetic.d.ts +6 -25
  176. package/dist/core/engine/arithmetic.d.ts.map +1 -1
  177. package/dist/core/engine/arithmetic.js +48 -3
  178. package/dist/core/engine/arithmetic.js.map +1 -1
  179. package/dist/core/engine/index.d.ts +2 -2
  180. package/dist/core/engine/index.d.ts.map +1 -1
  181. package/dist/core/engine/index.js +2 -2
  182. package/dist/core/engine/index.js.map +1 -1
  183. package/dist/core/engine/library/arrays.d.ts.map +1 -1
  184. package/dist/core/engine/library/arrays.js +8 -2
  185. package/dist/core/engine/library/arrays.js.map +1 -1
  186. package/dist/core/engine/library/code-points.d.ts +40 -0
  187. package/dist/core/engine/library/code-points.d.ts.map +1 -0
  188. package/dist/core/engine/library/code-points.js +74 -0
  189. package/dist/core/engine/library/code-points.js.map +1 -0
  190. package/dist/core/engine/library/index.d.ts +5 -0
  191. package/dist/core/engine/library/index.d.ts.map +1 -1
  192. package/dist/core/engine/library/index.js +5 -0
  193. package/dist/core/engine/library/index.js.map +1 -1
  194. package/dist/core/engine/library/text.d.ts.map +1 -1
  195. package/dist/core/engine/library/text.js +51 -34
  196. package/dist/core/engine/library/text.js.map +1 -1
  197. package/dist/core/engine/load.d.ts +35 -1
  198. package/dist/core/engine/load.d.ts.map +1 -1
  199. package/dist/core/engine/load.js +63 -0
  200. package/dist/core/engine/load.js.map +1 -1
  201. package/dist/core/engine/verify-tables.d.ts.map +1 -1
  202. package/dist/core/engine/verify-tables.js +41 -0
  203. package/dist/core/engine/verify-tables.js.map +1 -1
  204. package/dist/core/index.d.ts +43 -4
  205. package/dist/core/index.d.ts.map +1 -1
  206. package/dist/core/index.js +23 -2
  207. package/dist/core/index.js.map +1 -1
  208. package/dist/core/stdlib/index.d.ts +1 -1
  209. package/dist/core/stdlib/index.d.ts.map +1 -1
  210. package/dist/core/stdlib/index.js +1 -1
  211. package/dist/core/stdlib/index.js.map +1 -1
  212. package/dist/core/stdlib/maths/index.d.ts +1 -1
  213. package/dist/core/stdlib/maths/index.d.ts.map +1 -1
  214. package/dist/core/stdlib/maths/index.js +1 -1
  215. package/dist/core/stdlib/maths/index.js.map +1 -1
  216. package/dist/core/stdlib/maths/rounding.d.ts +5 -0
  217. package/dist/core/stdlib/maths/rounding.d.ts.map +1 -1
  218. package/dist/core/stdlib/maths/rounding.js +19 -1
  219. package/dist/core/stdlib/maths/rounding.js.map +1 -1
  220. package/dist/core/version/version.generated.d.ts +1 -1
  221. package/dist/core/version/version.generated.js +1 -1
  222. package/dist/editor/complete.d.ts +40 -0
  223. package/dist/editor/complete.d.ts.map +1 -0
  224. package/dist/editor/complete.js +206 -0
  225. package/dist/editor/complete.js.map +1 -0
  226. package/dist/editor/diagnose.d.ts +18 -0
  227. package/dist/editor/diagnose.d.ts.map +1 -0
  228. package/dist/editor/diagnose.js +70 -0
  229. package/dist/editor/diagnose.js.map +1 -0
  230. package/dist/editor/format.d.ts +11 -0
  231. package/dist/editor/format.d.ts.map +1 -0
  232. package/dist/editor/format.js +50 -0
  233. package/dist/editor/format.js.map +1 -0
  234. package/dist/editor/highlight.d.ts +28 -0
  235. package/dist/editor/highlight.d.ts.map +1 -0
  236. package/dist/editor/highlight.js +65 -0
  237. package/dist/editor/highlight.js.map +1 -0
  238. package/dist/editor/hover.d.ts +40 -0
  239. package/dist/editor/hover.d.ts.map +1 -0
  240. package/dist/editor/hover.js +147 -0
  241. package/dist/editor/hover.js.map +1 -0
  242. package/dist/editor/index.d.ts +60 -0
  243. package/dist/editor/index.d.ts.map +1 -0
  244. package/dist/editor/index.js +7 -0
  245. package/dist/editor/index.js.map +1 -0
  246. package/dist/editor/kinds.d.ts +27 -0
  247. package/dist/editor/kinds.d.ts.map +1 -0
  248. package/dist/editor/kinds.js +118 -0
  249. package/dist/editor/kinds.js.map +1 -0
  250. package/dist/editor/layout.d.ts +47 -0
  251. package/dist/editor/layout.d.ts.map +1 -0
  252. package/dist/editor/layout.js +135 -0
  253. package/dist/editor/layout.js.map +1 -0
  254. package/dist/editor/manifest.d.ts +47 -0
  255. package/dist/editor/manifest.d.ts.map +1 -0
  256. package/dist/editor/manifest.js +93 -0
  257. package/dist/editor/manifest.js.map +1 -0
  258. package/dist/editor/reading.d.ts +41 -0
  259. package/dist/editor/reading.d.ts.map +1 -0
  260. package/dist/editor/reading.js +51 -0
  261. package/dist/editor/reading.js.map +1 -0
  262. package/dist/editor/scan.d.ts +26 -0
  263. package/dist/editor/scan.d.ts.map +1 -0
  264. package/dist/editor/scan.js +139 -0
  265. package/dist/editor/scan.js.map +1 -0
  266. package/dist/editor/scope.d.ts +19 -0
  267. package/dist/editor/scope.d.ts.map +1 -0
  268. package/dist/editor/scope.js +99 -0
  269. package/dist/editor/scope.js.map +1 -0
  270. package/dist/editor/signature.d.ts +38 -0
  271. package/dist/editor/signature.d.ts.map +1 -0
  272. package/dist/editor/signature.js +112 -0
  273. package/dist/editor/signature.js.map +1 -0
  274. package/dist/editor/site.d.ts +46 -0
  275. package/dist/editor/site.d.ts.map +1 -0
  276. package/dist/editor/site.js +184 -0
  277. package/dist/editor/site.js.map +1 -0
  278. package/dist/editor/spacing.d.ts +29 -0
  279. package/dist/editor/spacing.d.ts.map +1 -0
  280. package/dist/editor/spacing.js +116 -0
  281. package/dist/editor/spacing.js.map +1 -0
  282. package/package.json +42 -3
  283. package/spec/README.md +2 -1
  284. package/spec/errors.json +141 -1
  285. package/src/adapters/charts/driving.ts +109 -0
  286. package/src/adapters/charts/run.ts +120 -28
  287. package/src/adapters/charts/surfaces.ts +17 -0
  288. package/src/adapters/charts/tables.ts +88 -0
  289. package/src/adapters/charts/venue.ts +132 -0
  290. package/src/adapters/codemirror/commands.ts +53 -0
  291. package/src/adapters/codemirror/completion.ts +74 -0
  292. package/src/adapters/codemirror/contract.ts +156 -0
  293. package/src/adapters/codemirror/index.ts +66 -0
  294. package/src/adapters/codemirror/lint.ts +66 -0
  295. package/src/adapters/codemirror/positions.ts +79 -0
  296. package/src/adapters/codemirror/stream.ts +87 -0
  297. package/src/adapters/codemirror/tokens.ts +64 -0
  298. package/src/adapters/codemirror/tooltips.ts +113 -0
  299. package/src/core/accounting/analysis.ts +188 -0
  300. package/src/core/accounting/charges.ts +452 -0
  301. package/src/core/accounting/equity.ts +314 -0
  302. package/src/core/accounting/index.ts +51 -0
  303. package/src/core/accounting/markers.ts +95 -0
  304. package/src/core/accounting/monthly.ts +137 -0
  305. package/src/core/accounting/report.ts +94 -0
  306. package/src/core/accounting/shapes.ts +73 -0
  307. package/src/core/accounting/statistics.ts +387 -0
  308. package/src/core/accounting/trades.ts +313 -0
  309. package/src/core/backtest/case.ts +395 -0
  310. package/src/core/backtest/compare.ts +246 -0
  311. package/src/core/backtest/declaration.ts +97 -0
  312. package/src/core/backtest/deliver.ts +161 -0
  313. package/src/core/backtest/drive.ts +468 -0
  314. package/src/core/backtest/index.ts +64 -0
  315. package/src/core/backtest/range.ts +137 -0
  316. package/src/core/backtest/record.ts +470 -0
  317. package/src/core/backtest/replay.ts +168 -0
  318. package/src/core/backtest/resting.ts +125 -0
  319. package/src/core/backtest/settings.ts +280 -0
  320. package/src/core/backtest/simulate.ts +499 -0
  321. package/src/core/catalogue/catalogue.generated.ts +6 -0
  322. package/src/core/catalogue/values.generated.ts +6 -0
  323. package/src/core/check/index.ts +3 -0
  324. package/src/core/check/library-orders.ts +2 -2
  325. package/src/core/check/library-prose.generated.ts +367 -0
  326. package/src/core/check/surface.ts +34 -0
  327. package/src/core/emit/canonical.ts +67 -9
  328. package/src/core/emit/defaults.ts +70 -0
  329. package/src/core/emit/index.ts +2 -0
  330. package/src/core/engine/arithmetic.ts +23 -3
  331. package/src/core/engine/index.ts +2 -2
  332. package/src/core/engine/library/arrays.ts +8 -2
  333. package/src/core/engine/library/code-points.ts +73 -0
  334. package/src/core/engine/library/index.ts +6 -0
  335. package/src/core/engine/library/text.ts +53 -35
  336. package/src/core/engine/load.ts +84 -2
  337. package/src/core/engine/verify-tables.ts +43 -0
  338. package/src/core/index.ts +100 -2
  339. package/src/core/stdlib/index.ts +1 -0
  340. package/src/core/stdlib/maths/index.ts +1 -0
  341. package/src/core/stdlib/maths/rounding.ts +23 -1
  342. package/src/core/version/version.generated.ts +1 -1
  343. package/src/editor/complete.ts +266 -0
  344. package/src/editor/diagnose.ts +71 -0
  345. package/src/editor/format.ts +85 -0
  346. package/src/editor/highlight.ts +110 -0
  347. package/src/editor/hover.ts +199 -0
  348. package/src/editor/index.ts +65 -0
  349. package/src/editor/kinds.ts +157 -0
  350. package/src/editor/layout.ts +189 -0
  351. package/src/editor/manifest.ts +119 -0
  352. package/src/editor/reading.ts +69 -0
  353. package/src/editor/scan.ts +162 -0
  354. package/src/editor/scope.ts +122 -0
  355. package/src/editor/signature.ts +150 -0
  356. package/src/editor/site.ts +233 -0
  357. package/src/editor/spacing.ts +132 -0
@@ -0,0 +1,93 @@
1
+ /**
2
+ * The standard library manifest, as the three functions that read it need it.
3
+ *
4
+ * `complete`, `hover` and `signature` all want the same things about a name:
5
+ * which signature the writer means, how to spell that signature, what each
6
+ * parameter defaults to, and the line the specification gives it. Every one of
7
+ * those is a question the compiler already answers, and the whole value of this
8
+ * file is that it asks rather than knows.
9
+ *
10
+ * which entries a name has the manifest index, `libraryEntries`
11
+ * what a parameter defaults the manifest, or the emitter for the eight
12
+ * declaration calls
13
+ * what the call is for `proseFor`, read out of `stdlib.md`'s own
14
+ * tables at build time, with the warmup its row
15
+ * states beside it
16
+ * what a type is called `typeText`, the checker's own spelling
17
+ *
18
+ * A list of function names typed into this repository would be right on the day
19
+ * it was typed and wrong at the next release, and a missing completion looks
20
+ * exactly like a completion that has not loaded yet, so nobody would report it.
21
+ *
22
+ * ## The default is the compiler's, including for the eight that hide it
23
+ *
24
+ * Most calls carry their default in the manifest, spelled as `stdlib.md` prints
25
+ * it. A `plot`, a `level`, a `table` and the five like them do not: their
26
+ * optional arguments become fields of a declaration rather than arguments an
27
+ * engine is passed, so their values live in the emitter
28
+ * (`compiled-program.md` 2.3). A tooltip built on the manifest alone would show
29
+ * a writer nothing beside `width?` while the compiler writes 1.5.
30
+ *
31
+ * So both are read, through `declarationDefaultText`, which is the same answer
32
+ * `scripts/check-defaults.mjs` holds to what the specification prints. A default
33
+ * shown here cannot differ from the one the compiler applies without failing the
34
+ * build, which is the only way a tooltip's number is worth anything.
35
+ */
36
+ import { DECLARATION_CALLS, declarationDefaultText, libraryEntries, typeText, } from '../core/index.js';
37
+ /** Every parameter of one signature, with the defaults from both homes. */
38
+ export function parametersOf(entry) {
39
+ const declared = DECLARATION_CALLS.has(entry.name);
40
+ return entry.parameters.map((one) => ({
41
+ name: one.name,
42
+ type: typeText(one.type),
43
+ required: !one.optional,
44
+ defaultText: declared
45
+ ? declarationDefaultText(entry.name, one.name)
46
+ : one.defaultText,
47
+ values: entry.values[one.name] ?? [],
48
+ }));
49
+ }
50
+ /**
51
+ * One signature, written out the way the specification's tables write one.
52
+ *
53
+ * `ema(src: series number, len: number) -> series number`. The parameter names,
54
+ * the types and the defaults are the manifest's; nothing about the spelling is
55
+ * decided here except the punctuation between them.
56
+ */
57
+ export function signatureTextOf(entry) {
58
+ if (!entry.callable)
59
+ return `${entry.name}: ${typeText(entry.returns)}`;
60
+ const written = parametersOf(entry).map((one) => {
61
+ const head = `${one.name}${one.required ? '' : '?'}: ${one.type}`;
62
+ return one.defaultText === undefined ? head : `${head} = ${one.defaultText}`;
63
+ });
64
+ return `${entry.name}(${written.join(', ')}) -> ${typeText(entry.returns)}`;
65
+ }
66
+ /**
67
+ * The signature a half written call means, chosen by the rule that can be
68
+ * applied to a half written call.
69
+ *
70
+ * `stdlib.md` 2.2 resolves an overload by arity first and by argument type
71
+ * second, and the checker does exactly that. The second rule needs a type for
72
+ * every argument, which needs a tree, which a call that is still being typed has
73
+ * not got: `clear(` is two signatures until the argument arrives. So only the
74
+ * first rule is applied here, and where it leaves more than one candidate the
75
+ * first is taken, which is the order `stdlib.md` states them in.
76
+ *
77
+ * That is a narrowing of the checker's answer rather than a second opinion about
78
+ * it: the tooltip may show the array signature of `clear` while the writer meant
79
+ * the grid one, and the moment the argument is written the checker settles it
80
+ * and `diagnose` is what says so. It is recorded in `spec/editor-narrowings.json`.
81
+ */
82
+ export function entryAt(name, given) {
83
+ const entries = libraryEntries(name).filter((one) => one.callable);
84
+ const first = entries[0];
85
+ if (first === undefined || entries.length === 1)
86
+ return first;
87
+ const byArity = entries.filter((one) => {
88
+ const required = one.parameters.filter((parameter) => !parameter.optional).length;
89
+ return given >= required && given <= one.parameters.length;
90
+ });
91
+ return byArity[0] ?? first;
92
+ }
93
+ //# sourceMappingURL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AC,CAAC,GAAG,KAAK,GAAG,CAAC,IAAI,EAAE,CAAC;QAClE,OAAO,GAAG,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,MAAM,GAAG,CAAC,WAAW,EAAE,CAAC;IAC/E,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,KAAK,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;AAC9E,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,OAAO,CAAC,IAAY,EAAE,KAAa;IACjD,MAAM,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACnE,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACzB,IAAI,KAAK,KAAK,SAAS,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAE9D,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE;QACrC,MAAM,QAAQ,GAAG,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC;QAClF,OAAO,KAAK,IAAI,QAAQ,IAAI,KAAK,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC;IAC7D,CAAC,CAAC,CAAC;IACH,OAAO,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The first step of every function in this tier: text becomes a file, and the
3
+ * file becomes tokens.
4
+ *
5
+ * It is one place rather than four because all four begin identically and
6
+ * because one of them beginning differently is a bug nobody would look for.
7
+ *
8
+ * The bag is created and, for `highlight`, thrown away. That is not waste: the
9
+ * lexer reports rather than throws, so handing it somewhere to report is how it
10
+ * is told to carry on, and a highlighter has nothing to say about a character
11
+ * the language does not have. `diagnose` is what says it.
12
+ */
13
+ import { DiagnosticBag } from '../core/index.js';
14
+ import type { CheckedScript, Script, SourceFile, Token } from '../core/index.js';
15
+ export interface Read {
16
+ readonly file: SourceFile;
17
+ readonly bag: DiagnosticBag;
18
+ readonly tokens: readonly Token[];
19
+ }
20
+ export interface ReadTree extends Read {
21
+ readonly script: Script;
22
+ }
23
+ export interface ReadChecked extends ReadTree {
24
+ readonly checked: CheckedScript;
25
+ }
26
+ /** Text to a file and its tokens. */
27
+ export declare function read(source: string): Read;
28
+ /** The same, with the tree, for the functions that need one. */
29
+ export declare function readTree(source: string): ReadTree;
30
+ /**
31
+ * The same again, checked, for the two that ask what a name means.
32
+ *
33
+ * `complete` and `hover` both need the checker's answers: which names the file
34
+ * has declared, where each was declared, and what type each one holds. Nothing
35
+ * here is a lighter version of the checker. It is the checker, run on a file
36
+ * that is halfway through being typed, which it is built to survive: a name
37
+ * that does not resolve becomes `unknown` and the lines around it are still
38
+ * checked, so the names above the cursor are still names.
39
+ */
40
+ export declare function readChecked(source: string): ReadChecked;
41
+ //# sourceMappingURL=reading.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reading.d.ts","sourceRoot":"","sources":["../../src/editor/reading.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,aAAa,EAAuC,MAAM,kBAAkB,CAAC;AACtF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAejF,MAAM,WAAW,IAAI;IACnB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;CACnC;AAED,MAAM,WAAW,QAAS,SAAQ,IAAI;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,WAAY,SAAQ,QAAQ;IAC3C,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;CACjC;AAED,qCAAqC;AACrC,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAIzC;AAED,gEAAgE;AAChE,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAGjD;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAGvD"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * The first step of every function in this tier: text becomes a file, and the
3
+ * file becomes tokens.
4
+ *
5
+ * It is one place rather than four because all four begin identically and
6
+ * because one of them beginning differently is a bug nobody would look for.
7
+ *
8
+ * The bag is created and, for `highlight`, thrown away. That is not waste: the
9
+ * lexer reports rather than throws, so handing it somewhere to report is how it
10
+ * is told to carry on, and a highlighter has nothing to say about a character
11
+ * the language does not have. `diagnose` is what says it.
12
+ */
13
+ import { DiagnosticBag, check, lex, parseTokens, sourceFile } from '../core/index.js';
14
+ /**
15
+ * The name the file is read under, and why none of these functions takes one.
16
+ *
17
+ * A `SourceFile` carries a name, and the renderer in the core puts it on the
18
+ * first line of a rendered diagnostic. Nothing this tier returns carries it: a
19
+ * diagnostic holds a span, and a highlighted piece holds a span, and neither
20
+ * holds a file. So a name parameter here would be a parameter a caller can only
21
+ * get wrong, with nothing anywhere able to notice that they had. A host that
22
+ * renders a diagnostic with its own file name on it builds the `SourceFile`
23
+ * itself, from the core, which is where the renderer lives.
24
+ */
25
+ const UNNAMED = 'script.oscript';
26
+ /** Text to a file and its tokens. */
27
+ export function read(source) {
28
+ const file = sourceFile(UNNAMED, source);
29
+ const bag = new DiagnosticBag();
30
+ return { file, bag, tokens: lex(file, bag) };
31
+ }
32
+ /** The same, with the tree, for the functions that need one. */
33
+ export function readTree(source) {
34
+ const held = read(source);
35
+ return { ...held, script: parseTokens(held.file, held.tokens, held.bag) };
36
+ }
37
+ /**
38
+ * The same again, checked, for the two that ask what a name means.
39
+ *
40
+ * `complete` and `hover` both need the checker's answers: which names the file
41
+ * has declared, where each was declared, and what type each one holds. Nothing
42
+ * here is a lighter version of the checker. It is the checker, run on a file
43
+ * that is halfway through being typed, which it is built to survive: a name
44
+ * that does not resolve becomes `unknown` and the lines around it are still
45
+ * checked, so the names above the cursor are still names.
46
+ */
47
+ export function readChecked(source) {
48
+ const held = readTree(source);
49
+ return { ...held, checked: check(held.file, held.script, held.bag) };
50
+ }
51
+ //# sourceMappingURL=reading.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reading.js","sourceRoot":"","sources":["../../src/editor/reading.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGtF;;;;;;;;;;GAUG;AACH,MAAM,OAAO,GAAG,gBAAgB,CAAC;AAgBjC,qCAAqC;AACrC,MAAM,UAAU,IAAI,CAAC,MAAc;IACjC,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACzC,MAAM,GAAG,GAAG,IAAI,aAAa,EAAE,CAAC;IAChC,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;AAC/C,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,QAAQ,CAAC,MAAc;IACrC,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1B,OAAO,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AAC5E,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,WAAW,CAAC,MAAc;IACxC,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AACvE,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { SourceFile, Span, Token } from '../core/index.js';
2
+ import type { HighlightKind } from './kinds.js';
3
+ /** One piece of the file, with what it is and the text it covers. */
4
+ export interface Highlight {
5
+ readonly kind: HighlightKind;
6
+ readonly span: Span;
7
+ /**
8
+ * The source the span covers, carried rather than left to the caller to slice.
9
+ *
10
+ * A host that concatenates these gets the file back, so a renderer never
11
+ * indexes the buffer and never has to agree with this module about what an
12
+ * offset means. It is also what makes the covering property a one-line test.
13
+ */
14
+ readonly text: string;
15
+ }
16
+ /**
17
+ * Every piece of a file, in order, covering it exactly.
18
+ *
19
+ * The token list is walked rather than sorted, and a token that would overlap
20
+ * the piece before it is skipped rather than believed. Both of those are
21
+ * defences rather than expectations: the property this returns is what a host
22
+ * draws with, and it has to hold for a stream from a file somebody is halfway
23
+ * through typing as firmly as for one from a script that compiles.
24
+ */
25
+ export declare function scan(file: SourceFile, tokens: readonly Token[]): readonly Highlight[];
26
+ //# sourceMappingURL=scan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../src/editor/scan.ts"],"names":[],"mappings":"AA4CA,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEhE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,qEAAqE;AACrE,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAiDD;;;;;;;;GAQG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,KAAK,EAAE,GAAG,SAAS,SAAS,EAAE,CA2CrF"}
@@ -0,0 +1,139 @@
1
+ /**
2
+ * The covering scan: every character of a file, exactly once, with what it is.
3
+ *
4
+ * ## The property that decides the shape
5
+ *
6
+ * A host draws highlighting behind or over a text component, and it draws it by
7
+ * walking a list. Drop one character anywhere on a line and everything after it
8
+ * on that line is drawn one column to the left, so the caret stops sitting where
9
+ * the text is. That is not a cosmetic bug: it is the editor feeling broken, and
10
+ * it is reported as "the cursor is in the wrong place" rather than as a
11
+ * highlighting fault, which is why it survives.
12
+ *
13
+ * So the guarantee here is not "here are the tokens". It is **the spans tile the
14
+ * source**: they are in order, they do not overlap, none is empty, and their
15
+ * texts concatenate to the file exactly. A host that renders the spans and
16
+ * nothing else cannot lose a character, because there is nowhere for one to go.
17
+ * `tests/editor/highlight.test.ts` holds that over every script in the
18
+ * repository and over a corpus of malformed ones.
19
+ *
20
+ * ## Where the comments come from
21
+ *
22
+ * The lexer emits no token for a comment, because the parser has no use for one
23
+ * (`language.md` 3.10, and it is the rule that lets a commented-out statement
24
+ * sit at column zero inside a block without closing it). A highlighter does have
25
+ * a use for one, so they have to be recovered, and this is the one place in the
26
+ * project that does it. Leaving it to each host is what produced the two
27
+ * problems this file exists to remove: a platform recovering comments from the
28
+ * gaps between token spans, and doing it with its own scan for `//`.
29
+ *
30
+ * A scan of its own is the wrong answer, because a `//` inside a string literal
31
+ * is ordinary text (3.2) and finding that out means lexing strings a second
32
+ * time. This does not scan the file. It walks the tokens the real lexer
33
+ * produced, and only looks at what is left between them, which by construction
34
+ * holds no string literal: a `//` in a gap is always a comment, with no second
35
+ * opinion about the language anywhere in it.
36
+ *
37
+ * What else can be in a gap is small and worth naming, because a reader of this
38
+ * file will want to know whether it can be surprised: blanks, a line continuation
39
+ * backslash, a region somebody meant as a block comment, and the characters the
40
+ * lexer refused and reported. All of those are `unknown`, which means "the lexer
41
+ * took no token from this", and `diagnose` is what says whether any of it is a
42
+ * mistake.
43
+ */
44
+ import { endOffset } from '../core/index.js';
45
+ import { kindOf } from './kinds.js';
46
+ const SLASH = 47;
47
+ const LINE_FEED = 10;
48
+ /** Whether a comment opens at `at`: two slashes, which run to the end of the line. */
49
+ function opensComment(text, at) {
50
+ return text.charCodeAt(at) === SLASH && text.charCodeAt(at + 1) === SLASH;
51
+ }
52
+ function isBlank(code) {
53
+ // The three the lexer passes over between tokens. A tab is OS1002 in leading
54
+ // whitespace and is still whitespace to look at, so it is painted as such and
55
+ // the compiler is left to be the one that objects to it. A lone carriage
56
+ // return is not one of these: `language.md` 3.1 does not accept it, the lexer
57
+ // reports it, and painting it as a space would hide the one thing about it
58
+ // worth knowing.
59
+ return code === 32 || code === 9 || code === LINE_FEED;
60
+ }
61
+ /** The end of the line `at` sits on, or the end of the file. */
62
+ function endOfLine(text, at) {
63
+ const found = text.indexOf('\n', at);
64
+ return found === -1 ? text.length : found;
65
+ }
66
+ /**
67
+ * A run of one kind inside a gap, from `from` up to but not including its end.
68
+ *
69
+ * The three cases are tried in the order they can be told apart: a blank is a
70
+ * blank, two slashes open a comment to the end of the line, and anything else
71
+ * runs until one of those two begins.
72
+ */
73
+ function runIn(text, from, to) {
74
+ if (isBlank(text.charCodeAt(from))) {
75
+ let i = from;
76
+ while (i < to && isBlank(text.charCodeAt(i)))
77
+ i += 1;
78
+ return { end: i, kind: 'whitespace' };
79
+ }
80
+ if (opensComment(text, from)) {
81
+ return { end: Math.min(endOfLine(text, from), to), kind: 'comment' };
82
+ }
83
+ let i = from;
84
+ while (i < to && !isBlank(text.charCodeAt(i)) && !opensComment(text, i))
85
+ i += 1;
86
+ return { end: i, kind: 'unknown' };
87
+ }
88
+ /**
89
+ * Every piece of a file, in order, covering it exactly.
90
+ *
91
+ * The token list is walked rather than sorted, and a token that would overlap
92
+ * the piece before it is skipped rather than believed. Both of those are
93
+ * defences rather than expectations: the property this returns is what a host
94
+ * draws with, and it has to hold for a stream from a file somebody is halfway
95
+ * through typing as firmly as for one from a script that compiles.
96
+ */
97
+ export function scan(file, tokens) {
98
+ const text = file.text;
99
+ const out = [];
100
+ let at = 0;
101
+ const fill = (to) => {
102
+ let from = at;
103
+ while (from < to) {
104
+ const run = runIn(text, from, to);
105
+ out.push({
106
+ kind: run.kind,
107
+ span: file.spanAt(from, run.end - from),
108
+ text: text.slice(from, run.end),
109
+ });
110
+ from = run.end;
111
+ }
112
+ };
113
+ const read = [];
114
+ for (const token of tokens) {
115
+ if (token.span.length === 0) {
116
+ // A dedent and the end of the file are positions rather than text, and a
117
+ // newline at the end of a file is one too. Nothing to paint, but the
118
+ // token still counts as read for the dotted name question next door.
119
+ read.push(token);
120
+ continue;
121
+ }
122
+ if (token.span.offset < at)
123
+ continue;
124
+ if (token.span.offset > at) {
125
+ fill(token.span.offset);
126
+ at = token.span.offset;
127
+ }
128
+ out.push({
129
+ kind: kindOf(token, read),
130
+ span: token.span,
131
+ text: text.slice(token.span.offset, endOffset(token.span)),
132
+ });
133
+ at = endOffset(token.span);
134
+ read.push(token);
135
+ }
136
+ fill(text.length);
137
+ return out;
138
+ }
139
+ //# sourceMappingURL=scan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scan.js","sourceRoot":"","sources":["../../src/editor/scan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAiBpC,MAAM,KAAK,GAAG,EAAE,CAAC;AACjB,MAAM,SAAS,GAAG,EAAE,CAAC;AAErB,sFAAsF;AACtF,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ACrE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACjB,SAAS;QACX,CAAC;QACD,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,EAAE;YAAE,SAAS;QACrC,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;YAC3B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACxB,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;QACzB,CAAC;QACD,GAAG,CAAC,IAAI,CAAC;YACP,IAAI,EAAE,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC;YACzB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;SAC3D,CAAC,CAAC;QACH,EAAE,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAClB,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { Binding, CheckedScript } from '../core/index.js';
2
+ /**
3
+ * Every name the file itself declares that may be written at an offset.
4
+ *
5
+ * A library name is not here: the manifest answers for those, and a binding of
6
+ * kind `library` is the checker's record of the global scope rather than
7
+ * something the file declared.
8
+ */
9
+ export declare function inScopeAt(script: CheckedScript, offset: number): readonly Binding[];
10
+ /**
11
+ * The binding a name means at an offset, or nothing where the file declares none.
12
+ *
13
+ * The declaration itself counts, which the scope rule above deliberately does
14
+ * not: a name is not in scope inside its own right hand side, and pointing at it
15
+ * on the line that declares it is still pointing at it. Without this, a hover
16
+ * over the `x` in `x = ema(close, 9)` would say nothing at all.
17
+ */
18
+ export declare function bindingNamed(script: CheckedScript, name: string, offset: number): Binding | undefined;
19
+ //# sourceMappingURL=scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../../src/editor/scope.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAW,OAAO,EAAE,aAAa,EAAY,MAAM,kBAAkB,CAAC;AAuDlF;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,OAAO,EAAE,CASnF;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACb,OAAO,GAAG,SAAS,CAWrB"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Which of the file's own names may be written at a position.
3
+ *
4
+ * A completion list that offered every name in the file would offer a loop
5
+ * variable three blocks away and a function parameter from another function,
6
+ * and a writer accepting one of those gets OS2001 from the compiler a moment
7
+ * later. So the two rules the language states are applied, and both are asked of
8
+ * the compiler's own answers rather than worked out again here.
9
+ *
10
+ * declared above OS2001 is "not defined at this point in the file", so a
11
+ * name is offered from the end of the statement that
12
+ * declares it. Not from the end of the name: `x` is not
13
+ * yet a name inside `x = ema(x, 9)`, and `f` is not one
14
+ * inside `f`'s own body, because recursion is OS2005
15
+ * and still inside a name belongs to the block that declared it
16
+ * (`language.md` 12), so it is offered inside that block
17
+ * and nowhere else
18
+ *
19
+ * The bindings are the checker's, not a second walk of the tree: `declaredAt` is
20
+ * the span the checker points OS2002 and OS8010 at, and the kind, the type and
21
+ * the persistence are what it worked out. What is derived here is one thing, the
22
+ * region a binding belongs to, and it is derived from the tree the parser
23
+ * produced by asking which nodes enclose the declaration.
24
+ */
25
+ import { containsOffset, endOffset, isStatement, pathAtOffset } from '../core/index.js';
26
+ /**
27
+ * The node kinds that hold a scope of their own.
28
+ *
29
+ * A block is the obvious one. A function declaration is here because its
30
+ * parameters are declared in its header rather than in its body, and a loop
31
+ * because its variable is declared in the header too. Anything else a name is
32
+ * declared inside belongs to whichever of these encloses it, and a file level
33
+ * name belongs to the file.
34
+ */
35
+ const SCOPES = new Set([
36
+ 'block',
37
+ 'functionDeclaration',
38
+ 'forRangeStatement',
39
+ 'forInStatement',
40
+ ]);
41
+ const HEADERS = new Set(['parameter', 'loop']);
42
+ function regionOf(script, binding) {
43
+ const path = pathAtOffset(script.script, binding.declaredAt.offset);
44
+ let node;
45
+ let statement;
46
+ for (let i = path.length - 1; i >= 0; i -= 1) {
47
+ const held = path[i];
48
+ if (held === undefined)
49
+ continue;
50
+ if (statement === undefined && isStatement(held))
51
+ statement = held;
52
+ if (SCOPES.has(held.kind)) {
53
+ node = held;
54
+ break;
55
+ }
56
+ }
57
+ const from = HEADERS.has(binding.kind)
58
+ ? endOffset(binding.declaredAt)
59
+ : endOffset(statement?.span ?? binding.declaredAt);
60
+ return { node, from };
61
+ }
62
+ /**
63
+ * Every name the file itself declares that may be written at an offset.
64
+ *
65
+ * A library name is not here: the manifest answers for those, and a binding of
66
+ * kind `library` is the checker's record of the global scope rather than
67
+ * something the file declared.
68
+ */
69
+ export function inScopeAt(script, offset) {
70
+ return script.bindings.filter((binding) => {
71
+ if (binding.kind === 'library')
72
+ return false;
73
+ const region = regionOf(script, binding);
74
+ if (region.from > offset)
75
+ return false;
76
+ // No enclosing scope node means the file, and the file holds every offset,
77
+ // including the one past its last character where somebody is typing.
78
+ return region.node === undefined || containsOffset(region.node.span, offset);
79
+ });
80
+ }
81
+ /**
82
+ * The binding a name means at an offset, or nothing where the file declares none.
83
+ *
84
+ * The declaration itself counts, which the scope rule above deliberately does
85
+ * not: a name is not in scope inside its own right hand side, and pointing at it
86
+ * on the line that declares it is still pointing at it. Without this, a hover
87
+ * over the `x` in `x = ema(close, 9)` would say nothing at all.
88
+ */
89
+ export function bindingNamed(script, name, offset) {
90
+ const declaring = script.bindings.find((binding) => binding.name === name && containsOffset(binding.declaredAt, offset));
91
+ if (declaring !== undefined)
92
+ return declaring;
93
+ const held = inScopeAt(script, offset).filter((binding) => binding.name === name);
94
+ // The innermost declaration wins, which is the one declared last among those
95
+ // still in scope: a block level name shadows a file level one of the same
96
+ // spelling for as long as its block lasts.
97
+ return held[held.length - 1];
98
+ }
99
+ //# sourceMappingURL=scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.js","sourceRoot":"","sources":["../../src/editor/scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGxF;;;;;;;;GAQG;AACH,MAAM,MAAM,GAA0B,IAAI,GAAG,CAAW;IACtD,OAAO;IACP,qBAAqB;IACrB,mBAAmB;IACnB,gBAAgB;CACjB,CAAC,CAAC;AAgBH,MAAM,OAAO,GAAiC,IAAI,GAAG,CAAkB,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;AAE9F,SAAS,QAAQ,CAAC,MAAqB,EAAE,OAAgB;IACvD,MAAM,IAAI,GAAG,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IACpE,IAAI,IAAyB,CAAC;IAC9B,IAAI,SAA8B,CAAC;IAEnC,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACrB,IAAI,IAAI,KAAK,SAAS;YAAE,SAAS;QACjC,IAAI,SAAS,KAAK,SAAS,IAAI,WAAW,CAAC,IAAI,CAAC;YAAE,SAAS,GAAG,IAAI,CAAC;QACnE,IAAI,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,C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AAM,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IAClF,6EAA6E;IAC7E,0EAA0E;IAC1E,2CAA2C;IAC3C,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { Span } from '../core/index.js';
2
+ import type { Parameter } from './manifest.js';
3
+ export interface SignatureHelp {
4
+ /** The callee as written: `ema`, `draw.box`, or a name the file declared. */
5
+ readonly name: string;
6
+ /** Whether the library holds it or the file declares it. */
7
+ readonly of: 'library' | 'declared';
8
+ /** The signature written out, the way the specification's tables write one. */
9
+ readonly signature: string;
10
+ readonly parameters: readonly Parameter[];
11
+ /**
12
+ * Which parameter the cursor is in, or -1 where it is in none.
13
+ *
14
+ * A label decides it where one is written, because `plot(close, color = ` is
15
+ * in `color` whatever position it sits in; otherwise the count of commas
16
+ * decides. It is -1 past the last parameter, which is a call with more
17
+ * arguments than the signature takes and is OS3001 the moment it is compiled.
18
+ */
19
+ readonly active: number;
20
+ /** The line the specification gives the call, where it gives one. */
21
+ readonly summary: string | undefined;
22
+ /** Named in the library and not implemented in this version: OS2020. */
23
+ readonly planned: boolean;
24
+ readonly refusal: string | undefined;
25
+ /** The callee's own name, for a host anchoring a tooltip to the call. */
26
+ readonly span: Span;
27
+ }
28
+ /**
29
+ * The call the cursor is inside, or nothing where it is inside none.
30
+ *
31
+ * Nothing is the answer for a cursor outside every bracket, and for one inside a
32
+ * bracket whose callee the language does not have: a name that resolves to
33
+ * neither the library nor the file is OS2001, and `diagnose` is what says so.
34
+ * A tooltip that invented a signature for it would be a second opinion about
35
+ * what the file declares.
36
+ */
37
+ export declare function signature(source: string, offset: number): SignatureHelp | undefined;
38
+ //# sourceMappingURL=signature.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../../src/editor/signature.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAiB,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAK/C,MAAM,WAAW,aAAa;IAC5B,6EAA6E;IAC7E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,EAAE,SAAS,GAAG,UAAU,CAAC;IACpC,+EAA+E;IAC/E,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,CAAC;IAC1C;;;;;;;OAOG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,qEAAqE;IACrE,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,wEAAwE;IACxE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,yEAAyE;IACzE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;CACrB;AAyDD;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAsBnF"}