Loquat
Monadic parser combinators for JavaScript / TypeScript
Install / Use
/learn @susisu/LoquatREADME
loquat
Monadic parser combinators for JavScript, inspired by Parsec.
import * as lq from "@loquat/simple";
const nat = lq.digit.manyChars1().map(str => parseInt(str, 10));
const op = lq.choice([
lq.char("+").return((a, b) => a + b),
lq.char("-").return((a, b) => a - b),
]);
const expr =
nat.bind(a =>
op.bind(f =>
nat.map(b =>
f(a, b)
)
)
);
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
Copyright 2019 Susisu
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Related Skills
node-connect
349.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
Writing Hookify Rules
109.4kThis skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.
review-duplication
100.3kUse this skill during code reviews to proactively investigate the codebase for duplicated functionality, reinvented wheels, or failure to reuse existing project best practices and shared utilities.
