tarsec
v0.4.7
Published
A parser combinator library for TypeScript, inspired by Parsec.
Maintainers
Readme
__
/\ \__
\ \ ,_\ __ _ __ ____ __ ___
\ \ \/ /'__`\ /\`'__\/',__\ /'__`\ /'___\
\ \ \_/\ \L\.\_\ \ \//\__, `\/\ __//\ \__/
\ \__\ \__/.\_\\ \_\\/\____/\ \____\ \____\
\/__/\/__/\/_/ \/_/ \/___/ \/____/\/____/A parser combinator library for TypeScript, inspired by Parsec.
Install
npm install tarsecHello world
import { str, seqR, space } from "tarsec";
// define a parser
const parser = seqR(
str("hello"),
space,
str("world")
);
// then use it
parser("hello world"); // success
parser("hello there"); // failureLearning tarsec
Features
- tarsec is entirely TypeScript. There's nothing to compile.
- Derived types: tarsec will generate TypeScript types for your parser
- Debug mode that prints what's happening step-by-step
- Tools to debug your parser's performance
peek/notlookahead for disambiguating grammars without backtracking- A way to make your parser more secure.
- Pretty error messages
Examples
- A CommonMark-ish markdown parser — importable as
tarsec/parsers/markdown. Supports headings (ATX 1–6 with optional trailing#stripping, plus setext), fenced and indented code blocks, multi-backtick inline code spans, multi-line / nested block quotes, ordered / unordered / nested lists, pipe tables with alignment, horizontal rules, HTML passthrough, VitePress-style YAML frontmatter, plus inline bold/italic (*and_), combined***bold-italic***, strikethrough, escapes, autolinks, hard and soft line breaks, images and links with optional"title", and reference-style links / footnotes resolved in a post-parse pass. Paragraphs round-trip soft-wrapped lines through aninline-soft-breaknode. Inline emphasis, strike, and link content all nest, so**[link](u)**and*a `code` b*round-trip into the AST.
Read more about use cases for tarsec.
Contributing
PRs for documentation, tests, and bug fixes are welcome.
