+ else {
+ return { _tag: "None" };
+ }
+}
+exports.matchAny = matchAny;
+/**
+* @description repeating matching function `f`
+* zero or more times, like the asterisk `*` in regex `f*` .
+* @param f : the function to be repeated 0+ times.
+* @returns:the combined function
+*/
+function OnceOrMoreDo(f) {
+ return (x) => {
+ var wrappedOldX = { _tag: "Some", value: x };
+ var wrappedNewX = wrappedOldX;
+ var counter = -1;
+ while (wrappedNewX._tag != "None") {
+ wrappedOldX = wrappedNewX;
+ wrappedNewX = thenDo(wrappedOldX, f);
+ counter += 1;
+ }
+ ;
+ if (counter <= 0) {
+ return { _tag: "None" };
+ }
+ let ast = wrappedOldX.value.ast;
+ wrappedOldX.value.ast = ast.slice(ast.length - counter);
+ console.log(repr(wrappedOldX.value.ast));
+ return wrappedOldX;
+ };
+}
+exports.OnceOrMoreDo = OnceOrMoreDo;
+/**
+ * aux function for midfix operator
+ * @param f function
+ * @param signal the rule name
+ * @returns
+ */
+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;