]>
git.kianting.info Git - uann/blob - index.js
712af45015c8dbd4747f9df53f1506724ca8effd
2 Object
.defineProperty(exports
, "__esModule", { value
: true });
3 exports
.thenDo
= exports
.charToCodepoint
= exports
.matchRange
= exports
.match1Char
= void 0;
4 var fs
= require('fs');
7 * it returns a function which test if the first char of the `remained` part of
8 * the argument of the function is `c`, if it's true, update the `MatchedPair` wrapped
9 * in `Some`. Otherwise, it returns `None`.
10 * * @param c : the char to be test.
11 * @returns the updated `MatchedPair` wrapped in `Some(x)` or `None`.
13 function match1Char(c
) {
15 const charToBeMatched
= m
.remained
[0];
16 if (charToBeMatched
=== c
) {
17 return { _tag
: "Some", value
: {
18 matched
: m
.matched
+ charToBeMatched
,
19 remained
: m
.remained
.substring(1)
23 return { _tag
: "None" };
27 exports
.match1Char
= match1Char
;
31 * it returns a function which test if the first char of the `remained` part of
32 * the argument of the function is between `l` and `u`, if it's true, update the `MatchedPair` wrapped
33 * in `Some`. Otherwise, it returns `None`.
34 * * @param l : lower bound char, 1-char string
35 * * @param u : upper bound char, 1-char string
36 * @returns the updated `MatchedPair` wrapped in `Some(x)` or `None`.
38 function matchRange(l
, u
) {
39 let lCodepoint
= charToCodepoint(l
);
40 let uCodepoint
= charToCodepoint(u
);
42 throw new Error("Error: the codepoint of `" + l
+ "` is not smaller than `" + u
+ "`)");
45 const charToBeMatched
= m
.remained
[0];
46 const codePointToBeMatched
= charToCodepoint(charToBeMatched
);
47 if (codePointToBeMatched
>= lCodepoint
&& codePointToBeMatched
<= uCodepoint
) {
48 return { _tag
: "Some", value
: {
49 matched
: m
.matched
+ charToBeMatched
,
50 remained
: m
.remained
.substring(1)
54 return { _tag
: "None" };
58 exports
.matchRange
= matchRange
;
61 * convert the one-char string to codepoint.
62 * @param s : the string to code point.
63 * @returns if `s.length > 1` return error; otherwise, return the codepoint of `s`.
65 function charToCodepoint(s
) {
67 throw new Error("Error: the length of input string for " + s
+ "is " + s
.length
+ `,
68 however, it should be 1.`);
71 return s
.charCodeAt(0);
74 exports
.charToCodepoint
= charToCodepoint
;
76 * @description thendo(input, f, ...) like
79 function thenDo(input
, f
) {
80 if (input
._tag
== "None") {
84 let inner
= input
.value
;
88 exports
.thenDo
= thenDo
;