Skip to main content
The Deno 2 Release Candidate is here
Learn more

parzec_deno

parzec_deno is a Deno port of the Parzec NPM package.

License Deno module Github
tag Build Code
coverage

Parser Combinators for Typescript

Parzec is a parser combinator library adapted from Haskell’s famous Parsec library. A parser combinator library consist of higher order functions which make it easy to build recursive descent parsers. Parsers composed from Parzec’s combinators can recognize languages in the PEG class of grammars. PEG grammars can be context-sensitive, so the parsers have infinite lookahead and backtracking capabilities.

Parzec also supports efficient parsing of LL(1) grammars by enabling the backtracking only when a special combinator is used. Also, to improve performance, some combinators have been inlined rather than built from lower level combinators.

Parzec’s input is represented by an abstract interface. Consequently, the parsers’ input can be anything from simple strings to files, or even tokenized data streams. Parzec includes functionality to create lexical analyzers or lexers from regular expressions. The lexer converts input strings into tokens, and makes the parsing simpler and more efficient.

johtela/parzec

Motivation

The original Parzec library (at deno.land/x/parzec) does not seem to currently support Deno.

Changes

In order to make the NPM based Parzec compatible with Deno, some changes have to be made. Parzec fortunately has no run-time dependencies, so only local imports need to be updated. These are parzec_deno’s contributions to the original Parzec repository:

  • Update docs and metadata.
    • Removed all files that were not TypeScript source file.
    • Added the README.md file (which you are reading right now).
    • Added the GitHub compatible LICENSE file with the original license text.
  • Translated the NPM project structure to Deno.
    • Added the mod.ts module that exports everything.
    • Replaced all NPM style import statements with ES module imports.
    • Removed property-based tests in src/test.
    • Replaced all tests in src/test with Deno compatible unit tests.
    • Renamed all test files to ensure a _test.ts suffix.
  • Fixed errors discovered by deno fmt and deno lint.
    • Formatted all files with deno fmt.
    • Added // deno-lint-ignore no-explicit-any where necessary.
    • Replaced let with const where possible.
    • Removed unnecessary async keywords in tests.
  • Added new build and CI tools.
    • Added dev.ts which uses edcb for running checks.
    • Added the GitHub Action ci workflow which runs dev.ts.
    • Added code coverage reporting.

Usage

import * as pz from "https://deno.land/x/parzec_deno/mod.ts";