@arborium/groovy 2.4.0 → 2.4.3

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/grammar.js ADDED
@@ -0,0 +1,358 @@
1
+ let wasm;
2
+
3
+ function addHeapObject(obj) {
4
+ if (heap_next === heap.length) heap.push(heap.length + 1);
5
+ const idx = heap_next;
6
+ heap_next = heap[idx];
7
+
8
+ heap[idx] = obj;
9
+ return idx;
10
+ }
11
+
12
+ function dropObject(idx) {
13
+ if (idx < 132) return;
14
+ heap[idx] = heap_next;
15
+ heap_next = idx;
16
+ }
17
+
18
+ function getArrayJsValueFromWasm0(ptr, len) {
19
+ ptr = ptr >>> 0;
20
+ const mem = getDataViewMemory0();
21
+ const result = [];
22
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
23
+ result.push(takeObject(mem.getUint32(i, true)));
24
+ }
25
+ return result;
26
+ }
27
+
28
+ let cachedDataViewMemory0 = null;
29
+ function getDataViewMemory0() {
30
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
31
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
32
+ }
33
+ return cachedDataViewMemory0;
34
+ }
35
+
36
+ function getStringFromWasm0(ptr, len) {
37
+ ptr = ptr >>> 0;
38
+ return decodeText(ptr, len);
39
+ }
40
+
41
+ let cachedUint8ArrayMemory0 = null;
42
+ function getUint8ArrayMemory0() {
43
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
44
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
45
+ }
46
+ return cachedUint8ArrayMemory0;
47
+ }
48
+
49
+ function getObject(idx) { return heap[idx]; }
50
+
51
+ let heap = new Array(128).fill(undefined);
52
+ heap.push(undefined, null, true, false);
53
+
54
+ let heap_next = heap.length;
55
+
56
+ function passStringToWasm0(arg, malloc, realloc) {
57
+ if (realloc === undefined) {
58
+ const buf = cachedTextEncoder.encode(arg);
59
+ const ptr = malloc(buf.length, 1) >>> 0;
60
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
61
+ WASM_VECTOR_LEN = buf.length;
62
+ return ptr;
63
+ }
64
+
65
+ let len = arg.length;
66
+ let ptr = malloc(len, 1) >>> 0;
67
+
68
+ const mem = getUint8ArrayMemory0();
69
+
70
+ let offset = 0;
71
+
72
+ for (; offset < len; offset++) {
73
+ const code = arg.charCodeAt(offset);
74
+ if (code > 0x7F) break;
75
+ mem[ptr + offset] = code;
76
+ }
77
+ if (offset !== len) {
78
+ if (offset !== 0) {
79
+ arg = arg.slice(offset);
80
+ }
81
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
82
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
83
+ const ret = cachedTextEncoder.encodeInto(arg, view);
84
+
85
+ offset += ret.written;
86
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
87
+ }
88
+
89
+ WASM_VECTOR_LEN = offset;
90
+ return ptr;
91
+ }
92
+
93
+ function takeObject(idx) {
94
+ const ret = getObject(idx);
95
+ dropObject(idx);
96
+ return ret;
97
+ }
98
+
99
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
100
+ cachedTextDecoder.decode();
101
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
102
+ let numBytesDecoded = 0;
103
+ function decodeText(ptr, len) {
104
+ numBytesDecoded += len;
105
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
106
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
107
+ cachedTextDecoder.decode();
108
+ numBytesDecoded = len;
109
+ }
110
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
111
+ }
112
+
113
+ const cachedTextEncoder = new TextEncoder();
114
+
115
+ if (!('encodeInto' in cachedTextEncoder)) {
116
+ cachedTextEncoder.encodeInto = function (arg, view) {
117
+ const buf = cachedTextEncoder.encode(arg);
118
+ view.set(buf);
119
+ return {
120
+ read: arg.length,
121
+ written: buf.length
122
+ };
123
+ }
124
+ }
125
+
126
+ let WASM_VECTOR_LEN = 0;
127
+
128
+ /**
129
+ * Cancels an ongoing parse operation.
130
+ * @param {number} session
131
+ */
132
+ export function cancel(session) {
133
+ wasm.cancel(session);
134
+ }
135
+
136
+ /**
137
+ * Creates a new parser session and returns its ID.
138
+ * @returns {number}
139
+ */
140
+ export function create_session() {
141
+ const ret = wasm.create_session();
142
+ return ret >>> 0;
143
+ }
144
+
145
+ /**
146
+ * Frees a parser session.
147
+ * @param {number} session
148
+ */
149
+ export function free_session(session) {
150
+ wasm.free_session(session);
151
+ }
152
+
153
+ /**
154
+ * Returns the list of languages this grammar can inject into (e.g., for embedded languages).
155
+ * Most grammars return an empty array.
156
+ * @returns {string[]}
157
+ */
158
+ export function injection_languages() {
159
+ try {
160
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
161
+ wasm.injection_languages(retptr);
162
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
163
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
164
+ var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
165
+ wasm.__wbindgen_export(r0, r1 * 4, 4);
166
+ return v1;
167
+ } finally {
168
+ wasm.__wbindgen_add_to_stack_pointer(16);
169
+ }
170
+ }
171
+
172
+ /**
173
+ * Returns the language ID for this grammar plugin.
174
+ * @returns {string}
175
+ */
176
+ export function language_id() {
177
+ let deferred1_0;
178
+ let deferred1_1;
179
+ try {
180
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
181
+ wasm.language_id(retptr);
182
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
183
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
184
+ deferred1_0 = r0;
185
+ deferred1_1 = r1;
186
+ return getStringFromWasm0(r0, r1);
187
+ } finally {
188
+ wasm.__wbindgen_add_to_stack_pointer(16);
189
+ wasm.__wbindgen_export(deferred1_0, deferred1_1, 1);
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Parses the text in a session and returns the result as a JS value.
195
+ *
196
+ * The result is a JavaScript object representation of ParseResult containing spans and injections.
197
+ * @param {number} session
198
+ * @returns {any}
199
+ */
200
+ export function parse(session) {
201
+ try {
202
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
203
+ wasm.parse(retptr, session);
204
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
205
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
206
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
207
+ if (r2) {
208
+ throw takeObject(r1);
209
+ }
210
+ return takeObject(r0);
211
+ } finally {
212
+ wasm.__wbindgen_add_to_stack_pointer(16);
213
+ }
214
+ }
215
+
216
+ /**
217
+ * Sets the text for a parser session.
218
+ * @param {number} session
219
+ * @param {string} text
220
+ */
221
+ export function set_text(session, text) {
222
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
223
+ const len0 = WASM_VECTOR_LEN;
224
+ wasm.set_text(session, ptr0, len0);
225
+ }
226
+
227
+ const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
228
+
229
+ async function __wbg_load(module, imports) {
230
+ if (typeof Response === 'function' && module instanceof Response) {
231
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
232
+ try {
233
+ return await WebAssembly.instantiateStreaming(module, imports);
234
+ } catch (e) {
235
+ const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
236
+
237
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
238
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
239
+
240
+ } else {
241
+ throw e;
242
+ }
243
+ }
244
+ }
245
+
246
+ const bytes = await module.arrayBuffer();
247
+ return await WebAssembly.instantiate(bytes, imports);
248
+ } else {
249
+ const instance = await WebAssembly.instantiate(module, imports);
250
+
251
+ if (instance instanceof WebAssembly.Instance) {
252
+ return { instance, module };
253
+ } else {
254
+ return instance;
255
+ }
256
+ }
257
+ }
258
+
259
+ function __wbg_get_imports() {
260
+ const imports = {};
261
+ imports.wbg = {};
262
+ imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
263
+ throw new Error(getStringFromWasm0(arg0, arg1));
264
+ };
265
+ imports.wbg.__wbg_new_1ba21ce319a06297 = function() {
266
+ const ret = new Object();
267
+ return addHeapObject(ret);
268
+ };
269
+ imports.wbg.__wbg_new_25f239778d6112b9 = function() {
270
+ const ret = new Array();
271
+ return addHeapObject(ret);
272
+ };
273
+ imports.wbg.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
274
+ getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
275
+ };
276
+ imports.wbg.__wbg_set_7df433eea03a5c14 = function(arg0, arg1, arg2) {
277
+ getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
278
+ };
279
+ imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
280
+ // Cast intrinsic for `Ref(String) -> Externref`.
281
+ const ret = getStringFromWasm0(arg0, arg1);
282
+ return addHeapObject(ret);
283
+ };
284
+ imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
285
+ // Cast intrinsic for `F64 -> Externref`.
286
+ const ret = arg0;
287
+ return addHeapObject(ret);
288
+ };
289
+ imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
290
+ const ret = getObject(arg0);
291
+ return addHeapObject(ret);
292
+ };
293
+ imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
294
+ takeObject(arg0);
295
+ };
296
+
297
+ return imports;
298
+ }
299
+
300
+ function __wbg_finalize_init(instance, module) {
301
+ wasm = instance.exports;
302
+ __wbg_init.__wbindgen_wasm_module = module;
303
+ cachedDataViewMemory0 = null;
304
+ cachedUint8ArrayMemory0 = null;
305
+
306
+
307
+
308
+ return wasm;
309
+ }
310
+
311
+ function initSync(module) {
312
+ if (wasm !== undefined) return wasm;
313
+
314
+
315
+ if (typeof module !== 'undefined') {
316
+ if (Object.getPrototypeOf(module) === Object.prototype) {
317
+ ({module} = module)
318
+ } else {
319
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
320
+ }
321
+ }
322
+
323
+ const imports = __wbg_get_imports();
324
+ if (!(module instanceof WebAssembly.Module)) {
325
+ module = new WebAssembly.Module(module);
326
+ }
327
+ const instance = new WebAssembly.Instance(module, imports);
328
+ return __wbg_finalize_init(instance, module);
329
+ }
330
+
331
+ async function __wbg_init(module_or_path) {
332
+ if (wasm !== undefined) return wasm;
333
+
334
+
335
+ if (typeof module_or_path !== 'undefined') {
336
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
337
+ ({module_or_path} = module_or_path)
338
+ } else {
339
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
340
+ }
341
+ }
342
+
343
+ if (typeof module_or_path === 'undefined') {
344
+ module_or_path = new URL('arborium_groovy_plugin_bg.wasm', import.meta.url);
345
+ }
346
+ const imports = __wbg_get_imports();
347
+
348
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
349
+ module_or_path = fetch(module_or_path);
350
+ }
351
+
352
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
353
+
354
+ return __wbg_finalize_init(instance, module);
355
+ }
356
+
357
+ export { initSync };
358
+ export default __wbg_init;
Binary file
package/package.json CHANGED
@@ -1,17 +1,26 @@
1
1
  {
2
- "name": "@arborium/groovy",
3
- "version": "2.4.0",
2
+ "author": "Amos Wenger <amos@bearcove.eu>",
3
+ "bugs": {
4
+ "url": "https://github.com/bearcove/arborium/issues"
5
+ },
4
6
  "description": "Syntax highlighting for Groovy, powered by WebAssembly",
5
- "type": "module",
6
- "main": "./grammar.js",
7
- "module": "./grammar.js",
7
+ "engines": {
8
+ "node": ">=18"
9
+ },
8
10
  "exports": {
9
11
  ".": "./grammar.js",
10
12
  "./grammar.js": "./grammar.js",
11
13
  "./grammar_bg.wasm": "./grammar_bg.wasm"
12
14
  },
13
- "files": ["grammar.js", "grammar_bg.wasm"],
14
- "sideEffects": false,
15
+ "files": [
16
+ "grammar.js",
17
+ "grammar_bg.wasm"
18
+ ],
19
+ "funding": {
20
+ "type": "github",
21
+ "url": "https://github.com/sponsors/fasterthanlime"
22
+ },
23
+ "homepage": "https://github.com/bearcove/arborium",
15
24
  "keywords": [
16
25
  "arborium",
17
26
  "syntax-highlighting",
@@ -20,24 +29,18 @@
20
29
  "Groovy",
21
30
  "wasm"
22
31
  ],
23
- "author": "Amos Wenger <amos@bearcove.eu>",
24
32
  "license": "MIT OR Apache-2.0",
33
+ "main": "./grammar.js",
34
+ "module": "./grammar.js",
35
+ "name": "@arborium/groovy",
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
25
39
  "repository": {
26
40
  "type": "git",
27
41
  "url": "https://github.com/bearcove/arborium"
28
42
  },
29
- "homepage": "https://github.com/bearcove/arborium",
30
- "bugs": {
31
- "url": "https://github.com/bearcove/arborium/issues"
32
- },
33
- "funding": {
34
- "type": "github",
35
- "url": "https://github.com/sponsors/fasterthanlime"
36
- },
37
- "engines": {
38
- "node": ">=18"
39
- },
40
- "publishConfig": {
41
- "access": "public"
42
- }
43
+ "sideEffects": false,
44
+ "type": "module",
45
+ "version": "2.4.3"
43
46
  }
package/README.md DELETED
@@ -1,65 +0,0 @@
1
- # @arborium/groovy
2
-
3
- [![Part of Arborium](https://img.shields.io/badge/🌳_Arborium-grammar_collection-228B22)](https://github.com/bearcove/arborium)
4
- [![npm](https://img.shields.io/npm/v/@arborium/groovy)](https://www.npmjs.com/package/@arborium/groovy)
5
- [![license](https://img.shields.io/npm/l/@arborium/groovy)](https://github.com/bearcove/arborium)
6
-
7
- Syntax highlighting for [Groovy](https://en.wikipedia.org/wiki/Apache_Groovy), powered by WebAssembly and [tree-sitter](https://tree-sitter.github.io/).
8
-
9
- > Apache Groovy is a dynamic language for the JVM with syntax inspired by Java, featuring optional typing, closures, and powerful DSL capabilities that make it ideal for scripting and build tools like Gradle.
10
-
11
-
12
- | | |
13
- |---|---|
14
- | **Inventor** | James Strachan |
15
- | **Year** | 2003 |
16
-
17
- ## Installation
18
-
19
- ```bash
20
- npm install @arborium/groovy
21
- ```
22
-
23
- ## Usage
24
-
25
- ```javascript
26
- import { createHighlighter } from '@arborium/arborium';
27
- import * as grammar from '@arborium/groovy';
28
-
29
- const highlighter = await createHighlighter();
30
- await highlighter.loadGrammar(grammar);
31
-
32
- const html = highlighter.highlight(code, 'groovy');
33
- ```
34
-
35
- ## What's included
36
-
37
- This package contains:
38
-
39
- - `grammar.js` - ES module that loads the WebAssembly grammar
40
- - `grammar.d.ts` - TypeScript type definitions
41
- - `grammar_bg.wasm` - The tree-sitter grammar compiled to WebAssembly
42
-
43
- ## About Arborium
44
-
45
- This package is part of [**Arborium**](https://github.com/bearcove/arborium), a collection of tree-sitter grammars for syntax highlighting, maintained by [Amos Wenger](https://fasterthanli.me).
46
-
47
- Arborium provides:
48
- - **98+ language grammars** compiled to WebAssembly
49
- - **Browser and Node.js support** via ES modules
50
- - **TypeScript definitions** for all packages
51
- - **Consistent API** across all grammars
52
-
53
- ## Related packages
54
-
55
- - [`@arborium/arborium`](https://www.npmjs.com/package/@arborium/arborium) - Core highlighter library
56
- - [All @arborium packages](https://www.npmjs.com/org/arborium)
57
-
58
- ## License
59
-
60
- MIT OR Apache-2.0
61
-
62
- ## Links
63
-
64
- - [GitHub](https://github.com/bearcove/arborium)
65
- - [Issues](https://github.com/bearcove/arborium/issues)