]>
git.kianting.info Git - uann/blob - index.ts
55e3d65db7b9894c9aead54e69cfa73e657a1520
1 var fs
= require('fs');
3 import * as tk from
'./tokenize.js';
7 let b
: Array<tk
.Token
> = tk
.tokenize("2+2");
9 export interface TokenMatcheePair
{
16 * it returns a function which test if the first char of the `remained` part of
17 * the argument of the function is `c`, if it's true, update the `MatchedPair` wrapped
18 * in `Some`. Otherwise, it returns `None`.
19 * * @param t : the char to be test.
20 * @returns the updated `MatchedPair` wrapped in `Some(x)` or `None`.
22 export function match1token(t
: tk
.Token
): (m
: TokenMatcheePair
) => tk
.Maybe
<TokenMatcheePair
> {
23 return (m
: TokenMatcheePair
) => {
24 if (m
.remained
.length
== 0) {
25 return { _tag
: "None" };
27 const tokenToBeMatched
= m
.remained
[0];
28 if (tokenToBeMatched
=== t
) {
29 m
.matched
.push(tokenToBeMatched
);
31 _tag
: "Some", value
: {
33 remained
: m
.remained
.slice(1)
38 return { _tag
: "None" };
46 console
.log(thenDo(c
,match1token(tk
.tokenize("+")[0])));