X-Git-Url: https://git.kianting.info/?a=blobdiff_plain;f=src%2Findex.ts;h=599d32a9040ef78c4127eff01698f54b0aa95ab1;hb=9784854866f652eb2118c390425a6cbe7a702ab1;hp=3b2b3d15af9be13f1d207bdf90198eddd973959b;hpb=77dc1ded9c4adbb3108269ebe881c535353d8b61;p=clo diff --git a/src/index.ts b/src/index.ts index 3b2b3d1..599d32a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -198,6 +198,7 @@ export function matchAny(m: TokenMatcheePair): tk.Maybe { } /** + * Danger : Maybe it's not enough to work. * @description repeating matching function `f` * zero or more times, like the asterisk `*` in regex `f*` . * @param f : the function to be repeated 0+ times. @@ -242,7 +243,7 @@ let midfix = (f : Function, signal? : string) => (x : TokenMatcheePair)=>{ let new_ast = [ast_tail]; a.value.ast = new_ast; - console.log("+"+signal+"+"+repr(a)); + // console.log("+"+signal+"+"+repr(a)); } @@ -277,12 +278,13 @@ let single = orDo(single1, single2); */ -/** fac = single ["(" single ")"]? | single */ +/** 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)); - console.log("+"+"火鳥"+"+"+repr(raw)); @@ -295,8 +297,6 @@ let fac1 = (x : TokenMatcheePair) => result = [applyToken, result, raw.value.ast[i]]; } - console.log("+"+"hitori"+"+"+repr(result)); - if (!Array.isArray(result)){ raw.value.ast = [result]; }else{ @@ -354,19 +354,18 @@ let expr = orDo(expr1, expr2); let tokens = tk.tokenize("1"); +let tokens2 = tk.tokenize("1(2)"); +let tokens3 = tk.tokenize("1(2)(3)"); +let tokens4 = tk.tokenize("(3(2))*2+1"); //let tokens = tk.tokenize("(4-(3/4))"); //tk.tokenize(argv[2]); -let tokensFiltered = tokens.filter( +let tokensFiltered = tokens4.filter( (x)=>{return (x.type != tk.TokenType.NL && x.type != tk.TokenType.SP)}); -let wrappedTokens : tk.Maybe = - tk.toSome({ - matched : [] , - remained : tokensFiltered, - ast : []}); + let beta = expr({ matched : [] ,