- else {
- return { _tag: "None" };
- }
-}
-/**
- * define the right hand side of a grammar
- * eg. `LHS ::= a + b`
- * @param process the right hand side processing : eg. `a + b` in `LHS`
- * @param arrange define the order (0 starting) of the elements of the result.
- * ast. : eg. `a + c` is `1 0 2` `(+ a c)`
- * @returns the processed ast.
- */
-function gramRHS(process, arrange) {
- return (m) => {
- let middle = process(m);
- console.log("Middle" + util.inspect(middle, { showHidden: true, depth: null }));
- if (middle._tag == "None") {
- return middle;
- }
- else {
- let matched = middle.value.matched;
- let arrLength = arrange.length;
- let returnRrray = Array(arrange.length);
- arrange.forEach((val, index) => {
- returnRrray[arrange[index]] = matched[index];
- });
- let matchedTmp1Length = matched.length - arrLength;
- console.log(matchedTmp1Length);
- var matchedTmp1 = matched
- .slice(0, matchedTmp1Length);
- console.log("matchedTmp1" + util.inspect(matchedTmp1, { showHidden: true, depth: null }));
- console.log("returnRrray" + util.inspect(returnRrray, { showHidden: true, depth: null }));
- matchedTmp1.push(returnRrray);
- let result = { _tag: "Some",
- value: { matched: matchedTmp1,
- remained: middle.value.remained } };
- return result;
- }
- };
-}
-/**
- * typeABS ::= "'" ID
- */
-var typeABS = (x) => {
- var result = thenDo(thenDo(toSome(x), tApos), tId);
- if (result._tag == "Some" && "text" in result.value.matched[1]) {
- var realToken = result.value.matched[1];
- realToken.text = "'" + realToken.text;
- result.value.matched = [realToken];
- }
- return result;
-};
-/**
- * TypeId ::= typeABS | ID
- */
-var typeName = (x) => {
- return thenDo(toSome(x), orDo(typeABS, tId));
-};
-/**
- * CONST ::= INT | STR | FLO | BOOL
- */
-/**
- * TODO: 要用 debugger 檢查分析問題
- */
-var constParser = gramRHS((x) => { return thenDo(toSome(x), orDo(orDo(orDo(tInt, tFlo), tStr), tBool)); }, [0]);
-/**
- * storing the tree
- */
-var astTree = [];
-/**
- * TYPE_PAIR ::= TYP_ID ID
- */
-var typePair = (x) => {
- let a = thenDo(thenDo(x.maybeTokens, typeName), tId);
- if (a._tag == "Some") {
- let matched = a.value.matched;
- let slice = matched.slice(matched.length - 2);
- console.log("slice" + slice);
- let b = { maybeTokens: a, ast: slice };
- return b;