Module

x/melody/melody_wasm.js

Melody is a language that compiles to regular expressions and aims to be more easily readable and maintainable
Latest
File


const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
let cachedUint8Memory0 = null;
function getUint8Memory0() { if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) { cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); } return cachedUint8Memory0;}
function getStringFromWasm0(ptr, len) { ptr = ptr >>> 0; return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));}
const heap = new Array(128).fill(undefined);
heap.push(undefined, null, true, false);
let heap_next = heap.length;
function addHeapObject(obj) { if (heap_next === heap.length) heap.push(heap.length + 1); const idx = heap_next; heap_next = heap[idx];
heap[idx] = obj; return idx;}
function getObject(idx) { return heap[idx]; }
function dropObject(idx) { if (idx < 132) return; heap[idx] = heap_next; heap_next = idx;}
function takeObject(idx) { const ret = getObject(idx); dropObject(idx); return ret;}
let WASM_VECTOR_LEN = 0;
const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
const encodeString = function (arg, view) { return cachedTextEncoder.encodeInto(arg, view);};
function passStringToWasm0(arg, malloc, realloc) {
if (realloc === undefined) { const buf = cachedTextEncoder.encode(arg); const ptr = malloc(buf.length, 1) >>> 0; getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf); WASM_VECTOR_LEN = buf.length; return ptr; }
let len = arg.length; let ptr = malloc(len, 1) >>> 0;
const mem = getUint8Memory0();
let offset = 0;
for (; offset < len; offset++) { const code = arg.charCodeAt(offset); if (code > 0x7F) break; mem[ptr + offset] = code; }
if (offset !== len) { if (offset !== 0) { arg = arg.slice(offset); } ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; const view = getUint8Memory0().subarray(ptr + offset, ptr + len); const ret = encodeString(arg, view);
offset += ret.written; }
WASM_VECTOR_LEN = offset; return ptr;}
let cachedInt32Memory0 = null;
function getInt32Memory0() { if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); } return cachedInt32Memory0;}/****Compiles Melody source code to a regular expression**# Errors**Throws an error if a compilation error is encountered**# Example**```js*const source = `* <start>;** option of "v";** capture major {* some of <digit>;* }** ".";** capture minor {* some of <digit>;* }** ".";** capture patch {* some of <digit>;* }** <end>;*`;**try {* const output = compiler(source);* new RegExp(output).test("v1.1.1"); // true*} catch (error) {* // handle compilation error*}*```* @param {string} source* @returns {string}*/export function compiler(source) { let deferred3_0; let deferred3_1; try { const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1); const len0 = WASM_VECTOR_LEN; wasm.compiler(retptr, ptr0, len0); var r0 = getInt32Memory0()[retptr / 4 + 0]; var r1 = getInt32Memory0()[retptr / 4 + 1]; var r2 = getInt32Memory0()[retptr / 4 + 2]; var r3 = getInt32Memory0()[retptr / 4 + 3]; var ptr2 = r0; var len2 = r1; if (r3) { ptr2 = 0; len2 = 0; throw takeObject(r2); } deferred3_0 = ptr2; deferred3_1 = len2; return getStringFromWasm0(ptr2, len2); } finally { wasm.__wbindgen_add_to_stack_pointer(16); wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1); }}
/***/export function main() { wasm.main();}
const imports = { __wbindgen_placeholder__: { __wbindgen_error_new: function(arg0, arg1) { const ret = new Error(getStringFromWasm0(arg0, arg1)); return addHeapObject(ret); }, __wbg_new_abda76e883ba8a5f: function() { const ret = new Error(); return addHeapObject(ret); }, __wbg_stack_658279fe44541cf6: function(arg0, arg1) { const ret = getObject(arg1).stack; const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1); const len1 = WASM_VECTOR_LEN; getInt32Memory0()[arg0 / 4 + 1] = len1; getInt32Memory0()[arg0 / 4 + 0] = ptr1; }, __wbg_error_f851667af71bcfc6: function(arg0, arg1) { let deferred0_0; let deferred0_1; try { deferred0_0 = arg0; deferred0_1 = arg1; console.error(getStringFromWasm0(arg0, arg1)); } finally { wasm.__wbindgen_export_2(deferred0_0, deferred0_1, 1); } }, __wbindgen_object_drop_ref: function(arg0) { takeObject(arg0); }, },
};
const wasm_url = new URL('melody_wasm_bg.wasm', import.meta.url);let wasmCode = '';switch (wasm_url.protocol) { case 'file:': wasmCode = await Deno.readFile(wasm_url); break case 'https:': case 'http:': wasmCode = await (await fetch(wasm_url)).arrayBuffer(); break default: throw new Error(`Unsupported protocol: ${wasm_url.protocol}`);}
const wasmInstance = (await WebAssembly.instantiate(wasmCode, imports)).instance;const wasm = wasmInstance.exports;
wasm.__wbindgen_start();