]> git.kianting.info Git - clo/blob - src/index.ts
rebuild parser, using `js-token`.
[clo] / src / index.ts
1 var fs = require('fs');
2 import jsTokens from "js-tokens";
3 import * as util from 'util';
4
5 /**inspect the inner of the representation. */
6 let repr = (x : any)=>{return util.inspect(x, {depth: null})};
7
8 /**
9 * like `m ==> f` in ocaml
10 * @param m matchee wrapped
11 * @param f matching function
12 * @returns wrapped result
13 */
14 function thenDo(m : tk.Maybe<TokenMatcheePair>, f : Function){
15 if (m._tag == "None"){
16 return m;
17 }else{
18 var a : tk.Maybe<TokenMatcheePair> = f(m.value);
19 if (a._tag == "Some"){
20 a.value.ast = concat(m.value.ast, a.value.ast);
21 }
22
23 return a;
24 }
25 }
26
27 const tokens = Array.from(jsTokens(`
28 import foo from\t 'bar';
29 import * as util from 'util';
30
31
32 花非花,霧\\{非霧 。{{foo();}}下
33 一句`));
34
35
36 console.log("RESULT="+repr(tokens));
37