-let midfix = (f, signal) => (x) => {
- var a = f(x);
- if (a._tag == "Some") {
- let ast_tail = slice(a.value.ast, a.value.ast.length - 3);
- let new_ast = [ast_tail];
- a.value.ast = new_ast;
- console.log("+" + signal + "+" + repr(a));
- }
- return a;
-};
-let circumfix = (f, signal) => (x) => {
- var a = f(x);
- if (a._tag == "Some") {
- let inner = a.value.ast[a.value.ast.length - 2];
- let ast_middle = [inner];
- let new_ast = [ast_middle];
- a.value.ast = new_ast;
- }
- return a;
-};
-/**
- * TODO: 12(13)(14) only parsed with only 12(13)
- */
-/** single1 = tInt | "(" expr ")"*/
-let single1 = circumfix((x) => thenDo(thenDo(thenDo(tk.toSome(x), tLParen), expr), tRParen), "fac1");
-let single2 = tInt;
-let single = orDo(single1, single2);
-/** func = single | single "(" single ")"
- * i.e.
- *
- * func = single | func_aux ( int )
- *
-*/
-/** fac = single ["(" single ")"]? | single */
-let fac1Appliee = circumfix((x) => thenDo(thenDo(thenDo(tk.toSome(x), tLParen), tInt), tRParen), "fac1");
-let fac1 = (x) => {
- let raw = thenDo(thenDo(toSome(x), single), OnceOrMoreDo(fac1Appliee));
- console.log("+" + "火鳥" + "+" + repr(raw));
- if (raw._tag == "Some") {
- var result = raw.value.ast[0];
- let applyToken = { text: '%apply', ln: 0, col: 0 };
- for (var i = 1; i < raw.value.ast.length; i++) {
- result = [applyToken, result, raw.value.ast[i]];