tree-sitter-scpi 0.1.0 → 0.1.4

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
@@ -32,6 +32,16 @@ Or using tree-sitter CLI directly:
32
32
  tree-sitter generate
33
33
  ```
34
34
 
35
+ ### Building WASM
36
+
37
+ To build the WebAssembly version for use in VS Code extensions or web applications:
38
+
39
+ ```bash
40
+ npm run build-wasm
41
+ ```
42
+
43
+ This generates `tree-sitter-scpi.wasm` in the root directory. The WASM file is automatically built before publishing to npm.
44
+
35
45
  ## Testing
36
46
 
37
47
  Run the test suite:
@@ -94,6 +104,8 @@ Multiple commands can be chained on a single line using semicolons:
94
104
 
95
105
  ## Example Usage
96
106
 
107
+ ### Node.js (Native Binding)
108
+
97
109
  ```javascript
98
110
  const Parser = require('tree-sitter');
99
111
  const SCPI = require('tree-sitter-scpi');
@@ -109,6 +121,40 @@ const tree = parser.parse(sourceCode);
109
121
  console.log(tree.rootNode.toString());
110
122
  ```
111
123
 
124
+ ### WebAssembly (for VS Code Extensions and Web)
125
+
126
+ For VS Code extensions or web applications, use the WASM version with `web-tree-sitter`:
127
+
128
+ ```javascript
129
+ const Parser = require('web-tree-sitter');
130
+
131
+ async function initializeParser() {
132
+ await Parser.init();
133
+ const SCPI = await Parser.Language.load(
134
+ require.resolve('tree-sitter-scpi/tree-sitter-scpi.wasm')
135
+ );
136
+ const parser = new Parser();
137
+ parser.setLanguage(SCPI);
138
+ return parser;
139
+ }
140
+
141
+ // Usage
142
+ initializeParser().then(parser => {
143
+ const sourceCode = `*IDN?
144
+ :MEASure:VOLTage?
145
+ :SOURce:VOLTage 5.0`;
146
+
147
+ const tree = parser.parse(sourceCode);
148
+ console.log(tree.rootNode.toString());
149
+ });
150
+ ```
151
+
152
+ **Note**: Make sure to install `web-tree-sitter` as a dependency in your project:
153
+
154
+ ```bash
155
+ npm install web-tree-sitter
156
+ ```
157
+
112
158
  ## Grammar Rules
113
159
 
114
160
  The grammar defines the following main rules:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tree-sitter-scpi",
3
- "version": "0.1.0",
3
+ "version": "0.1.4",
4
4
  "description": "Tree-sitter grammar for SCPI (Standard Commands for Programmable Instruments)",
5
5
  "main": "bindings/node",
6
6
  "keywords": [
@@ -21,17 +21,22 @@
21
21
  "src/",
22
22
  "bindings/node/",
23
23
  "binding.gyp",
24
- "README.md"
24
+ "README.md",
25
+ "tree-sitter-scpi.wasm"
25
26
  ],
26
27
  "dependencies": {
27
28
  "nan": "^2.17.0"
28
29
  },
29
30
  "devDependencies": {
30
- "tree-sitter-cli": "^0.20.0"
31
+ "tree-sitter-cli": "^0.20.0",
32
+ "node-gyp": "^10.0.0"
31
33
  },
32
34
  "scripts": {
33
35
  "generate": "tree-sitter generate",
34
- "test": "tree-sitter test"
36
+ "test": "tree-sitter test",
37
+ "build-wasm": "tree-sitter build-wasm",
38
+ "build:native": "node-gyp rebuild",
39
+ "prepublishOnly": "npm run build-wasm"
35
40
  },
36
41
  "tree-sitter": [
37
42
  {
@@ -42,4 +47,3 @@
42
47
  }
43
48
  ]
44
49
  }
45
-
Binary file