From 1599a9b65d63ceb9b5f2ba874ff00f96bd799fcc Mon Sep 17 00:00:00 2001 From: biglyderv Date: Fri, 29 Nov 2024 15:47:46 -0500 Subject: [PATCH] parser fixes --- index.mjs | 35 ++++++++++++++++++++--------------- objs.mjs | 6 +----- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/index.mjs b/index.mjs index f04a928..2380cfe 100644 --- a/index.mjs +++ b/index.mjs @@ -3,8 +3,7 @@ import objs from './objs.mjs'; let openers = { '{': '}', '[': ']', - '(': ')', - ';': ';' + '(': ')' }; let specialOpeners = { @@ -14,7 +13,8 @@ let specialOpeners = { function parser(str, context = '(') { str = str.replaceAll(/^\s+([^\s]+)/gms, '$1') str = str.replaceAll(/([^\s]+)\s+$/gms, '$1') - let nextI = str.search(/[^A-Za-z0-9 ]/gms); + + let nextI = str.search(/[^A-Za-z0-9;\s]/gms); if (context == '[') { nextI = str.search(/[\]]/); @@ -23,15 +23,14 @@ function parser(str, context = '(') { let nextChar = str[nextI]; - let special = specialOpeners[context] || ''; + let sliced = str.slice(0, nextI); + let rest = str.slice(nextI + 1); - let sp = (special == 'wildcard'); - - if (nextChar == openers[context] || !(openers[context] || sp)) { - return { context, str: str.slice(0, nextI), next: str.slice(nextI + 1), end: nextChar == openers[context] }; + if (nextChar == openers[context] || !(openers[context])) { + return { context, str: sliced, next: rest, end: nextChar == openers[context] || sliced.indexOf(';') != -1}; } else { let args = []; - let nextStr = str.slice(nextI + 1); + let nextStr = rest; while (nextStr && nextStr.length > 0) { args.push(parser(nextStr, nextChar)); @@ -43,7 +42,7 @@ function parser(str, context = '(') { if (a.end) break; } - let o = { context: str.slice(0, nextI), args, next: nextStr, op: context }; + let o = { context: sliced, args, next: nextStr, op: nextChar }; return o; } @@ -57,7 +56,11 @@ async function runner(script, objects) { if (op == '{') { h = (async function () { - return await runner(script.args[0], objects); + let output = false; + for (let a of script.args) { + output = await runner(a, objects); + } + return output; }) } else if (op == '(') { let arger = []; @@ -69,8 +72,8 @@ async function runner(script, objects) { if (arger.length == 1) arger = arger[0]; h = arger; - } else if (script.str) { - h = script.str; + } else if (op == '[') { + h = script.args[0].str; } if (typeof obj != 'function') { @@ -84,8 +87,10 @@ let data = parser(` on( [start] { - (echo(add([2][3]))) - (echo([Hello World!])) + echo(add([2][3])) + echo([Hello World!]) + echo(add([2][3])) + echo([Hello World!]) } ) `); diff --git a/objs.mjs b/objs.mjs index 4a1b500..f1f8669 100644 --- a/objs.mjs +++ b/objs.mjs @@ -1,9 +1,5 @@ let on = async function (input, objects) { - objects.events.addEventListener(input[0],(async function() { - for (let a of input[1]) { - await a(); - } - })); + objects.events.addEventListener(input[0],input[1]); } let echo = async function (input, objects) {