-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);
-/** fac1 = single "(" int ")" | single */
-let fac1Appliee = circumfix((x) => thenDo(thenDo(thenDo(tk.toSome(x), tLParen), tInt), tRParen), "fac1");
-let fac1 = (x) => {
- let n = thenDo(thenDo(toSome(x), single), fac1Appliee);
- console.log("+" + "bocchitherock" + "+" + repr(n));
- return n;
-};
-let fac2 = single;
-let fac = orDo(fac1, fac2);
-/**
- *
- * term1 = fac (MUL | DIV) fac
- */
-let term1 = midfix((x) => thenDo(thenDo(thenDo(tk.toSome(x), fac), orDo(tMul, tDiv)), fac), "term1");
-/**
- *
- * term2 = int MUL int
- */
-let term2 = fac;
-/**
- * term = term1 | term2
- */
-let term = orDo(term1, term2);
+function notDo(f) {
+ return (x) => {
+ let res1 = f(x);
+ if (res1._tag == "Some") {
+ return { _tag: "None" };
+ }
+ else {
+ let res2 = matchAny(x);
+ return res2;
+ }
+ };
+}
+function matchToken(typeName, value) {
+ return (t) => {
+ let headToken = t.remained[0];
+ if (headToken.type != typeName) {
+ return { _tag: "None" };
+ }
+ else {
+ if (value === undefined || value == headToken.value) {
+ let newTokenPair = {
+ matched: t.matched.concat(headToken),
+ remained: t.remained.slice(1),
+ ast: [headToken]
+ };
+ return { _tag: "Some", value: newTokenPair };
+ }
+ else {
+ return { _tag: "None" };
+ }
+ }
+ ;
+ };
+}
+;