mini-parser小轮子
代码链接 demo如下,定义好rule后进行parse。 const rule = AndRule.of( [ TextRule.of("hello", "HELLO_RULE"), OrRule.of( [TextRule.of(", "), TimesRule.of(3, TextRule.of(" ", "SPACE"), "TIMES")], "NO_NAME" ), TextRule.of("world", "WORLD"), OneOrMoreRule.of(TextRule.of("!"), "SAMPLE") ], "HELLO_WORLD" ); console.log(JSON.stringify(rule.accept("hello world!!!"))); 结果为: { "contain": true, "group": { "groups": [ { "text": "hello", "name": "HELLO_RULE" },...