fix parsing bug

This commit is contained in:
Tan, Kian-ting 2023-09-30 12:20:38 +08:00
parent 40a1652583
commit 4fd4c8a4b6
2 changed files with 17 additions and 5 deletions

View file

@ -237,12 +237,18 @@ 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)) {
if ('text' in inner[0] && (inner[0].text.slice(0, 1) != "%")) {
ast_middle = inner;
}
else {
ast_middle = [inner];
}
}
else {
ast_middle = [inner];
}
let new_ast = [ast_middle];
a.value.ast = new_ast;
}
@ -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) => {

View file

@ -250,17 +250,23 @@ let midfix = (f : Function, signal? : string) => (x : TokenMatcheePair)=>{
}
let circumfix = (f : Function, signal? : string) => (x : TokenMatcheePair)=>{
var a = f(x);
var a : tk.Maybe<TokenMatcheePair> = 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)){
if ('text' in inner[0] && (inner[0].text.slice(0,1) != "%")){
ast_middle = inner;
}
else{
ast_middle = [inner];
}
}
else{
ast_middle = [inner];
}
let new_ast = [ast_middle];
a.value.ast = new_ast;
}
@ -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]);