@tishlang/tish-format 1.0.12 → 1.0.13

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