ikasoba / daizu.ts

daizu.ts is simple parser combinator.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

٩(๑òωó๑)۶

@ikasoba000/daizu

daizu is simple parser combinator library.

installation

pnpm i @ikasoba000/daizu

Hello, world!

import * as D from "@ikasoba000/daizu";

const parser = D.string("Hello, world!");

D.parse(parser, "Hello, world!"); // "Hello, world!"

const parser = D.regexp(/Hello, \w+!/);

D.parse(parser, "Hello, daizu!"); // "Hello, daizu!"

const parser = D.regexp(/Hello, (\w+)!/);

D.parse(parser, "Hello, daizu!"); // "daizu"

daizu/helper

import D from "@ikasoba000/daizu/helper";

D.string("a").many1(); // Matches aaaaaaaaaaaaaa...

const parser =
  D.choice(
    D.regexp(/[a-zA-Z]/).map(x => x.toLowerCase()),
    D.regexp(/\s*/).ignore()
  )
  .many0();

parser.parse("a b \n c    d e\n f") // "a", "b", "c", "d", "e", "f"

About

daizu.ts is simple parser combinator.


Languages

Language:TypeScript 100.0%