项目作者: susisu

项目描述 :
Monadic parser combinators for JavaScript / TypeScript
高级语言: JavaScript
项目地址: git://github.com/susisu/loquat.git
创建时间: 2016-10-23T03:47:48Z
项目社区:https://github.com/susisu/loquat

开源协议:Apache License 2.0

下载


loquat

CI

Monadic parser combinators for JavScript, inspired by Parsec.

  1. import * as lq from "@loquat/simple";
  2. const nat = lq.digit.manyChars1().map(str => parseInt(str, 10));
  3. const op = lq.choice([
  4. lq.char("+").return((a, b) => a + b),
  5. lq.char("-").return((a, b) => a - b),
  6. ]);
  7. const expr =
  8. nat.bind(a =>
  9. op.bind(f =>
  10. nat.map(b =>
  11. f(a, b)
  12. )
  13. )
  14. );
  15. const res = expr.parse("", "14+28"); // { success: true, value: 42 }

Packages

If you are not familiar with loquat, or you are using TypeScript, @loquat/simple is recommended.

For a more flexible and extensible framework, use @loquat/framework.

The core features and extensions are provided as separate packages.

For extension development, a chai plugin and some test helpers are available.

License

  1. Copyright 2019 Susisu
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.