X-Git-Url: https://git.kianting.info/?a=blobdiff_plain;f=src%2Findex.ts;fp=src%2Findex.ts;h=90cdad4698b3734aeda9cb9582e57e42daade80a;hb=3441b825eb0f2be5ea74227fb1eaa90df236e563;hp=599d32a9040ef78c4127eff01698f54b0aa95ab1;hpb=f0777117c45a12375c4538e33c18f7bb4d0fc6f7;p=uann diff --git a/src/index.ts b/src/index.ts index 599d32a..90cdad4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -261,9 +261,6 @@ let circumfix = (f : Function, signal? : string) => (x : TokenMatcheePair)=>{ return a; } -/** - * TODO: 12(13)(14) only parsed with only 12(13) - */ /** single1 = tInt | "(" expr ")"*/ let single1 = circumfix((x : TokenMatcheePair) => thenDo(thenDo(thenDo(tk.toSome(x), tLParen), expr), tRParen), "fac1"); @@ -277,42 +274,116 @@ let single = orDo(single1, single2); * */ +/** callees = "(" args ")" | "(" ")" */ -/** fac = single ["(" single ")"]? | single - * Issue1 to be fixed. - */ -let fac1Appliee = circumfix((x : TokenMatcheePair) => thenDo(thenDo(thenDo(tk.toSome(x), tLParen), tInt), tRParen), "fac1"); -let fac1 = (x : TokenMatcheePair) => - { - let raw = thenDo(thenDo(toSome(x), single), OnceOrMoreDo(fac1Appliee)); - - - if (raw._tag == "Some"){ +let callees1 = circumfix((x : TokenMatcheePair) => + thenDo(thenDo(thenDo(tk.toSome(x), tLParen), tInt), tRParen), "callees1"); +let callees2 = (x: TokenMatcheePair)=>{ + let ret = thenDo(thenDo(tk.toSome(x), tLParen), tRParen); + if (ret._tag == "Some"){ + let new_ast : tkTree[] = [[]]; + ret.value.ast = new_ast; + } + + return ret}; +let callees = orDo(callees1, callees2); - var result : tkTree = raw.value.ast[0]; - let applyToken : tk.Token = {text: '%apply', ln:0, col:0}; - for (var i=1; i{ + var ret = thenDo(thenDo(tk.toSome(x), callees), facAux); + if (ret._tag == "Some"){ + console.log("1232345"+repr(tkTreeToSExp(ret.value.ast[ret.value.ast.length-1]))); + let last1 = ret.value.ast[ret.value.ast.length-1]; + let last2 = ret.value.ast[ret.value.ast.length-2]; - - return raw; + let b : tkTree[] = [applyToken]; + ret.value.ast = [b.concat([last2, last1])]; + console.log("11111"+repr(tkTreeToSExp(ret.value.ast))); + }; + +return ret;} +let facAux2 = callees; +let facAux = orDo(facAux1, facAux2); + + + +/** fac = single facAux | single + * Issue1 to be fixed. + */ +let fac1 = (x: TokenMatcheePair)=>{ + var ret = thenDo(thenDo(tk.toSome(x), single),facAux); + if(ret._tag == "Some"){ + console.log("777"+repr(tkTreeToSExp(ret.value.ast))); + ret.value.ast = [applyToken, ret.value.ast[ret.value.ast.length-2], + ret.value.ast[ret.value.ast.length-1]]; + ret.value.ast; + rearrangeTree(ret.value.ast); + console.log("888"+repr(tkTreeToSExp(ret.value.ast))); + + } + + return ret;}; let fac2 = single; let fac = orDo(fac1, fac2); +/** + * rearrangeTree : for applyToken subtree from right-combination to + * left-combination + * @input x a ast + * @return another ast + */ +function rearrangeTree(x: any) : any { + + if (x !== undefined){ + for (var i=1;i