openalgo-script 0.1.0-alpha.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 (266) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +12 -0
  3. package/README.md +255 -0
  4. package/dist/core/ast/annotations.d.ts +56 -0
  5. package/dist/core/ast/annotations.d.ts.map +1 -0
  6. package/dist/core/ast/annotations.js +27 -0
  7. package/dist/core/ast/annotations.js.map +1 -0
  8. package/dist/core/ast/build.d.ts +25 -0
  9. package/dist/core/ast/build.d.ts.map +1 -0
  10. package/dist/core/ast/build.js +26 -0
  11. package/dist/core/ast/build.js.map +1 -0
  12. package/dist/core/ast/children.d.ts +15 -0
  13. package/dist/core/ast/children.d.ts.map +1 -0
  14. package/dist/core/ast/children.js +103 -0
  15. package/dist/core/ast/children.js.map +1 -0
  16. package/dist/core/ast/expressions.d.ts +178 -0
  17. package/dist/core/ast/expressions.d.ts.map +1 -0
  18. package/dist/core/ast/expressions.js +50 -0
  19. package/dist/core/ast/expressions.js.map +1 -0
  20. package/dist/core/ast/header.d.ts +50 -0
  21. package/dist/core/ast/header.d.ts.map +1 -0
  22. package/dist/core/ast/header.js +2 -0
  23. package/dist/core/ast/header.js.map +1 -0
  24. package/dist/core/ast/index.d.ts +30 -0
  25. package/dist/core/ast/index.d.ts.map +1 -0
  26. package/dist/core/ast/index.js +21 -0
  27. package/dist/core/ast/index.js.map +1 -0
  28. package/dist/core/ast/name.d.ts +24 -0
  29. package/dist/core/ast/name.d.ts.map +1 -0
  30. package/dist/core/ast/name.js +2 -0
  31. package/dist/core/ast/name.js.map +1 -0
  32. package/dist/core/ast/node.d.ts +34 -0
  33. package/dist/core/ast/node.d.ts.map +1 -0
  34. package/dist/core/ast/node.js +70 -0
  35. package/dist/core/ast/node.js.map +1 -0
  36. package/dist/core/ast/script.d.ts +57 -0
  37. package/dist/core/ast/script.d.ts.map +1 -0
  38. package/dist/core/ast/script.js +2 -0
  39. package/dist/core/ast/script.js.map +1 -0
  40. package/dist/core/ast/statements.d.ts +161 -0
  41. package/dist/core/ast/statements.d.ts.map +1 -0
  42. package/dist/core/ast/statements.js +10 -0
  43. package/dist/core/ast/statements.js.map +1 -0
  44. package/dist/core/ast/walk.d.ts +39 -0
  45. package/dist/core/ast/walk.d.ts.map +1 -0
  46. package/dist/core/ast/walk.js +54 -0
  47. package/dist/core/ast/walk.js.map +1 -0
  48. package/dist/core/catalogue/catalogue.generated.d.ts +1590 -0
  49. package/dist/core/catalogue/catalogue.generated.d.ts.map +1 -0
  50. package/dist/core/catalogue/catalogue.generated.js +162 -0
  51. package/dist/core/catalogue/catalogue.generated.js.map +1 -0
  52. package/dist/core/catalogue/index.d.ts +15 -0
  53. package/dist/core/catalogue/index.d.ts.map +1 -0
  54. package/dist/core/catalogue/index.js +4 -0
  55. package/dist/core/catalogue/index.js.map +1 -0
  56. package/dist/core/catalogue/lookup.d.ts +14 -0
  57. package/dist/core/catalogue/lookup.d.ts.map +1 -0
  58. package/dist/core/catalogue/lookup.js +19 -0
  59. package/dist/core/catalogue/lookup.js.map +1 -0
  60. package/dist/core/catalogue/template.d.ts +15 -0
  61. package/dist/core/catalogue/template.d.ts.map +1 -0
  62. package/dist/core/catalogue/template.js +33 -0
  63. package/dist/core/catalogue/template.js.map +1 -0
  64. package/dist/core/catalogue/types.d.ts +34 -0
  65. package/dist/core/catalogue/types.d.ts.map +1 -0
  66. package/dist/core/catalogue/types.js +6 -0
  67. package/dist/core/catalogue/types.js.map +1 -0
  68. package/dist/core/catalogue/values.generated.d.ts +565 -0
  69. package/dist/core/catalogue/values.generated.d.ts.map +1 -0
  70. package/dist/core/catalogue/values.generated.js +6 -0
  71. package/dist/core/catalogue/values.generated.js.map +1 -0
  72. package/dist/core/diagnostics/collector.d.ts +46 -0
  73. package/dist/core/diagnostics/collector.d.ts.map +1 -0
  74. package/dist/core/diagnostics/collector.js +55 -0
  75. package/dist/core/diagnostics/collector.js.map +1 -0
  76. package/dist/core/diagnostics/diagnostic.d.ts +40 -0
  77. package/dist/core/diagnostics/diagnostic.d.ts.map +1 -0
  78. package/dist/core/diagnostics/diagnostic.js +29 -0
  79. package/dist/core/diagnostics/diagnostic.js.map +1 -0
  80. package/dist/core/diagnostics/index.d.ts +12 -0
  81. package/dist/core/diagnostics/index.d.ts.map +1 -0
  82. package/dist/core/diagnostics/index.js +3 -0
  83. package/dist/core/diagnostics/index.js.map +1 -0
  84. package/dist/core/index.d.ts +28 -0
  85. package/dist/core/index.d.ts.map +1 -0
  86. package/dist/core/index.js +22 -0
  87. package/dist/core/index.js.map +1 -0
  88. package/dist/core/lex/blocks.d.ts +51 -0
  89. package/dist/core/lex/blocks.d.ts.map +1 -0
  90. package/dist/core/lex/blocks.js +56 -0
  91. package/dist/core/lex/blocks.js.map +1 -0
  92. package/dist/core/lex/characters.d.ts +38 -0
  93. package/dist/core/lex/characters.d.ts.map +1 -0
  94. package/dist/core/lex/characters.js +50 -0
  95. package/dist/core/lex/characters.js.map +1 -0
  96. package/dist/core/lex/comments.d.ts +50 -0
  97. package/dist/core/lex/comments.d.ts.map +1 -0
  98. package/dist/core/lex/comments.js +64 -0
  99. package/dist/core/lex/comments.js.map +1 -0
  100. package/dist/core/lex/index.d.ts +12 -0
  101. package/dist/core/lex/index.d.ts.map +1 -0
  102. package/dist/core/lex/index.js +12 -0
  103. package/dist/core/lex/index.js.map +1 -0
  104. package/dist/core/lex/layout.d.ts +40 -0
  105. package/dist/core/lex/layout.d.ts.map +1 -0
  106. package/dist/core/lex/layout.js +143 -0
  107. package/dist/core/lex/layout.js.map +1 -0
  108. package/dist/core/lex/lexer.d.ts +13 -0
  109. package/dist/core/lex/lexer.d.ts.map +1 -0
  110. package/dist/core/lex/lexer.js +419 -0
  111. package/dist/core/lex/lexer.js.map +1 -0
  112. package/dist/core/lex/numbers.d.ts +22 -0
  113. package/dist/core/lex/numbers.d.ts.map +1 -0
  114. package/dist/core/lex/numbers.js +58 -0
  115. package/dist/core/lex/numbers.js.map +1 -0
  116. package/dist/core/lex/statements.d.ts +24 -0
  117. package/dist/core/lex/statements.d.ts.map +1 -0
  118. package/dist/core/lex/statements.js +90 -0
  119. package/dist/core/lex/statements.js.map +1 -0
  120. package/dist/core/lex/strings.d.ts +27 -0
  121. package/dist/core/lex/strings.d.ts.map +1 -0
  122. package/dist/core/lex/strings.js +92 -0
  123. package/dist/core/lex/strings.js.map +1 -0
  124. package/dist/core/lex/unexpected.d.ts +31 -0
  125. package/dist/core/lex/unexpected.d.ts.map +1 -0
  126. package/dist/core/lex/unexpected.js +114 -0
  127. package/dist/core/lex/unexpected.js.map +1 -0
  128. package/dist/core/parse/annotations.d.ts +4 -0
  129. package/dist/core/parse/annotations.d.ts.map +1 -0
  130. package/dist/core/parse/annotations.js +49 -0
  131. package/dist/core/parse/annotations.js.map +1 -0
  132. package/dist/core/parse/blocks.d.ts +18 -0
  133. package/dist/core/parse/blocks.d.ts.map +1 -0
  134. package/dist/core/parse/blocks.js +47 -0
  135. package/dist/core/parse/blocks.js.map +1 -0
  136. package/dist/core/parse/branches.d.ts +17 -0
  137. package/dist/core/parse/branches.d.ts.map +1 -0
  138. package/dist/core/parse/branches.js +66 -0
  139. package/dist/core/parse/branches.js.map +1 -0
  140. package/dist/core/parse/cursor.d.ts +119 -0
  141. package/dist/core/parse/cursor.d.ts.map +1 -0
  142. package/dist/core/parse/cursor.js +305 -0
  143. package/dist/core/parse/cursor.js.map +1 -0
  144. package/dist/core/parse/expressions.d.ts +57 -0
  145. package/dist/core/parse/expressions.d.ts.map +1 -0
  146. package/dist/core/parse/expressions.js +373 -0
  147. package/dist/core/parse/expressions.js.map +1 -0
  148. package/dist/core/parse/functions.d.ts +16 -0
  149. package/dist/core/parse/functions.d.ts.map +1 -0
  150. package/dist/core/parse/functions.js +92 -0
  151. package/dist/core/parse/functions.js.map +1 -0
  152. package/dist/core/parse/index.d.ts +13 -0
  153. package/dist/core/parse/index.d.ts.map +1 -0
  154. package/dist/core/parse/index.js +13 -0
  155. package/dist/core/parse/index.js.map +1 -0
  156. package/dist/core/parse/loops.d.ts +13 -0
  157. package/dist/core/parse/loops.d.ts.map +1 -0
  158. package/dist/core/parse/loops.js +78 -0
  159. package/dist/core/parse/loops.js.map +1 -0
  160. package/dist/core/parse/names.d.ts +34 -0
  161. package/dist/core/parse/names.d.ts.map +1 -0
  162. package/dist/core/parse/names.js +122 -0
  163. package/dist/core/parse/names.js.map +1 -0
  164. package/dist/core/parse/script.d.ts +23 -0
  165. package/dist/core/parse/script.d.ts.map +1 -0
  166. package/dist/core/parse/script.js +55 -0
  167. package/dist/core/parse/script.js.map +1 -0
  168. package/dist/core/parse/statements.d.ts +14 -0
  169. package/dist/core/parse/statements.d.ts.map +1 -0
  170. package/dist/core/parse/statements.js +292 -0
  171. package/dist/core/parse/statements.js.map +1 -0
  172. package/dist/core/parse/switches.d.ts +16 -0
  173. package/dist/core/parse/switches.d.ts.map +1 -0
  174. package/dist/core/parse/switches.js +98 -0
  175. package/dist/core/parse/switches.js.map +1 -0
  176. package/dist/core/render/index.d.ts +10 -0
  177. package/dist/core/render/index.d.ts.map +1 -0
  178. package/dist/core/render/index.js +10 -0
  179. package/dist/core/render/index.js.map +1 -0
  180. package/dist/core/render/terminal.d.ts +11 -0
  181. package/dist/core/render/terminal.d.ts.map +1 -0
  182. package/dist/core/render/terminal.js +51 -0
  183. package/dist/core/render/terminal.js.map +1 -0
  184. package/dist/core/source/index.d.ts +7 -0
  185. package/dist/core/source/index.d.ts.map +1 -0
  186. package/dist/core/source/index.js +2 -0
  187. package/dist/core/source/index.js.map +1 -0
  188. package/dist/core/source/source.d.ts +41 -0
  189. package/dist/core/source/source.d.ts.map +1 -0
  190. package/dist/core/source/source.js +67 -0
  191. package/dist/core/source/source.js.map +1 -0
  192. package/dist/core/span/index.d.ts +3 -0
  193. package/dist/core/span/index.d.ts.map +1 -0
  194. package/dist/core/span/index.js +2 -0
  195. package/dist/core/span/index.js.map +1 -0
  196. package/dist/core/span/span.d.ts +67 -0
  197. package/dist/core/span/span.d.ts.map +1 -0
  198. package/dist/core/span/span.js +27 -0
  199. package/dist/core/span/span.js.map +1 -0
  200. package/dist/core/tokens/index.d.ts +8 -0
  201. package/dist/core/tokens/index.d.ts.map +1 -0
  202. package/dist/core/tokens/index.js +2 -0
  203. package/dist/core/tokens/index.js.map +1 -0
  204. package/dist/core/tokens/kind.d.ts +53 -0
  205. package/dist/core/tokens/kind.d.ts.map +1 -0
  206. package/dist/core/tokens/kind.js +94 -0
  207. package/dist/core/tokens/kind.js.map +1 -0
  208. package/dist/core/tokens/token.d.ts +36 -0
  209. package/dist/core/tokens/token.d.ts.map +1 -0
  210. package/dist/core/tokens/token.js +2 -0
  211. package/dist/core/tokens/token.js.map +1 -0
  212. package/package.json +52 -0
  213. package/spec/README.md +48 -0
  214. package/spec/errors.json +3204 -0
  215. package/src/core/ast/annotations.ts +68 -0
  216. package/src/core/ast/build.ts +35 -0
  217. package/src/core/ast/children.ts +110 -0
  218. package/src/core/ast/expressions.ts +254 -0
  219. package/src/core/ast/header.ts +53 -0
  220. package/src/core/ast/index.ts +102 -0
  221. package/src/core/ast/name.ts +24 -0
  222. package/src/core/ast/node.ts +120 -0
  223. package/src/core/ast/script.ts +60 -0
  224. package/src/core/ast/statements.ts +193 -0
  225. package/src/core/ast/walk.ts +67 -0
  226. package/src/core/catalogue/catalogue.generated.ts +171 -0
  227. package/src/core/catalogue/index.ts +20 -0
  228. package/src/core/catalogue/lookup.ts +23 -0
  229. package/src/core/catalogue/template.ts +38 -0
  230. package/src/core/catalogue/types.ts +37 -0
  231. package/src/core/catalogue/values.generated.ts +160 -0
  232. package/src/core/diagnostics/collector.ts +87 -0
  233. package/src/core/diagnostics/diagnostic.ts +72 -0
  234. package/src/core/diagnostics/index.ts +12 -0
  235. package/src/core/index.ts +146 -0
  236. package/src/core/lex/blocks.ts +92 -0
  237. package/src/core/lex/characters.ts +56 -0
  238. package/src/core/lex/comments.ts +75 -0
  239. package/src/core/lex/index.ts +11 -0
  240. package/src/core/lex/layout.ts +188 -0
  241. package/src/core/lex/lexer.ts +486 -0
  242. package/src/core/lex/numbers.ts +77 -0
  243. package/src/core/lex/statements.ts +94 -0
  244. package/src/core/lex/strings.ts +119 -0
  245. package/src/core/lex/unexpected.ts +125 -0
  246. package/src/core/parse/annotations.ts +60 -0
  247. package/src/core/parse/blocks.ts +52 -0
  248. package/src/core/parse/branches.ts +77 -0
  249. package/src/core/parse/cursor.ts +348 -0
  250. package/src/core/parse/expressions.ts +441 -0
  251. package/src/core/parse/functions.ts +109 -0
  252. package/src/core/parse/index.ts +12 -0
  253. package/src/core/parse/loops.ts +97 -0
  254. package/src/core/parse/names.ts +135 -0
  255. package/src/core/parse/script.ts +64 -0
  256. package/src/core/parse/statements.ts +329 -0
  257. package/src/core/parse/switches.ts +105 -0
  258. package/src/core/render/index.ts +9 -0
  259. package/src/core/render/terminal.ts +62 -0
  260. package/src/core/source/index.ts +6 -0
  261. package/src/core/source/source.ts +102 -0
  262. package/src/core/span/index.ts +2 -0
  263. package/src/core/span/span.ts +84 -0
  264. package/src/core/tokens/index.ts +15 -0
  265. package/src/core/tokens/kind.ts +123 -0
  266. package/src/core/tokens/token.ts +39 -0
@@ -0,0 +1,57 @@
1
+ import type { Positioned } from '../span/index.js';
2
+ import type { TypeAnnotation } from './annotations.js';
3
+ import type { Expression } from './expressions.js';
4
+ import type { Name } from './name.js';
5
+ import type { Block, Statement } from './statements.js';
6
+ /**
7
+ * A parameter of a user function, language.md 11.2.
8
+ *
9
+ * A parameter is an ordinary identifier and a reserved word is OS1019 here,
10
+ * which is the rule a named argument label does not follow: the body refers to
11
+ * a parameter and nothing ever refers to a label.
12
+ */
13
+ export interface Parameter extends Positioned {
14
+ readonly kind: 'parameter';
15
+ readonly name: Name;
16
+ readonly annotation: TypeAnnotation | undefined;
17
+ readonly defaultValue: Expression | undefined;
18
+ }
19
+ /**
20
+ * `fn name(parameters) => body`, language.md 11.1.
21
+ *
22
+ * The body is an expression for the single line form and a block for the
23
+ * indented one, kept apart rather than wrapped, because the single line form
24
+ * has no block to give a span to and an editor folding a function should fold
25
+ * what was written.
26
+ *
27
+ * A function is not a statement. It may not be assigned to a name and it may
28
+ * not be nested, so the only place one belongs is the top level of a file. A
29
+ * block holds one all the same, because a reader who nested one has written it
30
+ * and OS1023 has to name the line it is on; what the tree says is where it was
31
+ * written, and the diagnostic says whether that was allowed.
32
+ */
33
+ export interface FunctionDeclaration extends Positioned {
34
+ readonly kind: 'functionDeclaration';
35
+ readonly name: Name;
36
+ readonly parameters: readonly Parameter[];
37
+ readonly body: Block | Expression;
38
+ }
39
+ export type TopLevelItem = Statement | FunctionDeclaration;
40
+ /**
41
+ * One source file.
42
+ *
43
+ * The items are everything the file holds, in source order, including the
44
+ * version line, the declaration and the limits line: a header node is a
45
+ * statement (see header.ts) and sits among the rest. So a file with no
46
+ * declaration, a file with two, and a version line halfway down all have a tree,
47
+ * which is what OS2007, OS2008 and OS1021 need in order to report a line number
48
+ * and a fix instead of a parse failure.
49
+ *
50
+ * A consumer reaches the declaration by looking through the items for the one
51
+ * kind it wants, and finds every occurrence rather than the first.
52
+ */
53
+ export interface Script extends Positioned {
54
+ readonly kind: 'script';
55
+ readonly items: readonly TopLevelItem[];
56
+ }
57
+ //# sourceMappingURL=script.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script.d.ts","sourceRoot":"","sources":["../../../src/core/ast/script.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAExD;;;;;;GAMG;AACH,MAAM,WAAW,SAAU,SAAQ,UAAU;IAC3C,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,UAAU,EAAE,cAAc,GAAG,SAAS,CAAC;IAChD,QAAQ,CAAC,YAAY,EAAE,UAAU,GAAG,SAAS,CAAC;CAC/C;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,mBAAoB,SAAQ,UAAU;IACrD,QAAQ,CAAC,IAAI,EAAE,qBAAqB,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,CAAC;IAC1C,QAAQ,CAAC,IAAI,EAAE,KAAK,GAAG,UAAU,CAAC;CACnC;AAED,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,mBAAmB,CAAC;AAE3D;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,MAAO,SAAQ,UAAU;IACxC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,CAAC;CACzC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=script.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script.js","sourceRoot":"","sources":["../../../src/core/ast/script.ts"],"names":[],"mappings":""}
@@ -0,0 +1,161 @@
1
+ import type { Positioned } from '../span/index.js';
2
+ import type { TypeAnnotation } from './annotations.js';
3
+ import type { Expression } from './expressions.js';
4
+ import type { LimitsLine, ScriptDeclaration, VersionLine } from './header.js';
5
+ import type { Name } from './name.js';
6
+ import type { FunctionDeclaration } from './script.js';
7
+ /**
8
+ * Every statement form of language.md section 10, plus the block they nest in.
9
+ *
10
+ * There is no statement that is also an expression and no expression that is
11
+ * also a statement: assignment is a statement (10.1), and `switch` is a
12
+ * statement rather than a value (10.6). That is why `if x = 5` can be OS1006
13
+ * with a fix naming `==` instead of a type error three stages later.
14
+ */
15
+ export declare const ASSIGNMENT_OPERATORS: readonly ["=", "+=", "-=", "*=", "/=", "%="];
16
+ export type AssignmentOperator = (typeof ASSIGNMENT_OPERATORS)[number];
17
+ /**
18
+ * The indented lines under a header, language.md 3.10.
19
+ *
20
+ * A block is a node with a span of its own so that OS1003 and OS1010 have
21
+ * something to point at, and so an editor can fold one. Blank and comment only
22
+ * lines produce no token, so they are not statements and never appear here.
23
+ *
24
+ * A function declaration may be written here and may not be legal here, which
25
+ * is the same arrangement the header statements already have: a version line
26
+ * inside a block is OS1021 and a declaration inside one is OS1023, and both
27
+ * diagnostics name a line and suggest a move, which a tree that refused to hold
28
+ * the node could not do. So a nested declaration stays where it was written,
29
+ * where the reader has to change it, rather than being dropped, which would
30
+ * hide it from every pass after the parser, or lifted to the top level, which
31
+ * would compile a file the language refuses.
32
+ */
33
+ export interface Block extends Positioned {
34
+ readonly kind: 'block';
35
+ readonly statements: readonly (Statement | FunctionDeclaration)[];
36
+ }
37
+ /** A bare expression on a line, which is how a script calls `plot` or `signal`. */
38
+ export interface ExpressionStatement extends Positioned {
39
+ readonly kind: 'expressionStatement';
40
+ readonly expression: Expression;
41
+ }
42
+ /**
43
+ * `name = value`, and the five compound forms.
44
+ *
45
+ * The target is a bare name, because that is the whole of the form: there is no
46
+ * `a[i] = v` and no `a.b = v` in the language, so an element is written with
47
+ * `set(arr, i, v)` and a runtime object with a `draw` setter.
48
+ */
49
+ export interface Assignment extends Positioned {
50
+ readonly kind: 'assignment';
51
+ readonly target: Name;
52
+ readonly operator: AssignmentOperator;
53
+ readonly value: Expression;
54
+ }
55
+ /**
56
+ * `var name = initial`, and `live var name = initial`, language.md 8.2.
57
+ *
58
+ * The initialiser is required rather than optional, because `var name` with no
59
+ * value is OS1011 and the fix names `= none`. A parser reporting it puts a
60
+ * `missingExpression` here and carries on, so the name is still declared for
61
+ * every later diagnostic about it.
62
+ */
63
+ export interface VarDeclaration extends Positioned {
64
+ readonly kind: 'varDeclaration';
65
+ /** `live var`: the value does not roll back when the moving bar re-executes. */
66
+ readonly live: boolean;
67
+ readonly name: Name;
68
+ readonly annotation: TypeAnnotation | undefined;
69
+ readonly initialiser: Expression;
70
+ }
71
+ /** One `if` or `else if` header and the block under it. */
72
+ export interface IfBranch extends Positioned {
73
+ readonly kind: 'ifBranch';
74
+ readonly condition: Expression;
75
+ readonly body: Block;
76
+ }
77
+ /** The final `else` and its block. A node, so the word itself has a span. */
78
+ export interface ElseBranch extends Positioned {
79
+ readonly kind: 'elseBranch';
80
+ readonly body: Block;
81
+ }
82
+ /**
83
+ * `if`, with its `else if` branches beside it rather than nested inside it.
84
+ *
85
+ * `else if` is two words on one line and does not increase indentation
86
+ * (language.md 10.2), so a reader sees one statement with several branches.
87
+ * Nesting each branch inside the previous one would make a chain of five read
88
+ * as five statements to every pass that walks the tree, and the depth would be
89
+ * visible in every diagnostic and every fold an editor offers.
90
+ */
91
+ export interface IfStatement extends Positioned {
92
+ readonly kind: 'ifStatement';
93
+ /** At least one: the `if` itself, then each `else if` in source order. */
94
+ readonly branches: readonly IfBranch[];
95
+ readonly elseBranch: ElseBranch | undefined;
96
+ }
97
+ /**
98
+ * `for i = 0 to 9` and `for i = 9 to 0 step -1`, language.md 10.3. Both ends
99
+ * are inclusive, and a missing `step` means one rather than a hidden node, so
100
+ * that OS3004 on a step of zero always has a span the reader wrote.
101
+ */
102
+ export interface ForRangeStatement extends Positioned {
103
+ readonly kind: 'forRangeStatement';
104
+ readonly variable: Name;
105
+ readonly from: Expression;
106
+ readonly to: Expression;
107
+ readonly step: Expression | undefined;
108
+ readonly body: Block;
109
+ }
110
+ /** `for price in prices`: the loop variable takes each element, not each index. */
111
+ export interface ForInStatement extends Positioned {
112
+ readonly kind: 'forInStatement';
113
+ readonly variable: Name;
114
+ readonly iterable: Expression;
115
+ readonly body: Block;
116
+ }
117
+ export interface WhileStatement extends Positioned {
118
+ readonly kind: 'whileStatement';
119
+ readonly condition: Expression;
120
+ readonly body: Block;
121
+ }
122
+ /** One `case` arm. Several values are one arm, not several arms. */
123
+ export interface SwitchCase extends Positioned {
124
+ readonly kind: 'switchCase';
125
+ readonly values: readonly Expression[];
126
+ readonly body: Block;
127
+ }
128
+ export interface SwitchDefault extends Positioned {
129
+ readonly kind: 'switchDefault';
130
+ readonly body: Block;
131
+ }
132
+ /**
133
+ * `switch`, in both forms of language.md 10.6.
134
+ *
135
+ * With a subject, each case value is compared against it. Without one, each
136
+ * case value is a condition and the first true arm runs. The absent subject is
137
+ * the difference between the two forms and needs no flag beside it.
138
+ *
139
+ * `default` has its own slot rather than sitting among the cases, because it
140
+ * must be last and because the arms do not fall through, so nothing downstream
141
+ * has to check the order it found them in.
142
+ */
143
+ export interface SwitchStatement extends Positioned {
144
+ readonly kind: 'switchStatement';
145
+ readonly subject: Expression | undefined;
146
+ readonly cases: readonly SwitchCase[];
147
+ readonly defaultCase: SwitchDefault | undefined;
148
+ }
149
+ export interface BreakStatement extends Positioned {
150
+ readonly kind: 'breakStatement';
151
+ }
152
+ export interface ContinueStatement extends Positioned {
153
+ readonly kind: 'continueStatement';
154
+ }
155
+ /** `return expression`, or a bare `return`, which returns `none`. */
156
+ export interface ReturnStatement extends Positioned {
157
+ readonly kind: 'returnStatement';
158
+ readonly value: Expression | undefined;
159
+ }
160
+ export type Statement = ExpressionStatement | Assignment | VarDeclaration | IfStatement | ForRangeStatement | ForInStatement | WhileStatement | SwitchStatement | BreakStatement | ContinueStatement | ReturnStatement | VersionLine | ScriptDeclaration | LimitsLine;
161
+ //# sourceMappingURL=statements.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"statements.d.ts","sourceRoot":"","sources":["../../../src/core/ast/statements.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,C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}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Every statement form of language.md section 10, plus the block they nest in.
3
+ *
4
+ * There is no statement that is also an expression and no expression that is
5
+ * also a statement: assignment is a statement (10.1), and `switch` is a
6
+ * statement rather than a value (10.6). That is why `if x = 5` can be OS1006
7
+ * with a fix naming `==` instead of a type error three stages later.
8
+ */
9
+ export const ASSIGNMENT_OPERATORS = ['=', '+=', '-=', '*=', '/=', '%='];
10
+ //# sourceMappingURL=statements.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"statements.js","sourceRoot":"","sources":["../../../src/core/ast/statements.ts"],"names":[],"mappings":"AAOA;;;;;;;GAOG;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAU,CAAC"}
@@ -0,0 +1,39 @@
1
+ import type { AstNode } from './node.js';
2
+ /** Returning `skip` from `enter` leaves that node's children unvisited. */
3
+ export type Visit = 'skip' | void;
4
+ export interface Visitor {
5
+ readonly enter?: (node: AstNode, parent: AstNode | undefined) => Visit;
6
+ readonly leave?: (node: AstNode, parent: AstNode | undefined) => void;
7
+ }
8
+ /**
9
+ * Every node, depth first, parents before children and children in source
10
+ * order.
11
+ *
12
+ * `leave` runs for a node whose children were skipped, so a pass that opens
13
+ * something on the way in and closes it on the way out stays balanced whatever
14
+ * it skips. A scope left open by a skipped node is the kind of fault that shows
15
+ * up as a name resolving in the wrong place, three files away from its cause.
16
+ *
17
+ * A pass that has to handle every kind should not use this. It should switch on
18
+ * `node.kind` with no default arm, so that the compiler names the kinds it has
19
+ * missed; this is for a pass that cares about a few kinds and wants the rest
20
+ * walked for it.
21
+ */
22
+ export declare function walk(root: AstNode, visitor: Visitor): void;
23
+ /**
24
+ * The nodes covering an offset, outermost first, ending at the smallest one.
25
+ *
26
+ * This is what an editor asks for and it is one function rather than three,
27
+ * because hover, completion and signature help each need the node under the
28
+ * caret and the ancestors above it, and three copies of a descent through the
29
+ * tree would answer differently at a boundary.
30
+ *
31
+ * A span covers its first character and stops before the one after it, and a
32
+ * span of no length covers nothing, so a caret sitting between two characters
33
+ * is inside the one on its left: an editor asking about a caret asks about the
34
+ * offset before it.
35
+ */
36
+ export declare function pathAtOffset(root: AstNode, offset: number): readonly AstNode[];
37
+ /** The smallest node covering an offset, or nothing when the offset is outside. */
38
+ export declare function nodeAtOffset(root: AstNode, offset: number): AstNode | undefined;
39
+ //# sourceMappingURL=walk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"walk.d.ts","sourceRoot":"","sources":["../../../src/core/ast/walk.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,2EAA2E;AAC3E,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,IAAI,CAAC;AAElC,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,SAAS,KAAK,KAAK,CAAC;IACvE,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,SAAS,KAAK,IAAI,CAAC;CACvE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAE1D;AASD;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,OAAO,EAAE,CAU9E;AAED,mFAAmF;AACnF,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAG/E"}
@@ -0,0 +1,54 @@
1
+ import { containsOffset } from '../span/index.js';
2
+ import { childrenOf } from './children.js';
3
+ /**
4
+ * Every node, depth first, parents before children and children in source
5
+ * order.
6
+ *
7
+ * `leave` runs for a node whose children were skipped, so a pass that opens
8
+ * something on the way in and closes it on the way out stays balanced whatever
9
+ * it skips. A scope left open by a skipped node is the kind of fault that shows
10
+ * up as a name resolving in the wrong place, three files away from its cause.
11
+ *
12
+ * A pass that has to handle every kind should not use this. It should switch on
13
+ * `node.kind` with no default arm, so that the compiler names the kinds it has
14
+ * missed; this is for a pass that cares about a few kinds and wants the rest
15
+ * walked for it.
16
+ */
17
+ export function walk(root, visitor) {
18
+ visitNode(root, undefined, visitor);
19
+ }
20
+ function visitNode(node, parent, visitor) {
21
+ if (visitor.enter?.(node, parent) !== 'skip') {
22
+ for (const child of childrenOf(node))
23
+ visitNode(child, node, visitor);
24
+ }
25
+ visitor.leave?.(node, parent);
26
+ }
27
+ /**
28
+ * The nodes covering an offset, outermost first, ending at the smallest one.
29
+ *
30
+ * This is what an editor asks for and it is one function rather than three,
31
+ * because hover, completion and signature help each need the node under the
32
+ * caret and the ancestors above it, and three copies of a descent through the
33
+ * tree would answer differently at a boundary.
34
+ *
35
+ * A span covers its first character and stops before the one after it, and a
36
+ * span of no length covers nothing, so a caret sitting between two characters
37
+ * is inside the one on its left: an editor asking about a caret asks about the
38
+ * offset before it.
39
+ */
40
+ export function pathAtOffset(root, offset) {
41
+ const path = [];
42
+ let current = containsOffset(root.span, offset) ? root : undefined;
43
+ while (current !== undefined) {
44
+ path.push(current);
45
+ current = childrenOf(current).find((child) => containsOffset(child.span, offset));
46
+ }
47
+ return path;
48
+ }
49
+ /** The smallest node covering an offset, or nothing when the offset is outside. */
50
+ export function nodeAtOffset(root, offset) {
51
+ const path = pathAtOffset(root, offset);
52
+ return path[path.length - 1];
53
+ }
54
+ //# sourceMappingURL=walk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"walk.js","sourceRoot":"","sources":["../../../src/core/ast/walk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,C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