Skip to content

Instantly share code, notes, and snippets.

@Vurv78
Created January 17, 2022 21:28
Show Gist options
  • Save Vurv78/556d5e739299f8798ae48c8c550eb106 to your computer and use it in GitHub Desktop.
Save Vurv78/556d5e739299f8798ae48c8c550eb106 to your computer and use it in GitHub Desktop.
const rgx = /virtual\s+(\w+)\s*\*?\s+\*?(\w+)\(([^)]+)\)/g;
const foo = document.getElementById("area");
const textarea = document.getElementById("code");
const btn = document.getElementById("btn");
btn.onclick = function() {
const code = textarea.value;
let submissions = code.matchAll(rgx);
const outputs = [];
let ind = 0;
for(const [full, ret, name, params] of submissions) {
outputs.push(`#[virtual_index(${ind})] pub fn ${name}(${params}) -> ${ret} {}`);
ind++;
}
foo.value = outputs.join("\n");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment