https://github.com/zachary822/parser-combinator
Javascript Parser Combinator
https://github.com/zachary822/parser-combinator
deno parser typescript
Last synced: about 1 month ago
JSON representation
Javascript Parser Combinator
- Host: GitHub
- URL: https://github.com/zachary822/parser-combinator
- Owner: zachary822
- Created: 2024-12-15T05:52:46.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-18T07:08:11.000Z (over 1 year ago)
- Last Synced: 2025-01-10T07:50:04.406Z (over 1 year ago)
- Topics: deno, parser, typescript
- Language: TypeScript
- Homepage: https://jsr.io/@fun/parser-combinator
- Size: 85.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Parser Combinator
Parser combinator implemented in church encoded types.
## Example
The library uses a custom `List` type to represent arrays, strings used by the
parser are lists of characters (`List`). Use `strToList` to convert
string to `List`.
```typescript
const input = strToList("abc");
const parser = stringP(strToList("ab"));
// result contained in a Maybe type
const result = parser(input)(
// default return value if parser doesn't match input
null,
// tuple of remaing input and parse result as javascript strings
(r) => [listToStr(fst(r)), listToStr(snd(r))];
```