From: Tan Kian-ting Date: Sat, 30 Sep 2023 04:20:38 +0000 (+0800) Subject: fix parsing bug X-Git-Url: https://git.kianting.info/?a=commitdiff_plain;h=4fd4c8a4b69464bf1ac74af920175308656e6f6b;p=clo fix parsing bug --- diff --git a/src/index.js b/src/index.js index 23f1346..c424e5b 100644 --- a/src/index.js +++ b/src/index.js @@ -237,8 +237,14 @@ let circumfix = (f, signal) => (x) => { console.log("$$$" + repr(a.value.ast)); let inner = a.value.ast[a.value.ast.length - 2]; var ast_middle; + // the list should not be (%list) (%apply) (%lambda) etc. if (Array.isArray(inner)) { - ast_middle = inner; + if ('text' in inner[0] && (inner[0].text.slice(0, 1) != "%")) { + ast_middle = inner; + } + else { + ast_middle = [inner]; + } } else { ast_middle = [inner]; @@ -379,7 +385,7 @@ let expr = orDo(expr1, expr2); let tokens = tk.tokenize("1"); let tokens2 = tk.tokenize("1(2)"); let tokens3 = tk.tokenize("1(2)(3)"); -let tokens4 = tk.tokenize("2()(4)"); +let tokens4 = tk.tokenize("2()(4)(5,6)(7,8,9,10)"); //let tokens = tk.tokenize("(4-(3/4))"); //tk.tokenize(argv[2]); let tokensFiltered = tokens4.filter((x) => { diff --git a/src/index.ts b/src/index.ts index 3bf281f..46c4a72 100644 --- a/src/index.ts +++ b/src/index.ts @@ -250,13 +250,19 @@ let midfix = (f : Function, signal? : string) => (x : TokenMatcheePair)=>{ } let circumfix = (f : Function, signal? : string) => (x : TokenMatcheePair)=>{ - var a = f(x); + var a : tk.Maybe = f(x); if (a._tag == "Some"){ console.log("$$$"+repr(a.value.ast)); let inner = a.value.ast[a.value.ast.length-2]; var ast_middle : tkTree[]; + // the list should not be (%list) (%apply) (%lambda) etc. if (Array.isArray(inner)){ - ast_middle = inner; + if ('text' in inner[0] && (inner[0].text.slice(0,1) != "%")){ + ast_middle = inner; + } + else{ + ast_middle = [inner]; + } } else{ ast_middle = [inner]; @@ -442,7 +448,7 @@ let expr = orDo(expr1, expr2); let tokens = tk.tokenize("1"); let tokens2 = tk.tokenize("1(2)"); let tokens3 = tk.tokenize("1(2)(3)"); -let tokens4 = tk.tokenize("2()(4)"); +let tokens4 = tk.tokenize("2()(4)(5,6)(7,8,9,10)"); //let tokens = tk.tokenize("(4-(3/4))"); //tk.tokenize(argv[2]);