@willbooster/web-tree-sitter 1.0.41 → 1.1.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.
package/README.md CHANGED
@@ -42,6 +42,31 @@ const JavaScript = await Language.load(javascript);
42
42
  To use the debug version of the library in Node.js, import `@willbooster/web-tree-sitter/debug` instead. It loads the
43
43
  debug versions of the `.js` and `.wasm` files, which include debug symbols and assertions.
44
44
 
45
+ ### Grammar DSL types
46
+
47
+ `@willbooster/web-tree-sitter/dsl` supplies types for the globals injected by the Tree-sitter CLI.
48
+ Bind those globals locally in a CommonJS grammar:
49
+
50
+ ```js
51
+ // @ts-check
52
+ const { grammar, repeat1, RustRegex } =
53
+ /** @type {typeof globalThis & import('@willbooster/web-tree-sitter/dsl').DSL} */ (globalThis);
54
+
55
+ module.exports = grammar({
56
+ name: 'example',
57
+ rules: {
58
+ source_file: ($) => repeat1($.word),
59
+ word: () => new RustRegex('[a-z]+'),
60
+ },
61
+ });
62
+ ```
63
+
64
+ The declaration module exports types. The CLI supplies the functions at runtime.
65
+ This pattern keeps the declarations local when composing grammars with other DSL types.
66
+
67
+ For grammar verification, enable `strict` and `noUncheckedIndexedAccess` so an unknown rule lookup is rejected.
68
+ Use the injected `sym(name)` helper for intentionally synthetic alias or external names.
69
+
45
70
  ### Basic Usage
46
71
 
47
72
  First, create a parser:
@@ -87,7 +112,7 @@ console.log(callExpression.type, callExpression.startPosition, callExpression.en
87
112
 
88
113
  ### Editing
89
114
 
90
- If your source code *changes*, you can update the syntax tree. This will take less time than the first parse.
115
+ If your source code _changes_, you can update the syntax tree. This will take less time than the first parse.
91
116
 
92
117
  ```javascript
93
118
  // Replace 'let' with 'const'
@@ -97,9 +122,9 @@ tree.edit({
97
122
  startIndex: 0,
98
123
  oldEndIndex: 3,
99
124
  newEndIndex: 5,
100
- startPosition: {row: 0, column: 0},
101
- oldEndPosition: {row: 0, column: 3},
102
- newEndPosition: {row: 0, column: 5},
125
+ startPosition: { row: 0, column: 0 },
126
+ oldEndPosition: { row: 0, column: 3 },
127
+ newEndPosition: { row: 0, column: 5 },
103
128
  });
104
129
 
105
130
  const newTree = parser.parse(newSourceCode, tree);
@@ -111,10 +136,7 @@ If your text is stored in a data structure other than a single string, you can p
111
136
  instead of a string:
112
137
 
113
138
  ```javascript
114
- const sourceLines = [
115
- 'let x = 1;',
116
- 'console.log(x);'
117
- ];
139
+ const sourceLines = ['let x = 1;', 'console.log(x);'];
118
140
 
119
141
  const tree = parser.parse((index, position) => {
120
142
  let line = sourceLines[position.row];
@@ -227,6 +249,10 @@ and not `http://localhost:3000/_next/static/chunks/pages/web-tree-sitter.wasm`.
227
249
 
228
250
  For more information on the module options you can pass in, see the [emscripten documentation][emscripten-module-options].
229
251
 
252
+ ## Development
253
+
254
+ For changes to the bindings or DSL declarations, read [the contributor guide](https://github.com/WillBooster/tree-sitter/blob/main/lib/binding_web/CONTRIBUTING.md).
255
+
230
256
  [emscripten-module-options]: https://emscripten.org/docs/api_reference/module.html#affecting-execution
231
257
  [gh release js]: https://github.com/tree-sitter/tree-sitter-javascript/releases/latest
232
258
  [releases]: https://github.com/WillBooster/tree-sitter/releases
Binary file