@tishlang/tish-format 1.0.12 → 2.0.1

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 (189) hide show
  1. package/Cargo.toml +51 -0
  2. package/LICENSE +13 -0
  3. package/bin/tish-format +0 -0
  4. package/crates/js_to_tish/Cargo.toml +11 -0
  5. package/crates/js_to_tish/README.md +18 -0
  6. package/crates/js_to_tish/src/error.rs +55 -0
  7. package/crates/js_to_tish/src/lib.rs +11 -0
  8. package/crates/js_to_tish/src/span_util.rs +35 -0
  9. package/crates/js_to_tish/src/transform/expr.rs +611 -0
  10. package/crates/js_to_tish/src/transform/stmt.rs +503 -0
  11. package/crates/js_to_tish/src/transform.rs +60 -0
  12. package/crates/tish/Cargo.toml +62 -0
  13. package/crates/tish/build.rs +21 -0
  14. package/crates/tish/src/cargo_native_registry.rs +32 -0
  15. package/crates/tish/src/cli_help.rs +576 -0
  16. package/crates/tish/src/main.rs +853 -0
  17. package/crates/tish/src/repl_completion.rs +199 -0
  18. package/crates/tish/tests/cargo_example_compile.rs +67 -0
  19. package/crates/tish/tests/error_source_location.rs +36 -0
  20. package/crates/tish/tests/fixtures/cargo_example_project/Cargo.toml +3 -0
  21. package/crates/tish/tests/fixtures/cargo_example_project/crates/demo-shim/Cargo.toml +11 -0
  22. package/crates/tish/tests/fixtures/cargo_example_project/crates/demo-shim/src/lib.rs +12 -0
  23. package/crates/tish/tests/fixtures/cargo_example_project/package.json +10 -0
  24. package/crates/tish/tests/fixtures/cargo_example_project/src/main.tish +3 -0
  25. package/crates/tish/tests/fixtures/runtime_error_location.tish +5 -0
  26. package/crates/tish/tests/fixtures/trycatch_runtime_errors.tish +15 -0
  27. package/crates/tish/tests/fixtures/tty_capability.tish +9 -0
  28. package/crates/tish/tests/integration_test.rs +1406 -0
  29. package/crates/tish/tests/run_optimize_stdout_parity.rs +50 -0
  30. package/crates/tish/tests/shortcircuit.rs +65 -0
  31. package/crates/tish/tests/trycatch_runtime_errors.rs +45 -0
  32. package/crates/tish/tests/tty_capability.rs +43 -0
  33. package/crates/tish_ast/Cargo.toml +9 -0
  34. package/crates/tish_ast/src/ast.rs +649 -0
  35. package/crates/tish_ast/src/lib.rs +5 -0
  36. package/crates/tish_build_utils/Cargo.toml +11 -0
  37. package/crates/tish_build_utils/src/lib.rs +577 -0
  38. package/crates/tish_builtins/Cargo.toml +22 -0
  39. package/crates/tish_builtins/src/array.rs +803 -0
  40. package/crates/tish_builtins/src/collections.rs +481 -0
  41. package/crates/tish_builtins/src/construct.rs +199 -0
  42. package/crates/tish_builtins/src/date.rs +538 -0
  43. package/crates/tish_builtins/src/globals.rs +293 -0
  44. package/crates/tish_builtins/src/helpers.rs +35 -0
  45. package/crates/tish_builtins/src/iterator.rs +129 -0
  46. package/crates/tish_builtins/src/lib.rs +21 -0
  47. package/crates/tish_builtins/src/math.rs +89 -0
  48. package/crates/tish_builtins/src/number.rs +96 -0
  49. package/crates/tish_builtins/src/object.rs +36 -0
  50. package/crates/tish_builtins/src/string.rs +646 -0
  51. package/crates/tish_builtins/src/symbol.rs +83 -0
  52. package/crates/tish_builtins/src/typedarrays.rs +298 -0
  53. package/crates/tish_bytecode/Cargo.toml +17 -0
  54. package/crates/tish_bytecode/src/chunk.rs +164 -0
  55. package/crates/tish_bytecode/src/compiler.rs +2604 -0
  56. package/crates/tish_bytecode/src/encoding.rs +102 -0
  57. package/crates/tish_bytecode/src/lib.rs +20 -0
  58. package/crates/tish_bytecode/src/opcode.rs +185 -0
  59. package/crates/tish_bytecode/src/peephole.rs +189 -0
  60. package/crates/tish_bytecode/src/serialize.rs +193 -0
  61. package/crates/tish_bytecode/tests/break_continue_bytecode.rs +44 -0
  62. package/crates/tish_bytecode/tests/constant_folding.rs +84 -0
  63. package/crates/tish_bytecode/tests/sort_optimization.rs +31 -0
  64. package/crates/tish_compile/Cargo.toml +27 -0
  65. package/crates/tish_compile/src/check.rs +774 -0
  66. package/crates/tish_compile/src/codegen.rs +7317 -0
  67. package/crates/tish_compile/src/infer.rs +1681 -0
  68. package/crates/tish_compile/src/lib.rs +206 -0
  69. package/crates/tish_compile/src/resolve.rs +1951 -0
  70. package/crates/tish_compile/src/types.rs +605 -0
  71. package/crates/tish_compile_js/Cargo.toml +18 -0
  72. package/crates/tish_compile_js/examples/jsx_vdom_smoke.tish +8 -0
  73. package/crates/tish_compile_js/src/codegen.rs +938 -0
  74. package/crates/tish_compile_js/src/error.rs +20 -0
  75. package/crates/tish_compile_js/src/lib.rs +26 -0
  76. package/crates/tish_compile_js/src/tests_jsx.rs +414 -0
  77. package/crates/tish_compiler_wasm/Cargo.toml +21 -0
  78. package/crates/tish_compiler_wasm/src/lib.rs +57 -0
  79. package/crates/tish_compiler_wasm/src/resolve_virtual.rs +473 -0
  80. package/crates/tish_core/Cargo.toml +32 -0
  81. package/crates/tish_core/src/console_style.rs +170 -0
  82. package/crates/tish_core/src/json.rs +430 -0
  83. package/crates/tish_core/src/lib.rs +20 -0
  84. package/crates/tish_core/src/macros.rs +36 -0
  85. package/crates/tish_core/src/shape.rs +85 -0
  86. package/crates/tish_core/src/uri.rs +118 -0
  87. package/crates/tish_core/src/value.rs +1350 -0
  88. package/crates/tish_core/src/vmref.rs +183 -0
  89. package/crates/tish_cranelift/Cargo.toml +19 -0
  90. package/crates/tish_cranelift/src/lib.rs +43 -0
  91. package/crates/tish_cranelift/src/link.rs +130 -0
  92. package/crates/tish_cranelift/src/lower.rs +85 -0
  93. package/crates/tish_cranelift_runtime/Cargo.toml +26 -0
  94. package/crates/tish_cranelift_runtime/src/lib.rs +45 -0
  95. package/crates/tish_eval/Cargo.toml +51 -0
  96. package/crates/tish_eval/src/eval.rs +4265 -0
  97. package/crates/tish_eval/src/http.rs +191 -0
  98. package/crates/tish_eval/src/lib.rs +99 -0
  99. package/crates/tish_eval/src/natives.rs +551 -0
  100. package/crates/tish_eval/src/promise.rs +179 -0
  101. package/crates/tish_eval/src/regex.rs +299 -0
  102. package/crates/tish_eval/src/timers.rs +120 -0
  103. package/crates/tish_eval/src/value.rs +336 -0
  104. package/crates/tish_eval/src/value_convert.rs +117 -0
  105. package/crates/tish_ffi/Cargo.toml +26 -0
  106. package/crates/tish_ffi/src/lib.rs +518 -0
  107. package/crates/tish_ffi/tests/fixtures/testmod/Cargo.toml +18 -0
  108. package/crates/tish_ffi/tests/fixtures/testmod/src/lib.rs +46 -0
  109. package/crates/tish_ffi/tests/loader.rs +65 -0
  110. package/crates/tish_fmt/Cargo.toml +16 -0
  111. package/crates/tish_fmt/src/bin/tish-fmt.rs +41 -0
  112. package/crates/tish_fmt/src/lib.rs +2157 -0
  113. package/crates/tish_jsx_web/Cargo.toml +9 -0
  114. package/crates/tish_jsx_web/README.md +5 -0
  115. package/crates/tish_jsx_web/src/lib.rs +2 -0
  116. package/crates/tish_lexer/Cargo.toml +9 -0
  117. package/crates/tish_lexer/src/lib.rs +1104 -0
  118. package/crates/tish_lexer/src/token.rs +170 -0
  119. package/crates/tish_lint/Cargo.toml +18 -0
  120. package/crates/tish_lint/src/bin/tish-lint.rs +195 -0
  121. package/crates/tish_lint/src/lib.rs +281 -0
  122. package/crates/tish_llvm/Cargo.toml +13 -0
  123. package/crates/tish_llvm/src/lib.rs +115 -0
  124. package/crates/tish_lsp/Cargo.toml +25 -0
  125. package/crates/tish_lsp/README.md +26 -0
  126. package/crates/tish_lsp/src/builtin_goto.rs +362 -0
  127. package/crates/tish_lsp/src/import_goto.rs +564 -0
  128. package/crates/tish_lsp/src/main.rs +1459 -0
  129. package/crates/tish_native/Cargo.toml +16 -0
  130. package/crates/tish_native/src/build.rs +481 -0
  131. package/crates/tish_native/src/config.rs +48 -0
  132. package/crates/tish_native/src/lib.rs +416 -0
  133. package/crates/tish_opt/Cargo.toml +13 -0
  134. package/crates/tish_opt/src/lib.rs +1046 -0
  135. package/crates/tish_parser/Cargo.toml +11 -0
  136. package/crates/tish_parser/src/lib.rs +386 -0
  137. package/crates/tish_parser/src/parser.rs +2726 -0
  138. package/crates/tish_pg/Cargo.toml +34 -0
  139. package/crates/tish_pg/README.md +38 -0
  140. package/crates/tish_pg/src/error.rs +52 -0
  141. package/crates/tish_pg/src/lib.rs +955 -0
  142. package/crates/tish_resolve/Cargo.toml +13 -0
  143. package/crates/tish_resolve/src/lib.rs +3601 -0
  144. package/crates/tish_resolve/src/pos.rs +141 -0
  145. package/crates/tish_runtime/Cargo.toml +100 -0
  146. package/crates/tish_runtime/src/http.rs +1347 -0
  147. package/crates/tish_runtime/src/http_fetch.rs +492 -0
  148. package/crates/tish_runtime/src/http_hyper.rs +441 -0
  149. package/crates/tish_runtime/src/http_prefork.rs +189 -0
  150. package/crates/tish_runtime/src/lib.rs +1447 -0
  151. package/crates/tish_runtime/src/native_promise.rs +15 -0
  152. package/crates/tish_runtime/src/promise.rs +558 -0
  153. package/crates/tish_runtime/src/promise_io.rs +38 -0
  154. package/crates/tish_runtime/src/timers.rs +172 -0
  155. package/crates/tish_runtime/src/tty.rs +226 -0
  156. package/crates/tish_runtime/src/ws.rs +778 -0
  157. package/crates/tish_runtime/tests/fetch_readable_stream.rs +102 -0
  158. package/crates/tish_ui/Cargo.toml +17 -0
  159. package/crates/tish_ui/src/jsx.rs +692 -0
  160. package/crates/tish_ui/src/lib.rs +20 -0
  161. package/crates/tish_ui/src/runtime/hooks.rs +573 -0
  162. package/crates/tish_ui/src/runtime/mod.rs +183 -0
  163. package/crates/tish_vm/Cargo.toml +60 -0
  164. package/crates/tish_vm/src/jit.rs +1050 -0
  165. package/crates/tish_vm/src/lib.rs +41 -0
  166. package/crates/tish_vm/src/vm.rs +3536 -0
  167. package/crates/tish_vm/tests/concurrent_shared_state.rs +140 -0
  168. package/crates/tish_vm/tests/fixtures/or_string_cmd.tish +2 -0
  169. package/crates/tish_vm/tests/lexical_scope_declare.rs +34 -0
  170. package/crates/tish_vm/tests/peephole_jump_chain_logical_or.rs +150 -0
  171. package/crates/tish_wasm/Cargo.toml +15 -0
  172. package/crates/tish_wasm/src/lib.rs +428 -0
  173. package/crates/tish_wasm_runtime/Cargo.toml +37 -0
  174. package/crates/tish_wasm_runtime/src/gpu.rs +429 -0
  175. package/crates/tish_wasm_runtime/src/lib.rs +42 -0
  176. package/crates/tishlang_cargo_bindgen/Cargo.toml +26 -0
  177. package/crates/tishlang_cargo_bindgen/src/classify.rs +261 -0
  178. package/crates/tishlang_cargo_bindgen/src/discover.rs +125 -0
  179. package/crates/tishlang_cargo_bindgen/src/infer.rs +382 -0
  180. package/crates/tishlang_cargo_bindgen/src/lib.rs +349 -0
  181. package/crates/tishlang_cargo_bindgen/src/main.rs +167 -0
  182. package/crates/tishlang_cargo_bindgen/src/metadata.rs +117 -0
  183. package/justfile +276 -0
  184. package/package.json +2 -2
  185. package/platform/darwin-arm64/tish-fmt +0 -0
  186. package/platform/darwin-x64/tish-fmt +0 -0
  187. package/platform/linux-arm64/tish-fmt +0 -0
  188. package/platform/linux-x64/tish-fmt +0 -0
  189. package/platform/win32-x64/tish-fmt.exe +0 -0
@@ -0,0 +1,649 @@
1
+ //! Abstract syntax tree for Tish.
2
+
3
+ use std::sync::Arc;
4
+
5
+ #[derive(Debug, Clone, Copy, PartialEq)]
6
+ pub struct Span {
7
+ pub start: (usize, usize), // line, col
8
+ pub end: (usize, usize),
9
+ }
10
+
11
+ /// Type annotation for variables, parameters, and return types.
12
+ #[derive(Debug, Clone, PartialEq)]
13
+ pub enum TypeAnnotation {
14
+ /// Primitive types: number, string, boolean, null
15
+ Simple(Arc<str>),
16
+ /// Array type: T[]
17
+ Array(Box<TypeAnnotation>),
18
+ /// Object type: { key: Type, ... }
19
+ Object(Vec<(Arc<str>, TypeAnnotation)>),
20
+ /// Function type: (T1, T2) => R
21
+ Function {
22
+ params: Vec<TypeAnnotation>,
23
+ returns: Box<TypeAnnotation>,
24
+ },
25
+ /// Union type: T1 | T2
26
+ Union(Vec<TypeAnnotation>),
27
+ /// Tuple type: [T1, T2, ...]
28
+ Tuple(Vec<TypeAnnotation>),
29
+ /// Literal type: "foo" | 42 | true (a value used as a type)
30
+ Literal(TypeLiteral),
31
+ /// Intersection type: T1 & T2 (e.g. `interface X extends Y { … }` → `Y & { … }`)
32
+ Intersection(Vec<TypeAnnotation>),
33
+ }
34
+
35
+ /// A literal value used in type position (`"a"`, `42`, `true`).
36
+ #[derive(Debug, Clone, PartialEq)]
37
+ pub enum TypeLiteral {
38
+ Str(Arc<str>),
39
+ Num(f64),
40
+ Bool(bool),
41
+ }
42
+
43
+ /// Function parameter with optional type annotation and default value.
44
+ #[derive(Debug, Clone, PartialEq)]
45
+ pub struct TypedParam {
46
+ pub name: Arc<str>,
47
+ pub name_span: Span,
48
+ pub type_ann: Option<TypeAnnotation>,
49
+ pub default: Option<Expr>,
50
+ }
51
+
52
+ /// Single formal parameter: simple identifier or destructuring pattern.
53
+ #[derive(Debug, Clone, PartialEq)]
54
+ pub enum FunParam {
55
+ Simple(TypedParam),
56
+ Destructure {
57
+ pattern: DestructPattern,
58
+ type_ann: Option<TypeAnnotation>,
59
+ default: Option<Expr>,
60
+ },
61
+ }
62
+
63
+ impl FunParam {
64
+ /// Variable names introduced by this formal parameter.
65
+ pub fn bound_names(&self) -> Vec<Arc<str>> {
66
+ let mut out = Vec::new();
67
+ match self {
68
+ FunParam::Simple(tp) => out.push(Arc::clone(&tp.name)),
69
+ FunParam::Destructure { pattern, .. } => {
70
+ Self::collect_pattern_binding_names(pattern, &mut out);
71
+ }
72
+ }
73
+ out
74
+ }
75
+
76
+ fn collect_pattern_binding_names(pattern: &DestructPattern, out: &mut Vec<Arc<str>>) {
77
+ match pattern {
78
+ DestructPattern::Array(elements) => {
79
+ for el in elements.iter().flatten() {
80
+ match el {
81
+ DestructElement::Ident(n, _) => out.push(Arc::clone(n)),
82
+ DestructElement::Pattern(p) => {
83
+ Self::collect_pattern_binding_names(p, out);
84
+ }
85
+ DestructElement::Rest(n, _) => out.push(Arc::clone(n)),
86
+ }
87
+ }
88
+ }
89
+ DestructPattern::Object(props) => {
90
+ for prop in props {
91
+ match &prop.value {
92
+ DestructElement::Ident(n, _) => out.push(Arc::clone(n)),
93
+ DestructElement::Pattern(p) => {
94
+ Self::collect_pattern_binding_names(p, out);
95
+ }
96
+ DestructElement::Rest(n, _) => out.push(Arc::clone(n)),
97
+ }
98
+ }
99
+ }
100
+ }
101
+ }
102
+ }
103
+
104
+ /// Destructuring pattern for array or object destructuring
105
+ #[derive(Debug, Clone, PartialEq)]
106
+ pub enum DestructPattern {
107
+ /// Array destructuring: [a, b, c] or [a, , c]
108
+ Array(Vec<Option<DestructElement>>),
109
+ /// Object destructuring: { a, b: renamed, c }
110
+ Object(Vec<DestructProp>),
111
+ }
112
+
113
+ /// Element in array destructuring pattern
114
+ #[derive(Debug, Clone, PartialEq)]
115
+ pub enum DestructElement {
116
+ /// Simple binding: a
117
+ Ident(Arc<str>, Span),
118
+ /// Nested pattern: [a, b] or { x, y }
119
+ Pattern(Box<DestructPattern>),
120
+ /// Rest element: ...rest
121
+ Rest(Arc<str>, Span),
122
+ }
123
+
124
+ /// Property in object destructuring pattern
125
+ #[derive(Debug, Clone, PartialEq)]
126
+ pub struct DestructProp {
127
+ /// Original property name in source object
128
+ pub key: Arc<str>,
129
+ /// Binding name (may be same as key or renamed)
130
+ pub value: DestructElement,
131
+ }
132
+
133
+ /// Import specifier: named (a, b: c), namespace (* as M), or default (X)
134
+ #[derive(Debug, Clone, PartialEq)]
135
+ pub enum ImportSpecifier {
136
+ /// Named: { foo } or { foo as bar }
137
+ Named {
138
+ name: Arc<str>,
139
+ name_span: Span,
140
+ alias: Option<Arc<str>>,
141
+ alias_span: Option<Span>,
142
+ },
143
+ /// Namespace: * as M
144
+ Namespace { name: Arc<str>, name_span: Span },
145
+ /// Default: import X from "..."
146
+ Default { name: Arc<str>, name_span: Span },
147
+ }
148
+
149
+ /// Export declaration: named (const/let/fn) or default
150
+ #[derive(Debug, Clone, PartialEq)]
151
+ pub enum ExportDeclaration {
152
+ /// export const x = 1 / export let x / export fn f() {}
153
+ Named(Box<Statement>),
154
+ /// export default expr
155
+ Default(Expr),
156
+ }
157
+
158
+ #[derive(Debug, Clone)]
159
+ pub struct Program {
160
+ pub statements: Vec<Statement>,
161
+ }
162
+
163
+ #[derive(Debug, Clone, PartialEq)]
164
+ pub enum Statement {
165
+ Block {
166
+ statements: Vec<Statement>,
167
+ span: Span,
168
+ },
169
+ VarDecl {
170
+ name: Arc<str>,
171
+ name_span: Span,
172
+ mutable: bool, // true for `let`, false for `const`
173
+ type_ann: Option<TypeAnnotation>,
174
+ init: Option<Expr>,
175
+ span: Span,
176
+ },
177
+ /// Variable declaration with destructuring pattern
178
+ VarDeclDestructure {
179
+ pattern: DestructPattern,
180
+ mutable: bool,
181
+ init: Expr,
182
+ span: Span,
183
+ },
184
+ /// A transparent group of statements that execute in the *current* scope
185
+ /// (no new block scope). Produced for comma-separated declarators
186
+ /// (`let a = 1, b = 2`) so each declarator lowers to its own VarDecl while
187
+ /// still occupying a single statement slot (e.g. a `for` initializer).
188
+ Multi {
189
+ statements: Vec<Statement>,
190
+ span: Span,
191
+ },
192
+ ExprStmt {
193
+ expr: Expr,
194
+ span: Span,
195
+ },
196
+ If {
197
+ cond: Expr,
198
+ then_branch: Box<Statement>,
199
+ else_branch: Option<Box<Statement>>,
200
+ span: Span,
201
+ },
202
+ While {
203
+ cond: Expr,
204
+ body: Box<Statement>,
205
+ span: Span,
206
+ },
207
+ For {
208
+ init: Option<Box<Statement>>,
209
+ cond: Option<Expr>,
210
+ update: Option<Expr>,
211
+ body: Box<Statement>,
212
+ span: Span,
213
+ },
214
+ ForOf {
215
+ name: Arc<str>,
216
+ name_span: Span,
217
+ iterable: Expr,
218
+ body: Box<Statement>,
219
+ span: Span,
220
+ },
221
+ Return {
222
+ value: Option<Expr>,
223
+ span: Span,
224
+ },
225
+ Break {
226
+ span: Span,
227
+ },
228
+ Continue {
229
+ span: Span,
230
+ },
231
+ FunDecl {
232
+ async_: bool,
233
+ name: Arc<str>,
234
+ name_span: Span,
235
+ params: Vec<FunParam>,
236
+ rest_param: Option<TypedParam>,
237
+ return_type: Option<TypeAnnotation>,
238
+ body: Box<Statement>,
239
+ span: Span,
240
+ },
241
+ Switch {
242
+ expr: Expr,
243
+ cases: Vec<(Option<Expr>, Vec<Statement>)>,
244
+ default_body: Option<Vec<Statement>>,
245
+ span: Span,
246
+ },
247
+ DoWhile {
248
+ body: Box<Statement>,
249
+ cond: Expr,
250
+ span: Span,
251
+ },
252
+ Throw {
253
+ value: Expr,
254
+ span: Span,
255
+ },
256
+ Try {
257
+ body: Box<Statement>,
258
+ catch_param: Option<Arc<str>>,
259
+ catch_param_span: Option<Span>,
260
+ catch_body: Option<Box<Statement>>,
261
+ finally_body: Option<Box<Statement>>,
262
+ span: Span,
263
+ },
264
+ Import {
265
+ specifiers: Vec<ImportSpecifier>,
266
+ from: Arc<str>,
267
+ span: Span,
268
+ },
269
+ Export {
270
+ declaration: Box<ExportDeclaration>,
271
+ span: Span,
272
+ },
273
+ /// `type Name = Type` (erased at runtime; for checker / declaration files).
274
+ TypeAlias {
275
+ name: Arc<str>,
276
+ name_span: Span,
277
+ ty: TypeAnnotation,
278
+ span: Span,
279
+ },
280
+ /// `declare let name: T` or `declare const name: T`
281
+ DeclareVar {
282
+ name: Arc<str>,
283
+ name_span: Span,
284
+ type_ann: Option<TypeAnnotation>,
285
+ const_: bool,
286
+ span: Span,
287
+ },
288
+ /// `declare [async] function name(...): R` (no body).
289
+ DeclareFun {
290
+ async_: bool,
291
+ name: Arc<str>,
292
+ name_span: Span,
293
+ params: Vec<FunParam>,
294
+ rest_param: Option<TypedParam>,
295
+ return_type: Option<TypeAnnotation>,
296
+ span: Span,
297
+ },
298
+ }
299
+
300
+ #[derive(Debug, Clone, PartialEq)]
301
+ pub enum Expr {
302
+ Literal {
303
+ value: Literal,
304
+ span: Span,
305
+ },
306
+ Ident {
307
+ name: Arc<str>,
308
+ span: Span,
309
+ },
310
+ Binary {
311
+ left: Box<Expr>,
312
+ op: BinOp,
313
+ right: Box<Expr>,
314
+ span: Span,
315
+ },
316
+ Unary {
317
+ op: UnaryOp,
318
+ operand: Box<Expr>,
319
+ span: Span,
320
+ },
321
+ Call {
322
+ callee: Box<Expr>,
323
+ args: Vec<CallArg>,
324
+ span: Span,
325
+ },
326
+ /// `new` expression (JavaScript target). `callee` is the constructor reference; `args` may be empty.
327
+ New {
328
+ callee: Box<Expr>,
329
+ args: Vec<CallArg>,
330
+ span: Span,
331
+ },
332
+ Member {
333
+ object: Box<Expr>,
334
+ prop: MemberProp,
335
+ optional: bool,
336
+ span: Span,
337
+ },
338
+ Index {
339
+ object: Box<Expr>,
340
+ index: Box<Expr>,
341
+ optional: bool,
342
+ span: Span,
343
+ },
344
+ Conditional {
345
+ cond: Box<Expr>,
346
+ then_branch: Box<Expr>,
347
+ else_branch: Box<Expr>,
348
+ span: Span,
349
+ },
350
+ NullishCoalesce {
351
+ left: Box<Expr>,
352
+ right: Box<Expr>,
353
+ span: Span,
354
+ },
355
+ Array {
356
+ elements: Vec<ArrayElement>,
357
+ span: Span,
358
+ },
359
+ Object {
360
+ props: Vec<ObjectProp>,
361
+ span: Span,
362
+ },
363
+ Assign {
364
+ name: Arc<str>,
365
+ value: Box<Expr>,
366
+ span: Span,
367
+ },
368
+ TypeOf {
369
+ operand: Box<Expr>,
370
+ span: Span,
371
+ },
372
+ /// `delete obj.prop` / `delete obj[key]` — removes a property, evaluates to a boolean.
373
+ Delete {
374
+ target: Box<Expr>,
375
+ span: Span,
376
+ },
377
+ PostfixInc {
378
+ name: Arc<str>,
379
+ span: Span,
380
+ },
381
+ PostfixDec {
382
+ name: Arc<str>,
383
+ span: Span,
384
+ },
385
+ PrefixInc {
386
+ name: Arc<str>,
387
+ span: Span,
388
+ },
389
+ PrefixDec {
390
+ name: Arc<str>,
391
+ span: Span,
392
+ },
393
+ CompoundAssign {
394
+ name: Arc<str>,
395
+ op: CompoundOp,
396
+ value: Box<Expr>,
397
+ span: Span,
398
+ },
399
+ LogicalAssign {
400
+ name: Arc<str>,
401
+ op: LogicalAssignOp,
402
+ value: Box<Expr>,
403
+ span: Span,
404
+ },
405
+ /// Property assignment: obj.prop = value
406
+ MemberAssign {
407
+ object: Box<Expr>,
408
+ prop: Arc<str>,
409
+ value: Box<Expr>,
410
+ span: Span,
411
+ },
412
+ /// Index assignment: arr[index] = value
413
+ IndexAssign {
414
+ object: Box<Expr>,
415
+ index: Box<Expr>,
416
+ value: Box<Expr>,
417
+ span: Span,
418
+ },
419
+ /// Arrow function: (params) => body
420
+ ArrowFunction {
421
+ params: Vec<FunParam>,
422
+ body: ArrowBody,
423
+ span: Span,
424
+ },
425
+ /// Template literal: `text ${expr} text`
426
+ TemplateLiteral {
427
+ quasis: Vec<Arc<str>>, // Static string parts (n+1 for n expressions)
428
+ exprs: Vec<Expr>, // Interpolated expressions (n)
429
+ span: Span,
430
+ },
431
+ /// Await expression: await operand
432
+ Await {
433
+ operand: Box<Expr>,
434
+ span: Span,
435
+ },
436
+ /// JSX element: <Tag props>children</Tag>
437
+ JsxElement {
438
+ tag: Arc<str>,
439
+ props: Vec<JsxProp>,
440
+ children: Vec<JsxChild>,
441
+ span: Span,
442
+ },
443
+ /// JSX fragment: <>children</>
444
+ JsxFragment {
445
+ children: Vec<JsxChild>,
446
+ span: Span,
447
+ },
448
+ /// Native module load: import { x } from 'tish:egui' → loads from tishlang_runtime
449
+ NativeModuleLoad {
450
+ spec: Arc<str>,
451
+ export_name: Arc<str>,
452
+ span: Span,
453
+ },
454
+ }
455
+
456
+ /// JSX attribute/prop
457
+ #[derive(Debug, Clone, PartialEq)]
458
+ pub enum JsxProp {
459
+ /// name="value" or name={expr} or name (boolean shorthand)
460
+ Attr { name: Arc<str>, value: JsxAttrValue },
461
+ /// {...expr}
462
+ Spread(Expr),
463
+ }
464
+
465
+ /// JSX attribute value
466
+ #[derive(Debug, Clone, PartialEq)]
467
+ pub enum JsxAttrValue {
468
+ /// "literal string"
469
+ String(Arc<str>),
470
+ /// {expr}
471
+ Expr(Expr),
472
+ /// name without value (e.g. disabled) = true
473
+ ImplicitTrue,
474
+ }
475
+
476
+ /// JSX child node
477
+ #[derive(Debug, Clone, PartialEq)]
478
+ pub enum JsxChild {
479
+ /// Text content
480
+ Text(Arc<str>),
481
+ /// {expr} or nested element
482
+ Expr(Expr),
483
+ }
484
+
485
+ impl Expr {
486
+ /// Return the source span for this expression.
487
+ pub fn span(&self) -> Span {
488
+ match self {
489
+ Expr::Literal { span, .. } => *span,
490
+ Expr::Ident { span, .. } => *span,
491
+ Expr::Binary { span, .. } => *span,
492
+ Expr::Unary { span, .. } => *span,
493
+ Expr::Call { span, .. } => *span,
494
+ Expr::New { span, .. } => *span,
495
+ Expr::Member { span, .. } => *span,
496
+ Expr::Index { span, .. } => *span,
497
+ Expr::Conditional { span, .. } => *span,
498
+ Expr::NullishCoalesce { span, .. } => *span,
499
+ Expr::Array { span, .. } => *span,
500
+ Expr::Object { span, .. } => *span,
501
+ Expr::Assign { span, .. } => *span,
502
+ Expr::TypeOf { span, .. } => *span,
503
+ Expr::Delete { span, .. } => *span,
504
+ Expr::PostfixInc { span, .. } => *span,
505
+ Expr::PostfixDec { span, .. } => *span,
506
+ Expr::PrefixInc { span, .. } => *span,
507
+ Expr::PrefixDec { span, .. } => *span,
508
+ Expr::CompoundAssign { span, .. } => *span,
509
+ Expr::LogicalAssign { span, .. } => *span,
510
+ Expr::MemberAssign { span, .. } => *span,
511
+ Expr::IndexAssign { span, .. } => *span,
512
+ Expr::ArrowFunction { span, .. } => *span,
513
+ Expr::TemplateLiteral { span, .. } => *span,
514
+ Expr::Await { span, .. } => *span,
515
+ Expr::JsxElement { span, .. } => *span,
516
+ Expr::JsxFragment { span, .. } => *span,
517
+ Expr::NativeModuleLoad { span, .. } => *span,
518
+ }
519
+ }
520
+ }
521
+
522
+ /// Body of an arrow function: either an expression or a block
523
+ #[derive(Debug, Clone, PartialEq)]
524
+ pub enum ArrowBody {
525
+ Expr(Box<Expr>),
526
+ Block(Box<Statement>),
527
+ }
528
+
529
+ /// Array element: either a regular expression or spread element
530
+ #[derive(Debug, Clone, PartialEq)]
531
+ pub enum ArrayElement {
532
+ Expr(Expr),
533
+ Spread(Expr),
534
+ }
535
+
536
+ /// Object property: either a regular key-value pair or spread
537
+ #[derive(Debug, Clone, PartialEq)]
538
+ pub enum ObjectProp {
539
+ KeyValue(Arc<str>, Expr),
540
+ Spread(Expr),
541
+ }
542
+
543
+ /// Function call argument: either a regular argument or spread
544
+ #[derive(Debug, Clone, PartialEq)]
545
+ pub enum CallArg {
546
+ Expr(Expr),
547
+ Spread(Expr),
548
+ }
549
+
550
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
551
+ pub enum CompoundOp {
552
+ Add, // +=
553
+ Sub, // -=
554
+ Mul, // *=
555
+ Div, // /=
556
+ Mod, // %=
557
+ }
558
+
559
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
560
+ pub enum LogicalAssignOp {
561
+ AndAnd, // &&=
562
+ OrOr, // ||=
563
+ Nullish, // ??=
564
+ }
565
+
566
+ #[derive(Debug, Clone, PartialEq)]
567
+ pub enum Literal {
568
+ Number(f64),
569
+ String(Arc<str>),
570
+ Bool(bool),
571
+ Null,
572
+ }
573
+
574
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
575
+ pub enum BinOp {
576
+ Add,
577
+ Sub,
578
+ Mul,
579
+ Div,
580
+ Mod,
581
+ Pow,
582
+ Eq,
583
+ Ne,
584
+ StrictEq,
585
+ StrictNe,
586
+ Lt,
587
+ Le,
588
+ Gt,
589
+ Ge,
590
+ And,
591
+ Or,
592
+ BitAnd,
593
+ BitOr,
594
+ BitXor,
595
+ Shl,
596
+ Shr,
597
+ /// `>>>` — unsigned (logical) right shift; JS ToUint32 semantics.
598
+ UShr,
599
+ In,
600
+ }
601
+
602
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
603
+ pub enum UnaryOp {
604
+ Not,
605
+ Neg,
606
+ Pos,
607
+ BitNot,
608
+ Void,
609
+ }
610
+
611
+ #[derive(Debug, Clone, PartialEq)]
612
+ pub enum MemberProp {
613
+ /// Property name in `obj.prop` / `obj?.prop` (span covers **prop** only).
614
+ Name {
615
+ name: Arc<str>,
616
+ span: Span,
617
+ },
618
+ Expr(Box<Expr>), // for computed property
619
+ }
620
+
621
+ impl Statement {
622
+ /// Source span covering this statement (including nested bodies where applicable).
623
+ pub fn span(&self) -> Span {
624
+ match self {
625
+ Statement::Block { span, .. }
626
+ | Statement::VarDecl { span, .. }
627
+ | Statement::VarDeclDestructure { span, .. }
628
+ | Statement::Multi { span, .. }
629
+ | Statement::ExprStmt { span, .. }
630
+ | Statement::If { span, .. }
631
+ | Statement::While { span, .. }
632
+ | Statement::For { span, .. }
633
+ | Statement::ForOf { span, .. }
634
+ | Statement::Return { span, .. }
635
+ | Statement::Break { span, .. }
636
+ | Statement::Continue { span, .. }
637
+ | Statement::FunDecl { span, .. }
638
+ | Statement::Switch { span, .. }
639
+ | Statement::DoWhile { span, .. }
640
+ | Statement::Throw { span, .. }
641
+ | Statement::Try { span, .. }
642
+ | Statement::Import { span, .. }
643
+ | Statement::Export { span, .. }
644
+ | Statement::TypeAlias { span, .. }
645
+ | Statement::DeclareVar { span, .. }
646
+ | Statement::DeclareFun { span, .. } => *span,
647
+ }
648
+ }
649
+ }
@@ -0,0 +1,5 @@
1
+ //! Tish AST types and span info.
2
+
3
+ mod ast;
4
+
5
+ pub use ast::*;
@@ -0,0 +1,11 @@
1
+ [package]
2
+ name = "tishlang_build_utils"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ description = "Shared build utilities for Tish (workspace discovery, path resolution)"
6
+ license-file = { workspace = true }
7
+ repository = { workspace = true }
8
+
9
+ [dependencies]
10
+ # Bundled `protoc` for nested `cargo build` (Lance / prost-build) when none is on PATH.
11
+ protoc-bin-vendored = "3"