semantifold 0.5.0 → 0.7.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 (201) hide show
  1. package/README.md +15 -9
  2. package/build/index.d.ts +8 -8
  3. package/build/index.d.ts.map +1 -1
  4. package/build/index.js +6 -6
  5. package/build/src/backends/android.js +8 -4
  6. package/build/src/backends/dart.d.ts +19 -0
  7. package/build/src/backends/dart.d.ts.map +1 -1
  8. package/build/src/backends/dart.js +28 -16
  9. package/build/src/backends/flutter.d.ts +51 -0
  10. package/build/src/backends/flutter.d.ts.map +1 -0
  11. package/build/src/backends/flutter.js +1362 -0
  12. package/build/src/backends/identifiers.d.ts +6 -0
  13. package/build/src/backends/identifiers.d.ts.map +1 -1
  14. package/build/src/backends/identifiers.js +28 -5
  15. package/build/src/backends/ios.js +2 -2
  16. package/build/src/backends/native-validation.d.ts +2 -2
  17. package/build/src/backends/native-validation.d.ts.map +1 -1
  18. package/build/src/backends/native-validation.js +2 -2
  19. package/build/src/backends/program.d.ts +4 -4
  20. package/build/src/backends/program.d.ts.map +1 -1
  21. package/build/src/backends/program.js +4 -4
  22. package/build/src/backends/scalars.d.ts.map +1 -1
  23. package/build/src/backends/scalars.js +2 -1
  24. package/build/src/backends/shared.d.ts +7 -0
  25. package/build/src/backends/shared.d.ts.map +1 -1
  26. package/build/src/backends/shared.js +14 -9
  27. package/build/src/backends/zig-runtime.d.ts +5 -0
  28. package/build/src/backends/zig-runtime.d.ts.map +1 -0
  29. package/build/src/backends/zig-runtime.js +92 -0
  30. package/build/src/backends/zig-validation.d.ts +9 -0
  31. package/build/src/backends/zig-validation.d.ts.map +1 -0
  32. package/build/src/backends/zig-validation.js +73 -0
  33. package/build/src/backends/zig.d.ts +42 -0
  34. package/build/src/backends/zig.d.ts.map +1 -0
  35. package/build/src/backends/zig.js +584 -0
  36. package/build/src/frontends/scalars.d.ts.map +1 -1
  37. package/build/src/frontends/scalars.js +2 -1
  38. package/build/src/frontends/zig-parser.d.ts +31 -0
  39. package/build/src/frontends/zig-parser.d.ts.map +1 -0
  40. package/build/src/frontends/zig-parser.js +17 -0
  41. package/build/src/frontends/zig.d.ts +14 -0
  42. package/build/src/frontends/zig.d.ts.map +1 -0
  43. package/build/src/frontends/zig.js +970 -0
  44. package/build/src/language-registry.d.ts.map +1 -1
  45. package/build/src/language-registry.js +40 -1
  46. package/build/src/mapping.js +2 -2
  47. package/build/src/semantic/provenance.js +3 -3
  48. package/build/src/semantic/types.d.ts +154 -4
  49. package/build/src/semantic/types.d.ts.map +1 -1
  50. package/build/src/semantic/types.js +39 -3
  51. package/build/src/semantic/validate.js +2 -2
  52. package/build/src/toolchains.d.ts +6 -0
  53. package/build/src/toolchains.d.ts.map +1 -1
  54. package/build/src/toolchains.js +2 -1
  55. package/build/src/zig-bindings.d.ts +10 -0
  56. package/build/src/zig-bindings.d.ts.map +1 -0
  57. package/build/src/zig-bindings.js +54 -0
  58. package/docs/android.md +7 -3
  59. package/docs/architecture.md +13 -5
  60. package/docs/flutter.md +47 -0
  61. package/docs/goals.md +1 -1
  62. package/docs/language-support.md +16 -5
  63. package/docs/parser-qualification.md +31 -1
  64. package/docs/source-maps.md +7 -3
  65. package/docs/testing.md +47 -4
  66. package/docs/zig.md +33 -0
  67. package/index.js +5 -5
  68. package/node_modules/semantifold-tree-sitter-zig-internal/LICENSE +15 -0
  69. package/node_modules/semantifold-tree-sitter-zig-internal/README.md +5 -0
  70. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/LICENSE +21 -0
  71. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/README.md +21 -0
  72. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/binding.gyp +29 -0
  73. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/bindings/node/binding.cc +20 -0
  74. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/bindings/node/binding_test.js +9 -0
  75. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/bindings/node/index.d.ts +28 -0
  76. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/bindings/node/index.js +11 -0
  77. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/grammar.js +900 -0
  78. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/package.json +57 -0
  79. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/prebuilds/darwin-arm64/@tree-sitter-grammars+tree-sitter-zig.node +0 -0
  80. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/prebuilds/darwin-x64/@tree-sitter-grammars+tree-sitter-zig.node +0 -0
  81. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/prebuilds/linux-arm64/@tree-sitter-grammars+tree-sitter-zig.node +0 -0
  82. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/prebuilds/linux-x64/@tree-sitter-grammars+tree-sitter-zig.node +0 -0
  83. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/prebuilds/win32-arm64/@tree-sitter-grammars+tree-sitter-zig.node +0 -0
  84. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/prebuilds/win32-x64/@tree-sitter-grammars+tree-sitter-zig.node +0 -0
  85. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/queries/folds.scm +23 -0
  86. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/queries/highlights.scm +291 -0
  87. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/queries/indents.scm +22 -0
  88. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/queries/injections.scm +10 -0
  89. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/src/grammar.json +6570 -0
  90. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/src/node-types.json +3178 -0
  91. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/src/parser.c +169829 -0
  92. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/src/tree_sitter/alloc.h +54 -0
  93. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/src/tree_sitter/array.h +291 -0
  94. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/src/tree_sitter/parser.h +266 -0
  95. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/tree-sitter-zig.wasm +0 -0
  96. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/@tree-sitter-grammars/tree-sitter-zig/tree-sitter.json +38 -0
  97. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/LICENSE +21 -0
  98. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/README.md +128 -0
  99. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/binding.gyp +80 -0
  100. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/index.js +916 -0
  101. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/package.json +76 -0
  102. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/prebuilds/darwin-arm64/tree-sitter.node +0 -0
  103. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/prebuilds/darwin-x64/tree-sitter.node +0 -0
  104. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/prebuilds/linux-arm64/tree-sitter.node +0 -0
  105. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/prebuilds/linux-x64/tree-sitter.node +0 -0
  106. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/prebuilds/win32-arm64/tree-sitter.node +0 -0
  107. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/prebuilds/win32-x64/tree-sitter.node +0 -0
  108. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/addon_data.h +47 -0
  109. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/binding.cc +35 -0
  110. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/conversions.cc +140 -0
  111. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/conversions.h +22 -0
  112. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/language.cc +106 -0
  113. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/language.h +17 -0
  114. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/logger.cc +70 -0
  115. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/logger.h +19 -0
  116. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/lookaheaditerator.cc +122 -0
  117. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/lookaheaditerator.h +33 -0
  118. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/node.cc +1088 -0
  119. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/node.h +30 -0
  120. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/parser.cc +306 -0
  121. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/parser.h +35 -0
  122. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/query.cc +397 -0
  123. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/query.h +40 -0
  124. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/tree.cc +316 -0
  125. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/tree.h +45 -0
  126. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/tree_cursor.cc +213 -0
  127. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/src/tree_cursor.h +52 -0
  128. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/tree-sitter.d.ts +1042 -0
  129. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/include/tree_sitter/api.h +1318 -0
  130. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.c +48 -0
  131. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.h +41 -0
  132. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/array.h +291 -0
  133. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/atomic.h +68 -0
  134. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/clock.h +146 -0
  135. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/error_costs.h +11 -0
  136. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.c +501 -0
  137. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.h +36 -0
  138. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/host.h +21 -0
  139. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.c +223 -0
  140. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.h +297 -0
  141. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/length.h +52 -0
  142. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.c +435 -0
  143. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.h +49 -0
  144. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lib.c +12 -0
  145. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/node.c +920 -0
  146. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.c +2165 -0
  147. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.h +266 -0
  148. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/point.h +62 -0
  149. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/portable/endian.h +206 -0
  150. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/query.c +4187 -0
  151. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reduce_action.h +34 -0
  152. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reusable_node.h +95 -0
  153. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.c +899 -0
  154. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.h +130 -0
  155. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.c +1066 -0
  156. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.h +399 -0
  157. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.c +170 -0
  158. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.h +31 -0
  159. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.c +712 -0
  160. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.h +48 -0
  161. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/ts_assert.h +11 -0
  162. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ICU_SHA +1 -0
  163. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/LICENSE +414 -0
  164. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/README.md +29 -0
  165. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ptypes.h +1 -0
  166. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/umachine.h +448 -0
  167. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/urename.h +1 -0
  168. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf.h +1 -0
  169. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf16.h +733 -0
  170. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf8.h +881 -0
  171. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode.h +83 -0
  172. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib-symbols.txt +24 -0
  173. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib.c +109 -0
  174. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/wasm-stdlib.h +1302 -0
  175. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.c +1859 -0
  176. package/node_modules/semantifold-tree-sitter-zig-internal/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.h +31 -0
  177. package/node_modules/semantifold-tree-sitter-zig-internal/package.json +21 -0
  178. package/node_modules/semantifold-tree-sitter-zig-internal/src/zig.js +134 -0
  179. package/package.json +11 -6
  180. package/src/backends/android.js +7 -3
  181. package/src/backends/dart.js +28 -15
  182. package/src/backends/flutter.js +1465 -0
  183. package/src/backends/identifiers.js +28 -4
  184. package/src/backends/ios.js +1 -1
  185. package/src/backends/native-validation.js +1 -1
  186. package/src/backends/program.js +3 -3
  187. package/src/backends/scalars.js +1 -0
  188. package/src/backends/shared.js +15 -11
  189. package/src/backends/zig-runtime.js +93 -0
  190. package/src/backends/zig-validation.js +68 -0
  191. package/src/backends/zig.js +579 -0
  192. package/src/frontends/scalars.js +1 -0
  193. package/src/frontends/zig-parser.js +20 -0
  194. package/src/frontends/zig.js +994 -0
  195. package/src/language-registry.js +40 -0
  196. package/src/mapping.js +1 -1
  197. package/src/semantic/provenance.js +2 -2
  198. package/src/semantic/types.js +41 -2
  199. package/src/semantic/validate.js +1 -1
  200. package/src/toolchains.js +1 -0
  201. package/src/zig-bindings.js +46 -0
@@ -0,0 +1,31 @@
1
+ #ifndef TREE_SITTER_WASM_H_
2
+ #define TREE_SITTER_WASM_H_
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
8
+ #include "tree_sitter/api.h"
9
+ #include "./parser.h"
10
+
11
+ bool ts_wasm_store_start(TSWasmStore *self, TSLexer *lexer, const TSLanguage *language);
12
+ void ts_wasm_store_reset(TSWasmStore *self);
13
+ bool ts_wasm_store_has_error(const TSWasmStore *self);
14
+
15
+ bool ts_wasm_store_call_lex_main(TSWasmStore *self, TSStateId state);
16
+ bool ts_wasm_store_call_lex_keyword(TSWasmStore *self, TSStateId state);
17
+
18
+ uint32_t ts_wasm_store_call_scanner_create(TSWasmStore *self);
19
+ void ts_wasm_store_call_scanner_destroy(TSWasmStore *self, uint32_t scanner_address);
20
+ bool ts_wasm_store_call_scanner_scan(TSWasmStore *self, uint32_t scanner_address, uint32_t valid_tokens_ix);
21
+ uint32_t ts_wasm_store_call_scanner_serialize(TSWasmStore *self, uint32_t scanner_address, char *buffer);
22
+ void ts_wasm_store_call_scanner_deserialize(TSWasmStore *self, uint32_t scanner, const char *buffer, unsigned length);
23
+
24
+ void ts_wasm_language_retain(const TSLanguage *self);
25
+ void ts_wasm_language_release(const TSLanguage *self);
26
+
27
+ #ifdef __cplusplus
28
+ }
29
+ #endif
30
+
31
+ #endif // TREE_SITTER_WASM_H_
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "semantifold-tree-sitter-zig-internal",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "description": "Private parser-neutral Zig snapshots using Semantifold's isolated Tree-sitter runtime",
6
+ "type": "module",
7
+ "main": "./src/zig.js",
8
+ "files": [
9
+ "src/zig.js",
10
+ "LICENSE",
11
+ "README.md"
12
+ ],
13
+ "engines": {
14
+ "node": ">=24"
15
+ },
16
+ "license": "ISC",
17
+ "dependencies": {
18
+ "@tree-sitter-grammars/tree-sitter-zig": "1.1.2",
19
+ "tree-sitter": "0.22.4"
20
+ }
21
+ }
@@ -0,0 +1,134 @@
1
+ // @ts-check
2
+
3
+ import Parser from "tree-sitter"
4
+ import ZigLanguage from "@tree-sitter-grammars/tree-sitter-zig"
5
+
6
+ /** @typedef {Readonly<{row: number, column: number}>} CstPosition */
7
+ /** @typedef {Readonly<{field: string | null, node: CstNode}>} CstChild */
8
+ /**
9
+ * @typedef {Readonly<{
10
+ * type: string,
11
+ * named: boolean,
12
+ * extra: boolean,
13
+ * error: boolean,
14
+ * missing: boolean,
15
+ * hasError: boolean,
16
+ * startIndex: number,
17
+ * endIndex: number,
18
+ * startPosition: CstPosition,
19
+ * endPosition: CstPosition,
20
+ * children: readonly CstChild[]
21
+ * }>} CstNode
22
+ */
23
+ /** @typedef {Readonly<{schema: "semantifold.parser-cst", version: 1, language: "zig", root: CstNode}>} CstSnapshot */
24
+
25
+ /**
26
+ * Parses the pinned Zig grammar with its isolated compatible runtime.
27
+ * @param {string} source - Caller-owned source text.
28
+ * @returns {CstSnapshot} Recursively frozen parser-neutral CST data.
29
+ */
30
+ export function parseCst(source) {
31
+ const parser = new Parser()
32
+
33
+ // The grammar's declaration intentionally hides its native language handle as unknown.
34
+ parser.setLanguage(/** @type {Parser.Language} */ (/** @type {unknown} */ (ZigLanguage)))
35
+ const tree = parser.parse(source)
36
+ const convertIndex = createIndexConverter(source, tree.rootNode.endIndex)
37
+ const lineStarts = createLineStarts(source)
38
+ const root = snapshotNode(tree.rootNode, convertIndex, lineStarts)
39
+
40
+ parser.reset()
41
+ return Object.freeze({language: "zig", root, schema: "semantifold.parser-cst", version: 1})
42
+ }
43
+
44
+ /**
45
+ * @param {import("tree-sitter").SyntaxNode} node
46
+ * @param {(index: number) => number} convertIndex
47
+ * @param {readonly number[]} lineStarts
48
+ * @returns {CstNode}
49
+ */
50
+ function snapshotNode(node, convertIndex, lineStarts) {
51
+ /** @type {CstChild[]} */
52
+ const children = []
53
+
54
+ for (let index = 0; index < node.childCount; index += 1) {
55
+ const child = node.child(index)
56
+
57
+ if (!child) throw new Error(`Zig Tree-sitter returned no child at index ${index}`)
58
+ children.push(Object.freeze({
59
+ field: node.fieldNameForChild(index) ?? null,
60
+ node: snapshotNode(child, convertIndex, lineStarts)
61
+ }))
62
+ }
63
+ const startIndex = convertIndex(node.startIndex)
64
+ const endIndex = convertIndex(node.endIndex)
65
+
66
+ return Object.freeze({
67
+ children: Object.freeze(children),
68
+ endIndex,
69
+ endPosition: positionForIndex(endIndex, lineStarts),
70
+ error: node.isError,
71
+ extra: node.isExtra,
72
+ hasError: node.hasError,
73
+ missing: node.isMissing,
74
+ named: node.isNamed,
75
+ startIndex,
76
+ startPosition: positionForIndex(startIndex, lineStarts),
77
+ type: node.type
78
+ })
79
+ }
80
+
81
+ /**
82
+ * Normalizes either UTF-8 byte offsets or UTF-16 offsets to UTF-16.
83
+ * @param {string} source
84
+ * @param {number} rootEndIndex
85
+ * @returns {(index: number) => number}
86
+ */
87
+ function createIndexConverter(source, rootEndIndex) {
88
+ if (rootEndIndex == source.length) return (index) => index
89
+ const utf8Length = Buffer.byteLength(source, "utf8")
90
+
91
+ if (rootEndIndex != utf8Length) throw new Error(`Unsupported Zig Tree-sitter index extent ${rootEndIndex} for source length ${source.length}`)
92
+ /** @type {Map<number, number>} */
93
+ const byteToUtf16 = new Map([[0, 0]])
94
+ let byteIndex = 0
95
+
96
+ for (let utf16Index = 0; utf16Index < source.length;) {
97
+ const codePoint = source.codePointAt(utf16Index)
98
+
99
+ if (codePoint == null) throw new Error(`Cannot read source code point at index ${utf16Index}`)
100
+ const character = String.fromCodePoint(codePoint)
101
+
102
+ byteIndex += Buffer.byteLength(character, "utf8")
103
+ utf16Index += character.length
104
+ byteToUtf16.set(byteIndex, utf16Index)
105
+ }
106
+ return (index) => {
107
+ const converted = byteToUtf16.get(index)
108
+
109
+ if (converted == null) throw new Error(`Zig Tree-sitter returned a non-boundary byte index ${index}`)
110
+ return converted
111
+ }
112
+ }
113
+
114
+ /** @param {string} source @returns {readonly number[]} */
115
+ function createLineStarts(source) {
116
+ const starts = [0]
117
+
118
+ for (let index = 0; index < source.length; index += 1) if (source[index] == "\n") starts.push(index + 1)
119
+ return starts
120
+ }
121
+
122
+ /** @param {number} index @param {readonly number[]} lineStarts @returns {CstPosition} */
123
+ function positionForIndex(index, lineStarts) {
124
+ let low = 0
125
+ let high = lineStarts.length
126
+
127
+ while (low + 1 < high) {
128
+ const middle = Math.floor((low + high) / 2)
129
+
130
+ if (/** @type {number} */ (lineStarts[middle]) <= index) low = middle
131
+ else high = middle
132
+ }
133
+ return Object.freeze({column: index - /** @type {number} */ (lineStarts[low]), row: low})
134
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "semantifold",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Language-neutral semantic code analysis, transformation, generation, and execution toolkit",
5
5
  "type": "module",
6
6
  "main": "build/index.js",
@@ -21,17 +21,18 @@
21
21
  "tsconfig.json"
22
22
  ],
23
23
  "workspaces": [
24
- "packages/tree-sitter-legacy"
24
+ "packages/tree-sitter-legacy",
25
+ "packages/tree-sitter-zig"
25
26
  ],
26
27
  "scripts": {
27
28
  "all-checks": "npm run lint && npm test",
28
- "build": "node scripts/clean-build.js && tsc && npm run build --workspace=semantifold-tree-sitter-legacy-workspace",
29
+ "build": "node scripts/clean-build.js && tsc && npm run build --workspace=semantifold-tree-sitter-legacy-workspace && npm run build --workspace=semantifold-tree-sitter-zig-workspace",
29
30
  "eslint": "eslint --max-warnings 0 .",
30
31
  "lint": "npm run verify:legacy-runtime && npm run eslint && npm run typecheck",
31
32
  "prepack": "npm run verify:legacy-runtime && npm run build",
32
- "pretest": "npm run verify:legacy-runtime && npm run build --workspace=semantifold-tree-sitter-legacy-workspace",
33
+ "pretest": "npm run verify:legacy-runtime && npm run build --workspace=semantifold-tree-sitter-legacy-workspace && npm run build --workspace=semantifold-tree-sitter-zig-workspace",
33
34
  "test": "velocious-test spec",
34
- "typecheck": "tsc --noEmit && npm run typecheck --workspace=semantifold-tree-sitter-legacy-workspace",
35
+ "typecheck": "tsc --noEmit && npm run typecheck --workspace=semantifold-tree-sitter-legacy-workspace && npm run typecheck --workspace=semantifold-tree-sitter-zig-workspace",
35
36
  "verify:legacy-runtime": "node scripts/verify-legacy-runtime.js"
36
37
  },
37
38
  "engines": {
@@ -58,6 +59,7 @@
58
59
  "comment-parser": "^1.4.1",
59
60
  "php-parser": "^3.7.0",
60
61
  "semantifold-tree-sitter-legacy-internal": "file:packages/tree-sitter-legacy/runtime",
62
+ "semantifold-tree-sitter-zig-internal": "file:packages/tree-sitter-zig/runtime",
61
63
  "tree-sitter": "0.25.1",
62
64
  "tree-sitter-c-sharp": "0.23.5",
63
65
  "tree-sitter-dart-orchard": "0.7.0",
@@ -68,10 +70,12 @@
68
70
  },
69
71
  "bundleDependencies": [
70
72
  "semantifold-tree-sitter-legacy-internal",
73
+ "semantifold-tree-sitter-zig-internal",
71
74
  "tree-sitter"
72
75
  ],
73
76
  "acceptDependencies": {
74
- "semantifold-tree-sitter-legacy-internal": "0.1.0"
77
+ "semantifold-tree-sitter-legacy-internal": "0.1.0",
78
+ "semantifold-tree-sitter-zig-internal": "0.1.0"
75
79
  },
76
80
  "devDependencies": {
77
81
  "@eslint/js": "^10.0.1",
@@ -84,6 +88,7 @@
84
88
  "eslint-plugin-jsdoc-tag-lines": "^1.0.1",
85
89
  "globals": "^17.0.0",
86
90
  "semantifold-tree-sitter-legacy-workspace": "0.1.0",
91
+ "semantifold-tree-sitter-zig-workspace": "0.1.0",
87
92
  "typescript": "^7.0.0",
88
93
  "yaml": "^2.9.0"
89
94
  }
@@ -17,7 +17,7 @@ const projectRoot = "generated/android-app"
17
17
  const generatorVersion = "0.4.0"
18
18
  /** @type {Readonly<Set<import("../semantic/types.js").SemanticLanguage>>} */
19
19
  const androidSourceLanguages = new Set([
20
- "php", "ruby", "javascript", "typescript", "java", "kotlin", "python", "csharp", "go", "c", "cpp", "rust", "swift", "dart"
20
+ "php", "ruby", "javascript", "typescript", "java", "kotlin", "python", "csharp", "go", "c", "cpp", "rust", "swift", "dart", "zig"
21
21
  ])
22
22
  const requestFields = new Set(["assets", "configuration", "language", "module", "program", "resources", "role"])
23
23
  const configurationFields = new Set([
@@ -74,7 +74,7 @@ const toolchain = Object.freeze({
74
74
  commandLineTools: "11076708",
75
75
  compileSdk: 35,
76
76
  emulator: "35.6.11",
77
- gradle: "8.13",
77
+ gradle: "8.14",
78
78
  java: "21.0.8",
79
79
  kotlin: "2.2.10",
80
80
  kotlinCompilerSha256: "302d1d8e671e5c3207e6ed62ff11fb555462a628e22a1158254dcaaf7e7394bc",
@@ -440,7 +440,11 @@ val semantifoldKotlinHome = providers.environmentVariable("SEMANTIFOLD_KOTLIN_HO
440
440
  ?: throw GradleException("SEMANTIFOLD_ANDROID_INFRASTRUCTURE: SEMANTIFOLD_KOTLIN_HOME is required")
441
441
  val semantifoldKotlinStdlib = file("$semantifoldKotlinHome/lib/kotlin-stdlib.jar")
442
442
  if (!semantifoldKotlinStdlib.isFile) {
443
- throw GradleException("SEMANTIFOLD_ANDROID_INFRASTRUCTURE: pinned Kotlin compile library is missing")
443
+ throw GradleException("SEMANTIFOLD_ANDROID_INFRASTRUCTURE: pinned Kotlin stdlib is missing")
444
+ }
445
+
446
+ dependencies {
447
+ androidTestImplementation(files(semantifoldKotlinStdlib))
444
448
  }
445
449
  val semantifoldAcceptanceRoot = providers.environmentVariable("SEMANTIFOLD_ANDROID_ACCEPTANCE_ROOT").orNull
446
450
  ?: throw GradleException("SEMANTIFOLD_ANDROID_INFRASTRUCTURE: SEMANTIFOLD_ANDROID_ACCEPTANCE_ROOT is required")
@@ -2,7 +2,7 @@
2
2
 
3
3
  import {unsupportedCapability} from "../diagnostic.js"
4
4
  import {finalizeMapping, toSourceMapV3} from "../mapping.js"
5
- import {emitExpression, validateBackendModule} from "./shared.js"
5
+ import {emitExpression, flatDartExpression, validateBackendModule} from "./shared.js"
6
6
  import {dartRuntime} from "./dart-runtime.js"
7
7
  import {emitScalarType} from "./scalars.js"
8
8
  import {SourceWriter} from "./writer.js"
@@ -23,7 +23,7 @@ export function generateDartPackage({filename, mapDirective, module, sourceMapFi
23
23
  if (mapDirective !== undefined || sourceMapFilename !== undefined) {
24
24
  unsupportedCapability("dart", "source-map filename or directive option", module.location)
25
25
  }
26
- const unreadLocals = findUnreadLocals(module)
26
+ const unreadLocals = findUnreadDartLocals(module)
27
27
  const writer = new SourceWriter({filename: "bin/program.dart", language: "dart", module, sources})
28
28
 
29
29
  emitProgram(module, writer, unreadLocals)
@@ -113,12 +113,12 @@ function emitProgram(module, writer, unreadLocals) {
113
113
  writer.synthetic(" ", "body spacing", [declaration], [path])
114
114
  writer.mapped("{", {mappingKind: "anchor", node: declaration.body, path: `${path}/body`})
115
115
  writer.synthetic("\n", "line break", [declaration], [path])
116
- emitBlock(writer, declaration.body, " ", `${path}/body`, unreadLocals)
116
+ emitDartBlock(writer, declaration.body, " ", `${path}/body`, unreadLocals)
117
117
  writer.mapped("}", {mappingKind: "anchor", node: declaration.body, path: `${path}/body`})
118
118
  writer.synthetic("\n", "line break", [declaration], [path])
119
119
  }
120
120
  writer.synthetic("\nvoid main() {\n", "Dart generated main scaffold", [module.entryPoint], ["/entryPoint"])
121
- emitBlock(writer, module.entryPoint.body, " ", "/entryPoint/body", unreadLocals)
121
+ emitDartBlock(writer, module.entryPoint.body, " ", "/entryPoint/body", unreadLocals)
122
122
  writer.synthetic("}\n", "Dart generated main scaffold", [module.entryPoint], ["/entryPoint"])
123
123
  }
124
124
 
@@ -129,11 +129,13 @@ function emitProgram(module, writer, unreadLocals) {
129
129
  * @param {string} indent Current indentation.
130
130
  * @param {string} path Exact semantic path.
131
131
  * @param {Set<import("../semantic/types.js").LocalDeclaration>} unreadLocals Locals requiring an analyzer-only read.
132
+ * @param {string} [printTarget] Target-owned output function spelling.
133
+ * @param {boolean} [multilinePrint] Whether target plumbing requires trailing-comma multiline calls.
132
134
  * @returns {void}
133
135
  */
134
- function emitBlock(writer, block, indent, path, unreadLocals) {
136
+ export function emitDartBlock(writer, block, indent, path, unreadLocals, printTarget = "print", multilinePrint = false) {
135
137
  block.statements.forEach((statement, index) =>
136
- emitStatement(writer, statement, indent, `${path}/statements/${index}`, unreadLocals))
138
+ emitStatement(writer, statement, indent, `${path}/statements/${index}`, unreadLocals, printTarget, multilinePrint))
137
139
  }
138
140
 
139
141
  /**
@@ -143,9 +145,11 @@ function emitBlock(writer, block, indent, path, unreadLocals) {
143
145
  * @param {string} indent Current indentation.
144
146
  * @param {string} path Exact semantic path.
145
147
  * @param {Set<import("../semantic/types.js").LocalDeclaration>} unreadLocals Locals requiring an analyzer-only read.
148
+ * @param {string} printTarget Target-owned output function spelling.
149
+ * @param {boolean} multilinePrint Whether target plumbing requires trailing-comma multiline calls.
146
150
  * @returns {void}
147
151
  */
148
- function emitStatement(writer, statement, indent, path, unreadLocals) {
152
+ function emitStatement(writer, statement, indent, path, unreadLocals, printTarget, multilinePrint) {
149
153
  writer.synthetic(indent, "indentation", [statement], [path])
150
154
  if (statement.kind == "LocalDeclaration") {
151
155
  if (!statement.mutable) writer.mapped("final", {mappingKind: "anchor", node: statement, path})
@@ -181,7 +185,7 @@ function emitStatement(writer, statement, indent, path, unreadLocals) {
181
185
  writer.synthetic("\n", "line break", [statement], [path])
182
186
  return
183
187
  }
184
- if (statement.kind == "IfStatement") return emitIf(writer, statement, indent, path, unreadLocals)
188
+ if (statement.kind == "IfStatement") return emitIf(writer, statement, indent, path, unreadLocals, printTarget, multilinePrint)
185
189
  if (statement.kind == "ReturnStatement") {
186
190
  writer.mapped("return", {mappingKind: "anchor", node: statement, path})
187
191
  if (statement.expression) {
@@ -193,10 +197,15 @@ function emitStatement(writer, statement, indent, path, unreadLocals) {
193
197
  return
194
198
  }
195
199
  if (statement.kind == "PrintStatement") {
196
- writer.mapped("print", {mappingKind: "anchor", node: statement, path})
197
- writer.mapped("(", {mappingKind: "anchor", node: statement, path})
200
+ const expandedPrint = multilinePrint && writer.column - 1 + printTarget.length +
201
+ flatDartExpression(writer, statement.expression).length + 3 > 80
202
+
203
+ if (printTarget == "print") {
204
+ writer.mapped(printTarget, {mappingKind: "anchor", name: "print", node: statement, path, role: "callee"})
205
+ } else writer.synthetic(printTarget, "Dart print plumbing", [statement], [path])
206
+ writer.synthetic(`(${expandedPrint ? `\n${indent} ` : ""}`, "Dart print plumbing", [statement], [path])
198
207
  emitExpression(writer, statement.expression, `${path}/expression`, "dart", identity)
199
- writer.mapped(");", {mappingKind: "anchor", node: statement, path})
208
+ writer.synthetic(expandedPrint ? `,\n${indent});` : ");", "Dart print plumbing", [statement], [path])
200
209
  writer.synthetic("\n", "line break", [statement], [path])
201
210
  return
202
211
  }
@@ -216,23 +225,27 @@ function emitStatement(writer, statement, indent, path, unreadLocals) {
216
225
  * @param {string} indent Current indentation.
217
226
  * @param {string} path Exact semantic path.
218
227
  * @param {Set<import("../semantic/types.js").LocalDeclaration>} unreadLocals Locals requiring an analyzer-only read.
228
+ * @param {string} printTarget Target-owned output function spelling.
229
+ * @param {boolean} multilinePrint Whether target plumbing requires trailing-comma multiline calls.
219
230
  * @returns {void}
220
231
  */
221
- function emitIf(writer, statement, indent, path, unreadLocals) {
232
+ function emitIf(writer, statement, indent, path, unreadLocals, printTarget, multilinePrint) {
222
233
  writer.mapped("if", {mappingKind: "anchor", node: statement, path})
223
234
  writer.synthetic(" (", "Dart conditional scaffold", [statement], [path])
224
235
  emitExpression(writer, statement.condition, `${path}/condition`, "dart", identity)
225
236
  writer.synthetic(") ", "Dart conditional scaffold", [statement], [path])
226
237
  writer.mapped("{", {mappingKind: "anchor", node: statement.consequent, path: `${path}/consequent`})
227
238
  writer.synthetic("\n", "line break", [statement], [path])
228
- emitBlock(writer, statement.consequent, `${indent} `, `${path}/consequent`, unreadLocals)
239
+ emitDartBlock(writer, statement.consequent, `${indent} `, `${path}/consequent`, unreadLocals, printTarget,
240
+ multilinePrint)
229
241
  writer.synthetic(indent, "indentation", [statement], [path])
230
242
  writer.mapped("}", {mappingKind: "anchor", node: statement.consequent, path: `${path}/consequent`})
231
243
  if (statement.alternate) {
232
244
  writer.synthetic(" else ", "Dart alternate scaffold", [statement], [path])
233
245
  writer.mapped("{", {mappingKind: "anchor", node: statement.alternate, path: `${path}/alternate`})
234
246
  writer.synthetic("\n", "line break", [statement], [path])
235
- emitBlock(writer, statement.alternate, `${indent} `, `${path}/alternate`, unreadLocals)
247
+ emitDartBlock(writer, statement.alternate, `${indent} `, `${path}/alternate`, unreadLocals, printTarget,
248
+ multilinePrint)
236
249
  writer.synthetic(indent, "indentation", [statement], [path])
237
250
  writer.mapped("}", {mappingKind: "anchor", node: statement.alternate, path: `${path}/alternate`})
238
251
  }
@@ -244,7 +257,7 @@ function emitIf(writer, statement, indent, path, unreadLocals) {
244
257
  * @param {import("../semantic/types.js").SemanticModule} module Validated semantic module.
245
258
  * @returns {Set<import("../semantic/types.js").LocalDeclaration>} Unread declaration identities.
246
259
  */
247
- function findUnreadLocals(module) {
260
+ export function findUnreadDartLocals(module) {
248
261
  /** @type {Set<import("../semantic/types.js").LocalDeclaration>} */
249
262
  const unread = new Set()
250
263