https://github.com/bikossor/rudus
Parser combinator library for TypeScript.
https://github.com/bikossor/rudus
functional-parsing hacktoberfest javascript node-js nodejs parser parser-combinators typescript
Last synced: 11 months ago
JSON representation
Parser combinator library for TypeScript.
- Host: GitHub
- URL: https://github.com/bikossor/rudus
- Owner: Bikossor
- License: mit
- Created: 2020-11-11T16:33:50.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-09-05T17:39:13.000Z (over 1 year ago)
- Last Synced: 2025-02-24T12:12:08.603Z (12 months ago)
- Topics: functional-parsing, hacktoberfest, javascript, node-js, nodejs, parser, parser-combinators, typescript
- Language: TypeScript
- Homepage: https://rudus.pages.dev/
- Size: 1.29 MB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
Rudus
Parser combinator library for TypeScript.
## API
### Parsers
- `number`
- Tries to match a given number
- `string`
- Tries to match a given string
- `regex`
- Tries to match a given regex
- `whitespace`
- Tries to match one or more whitespaces (regex: `/[\r\n\t\f\v ]+/`)
- `word`
- Tries to match one or more words (regex: `/[a-zA-Z0-9_]+/`)
- `endOfInput`
- Checks if there is nothing left to parse otherwise it fails
- `endOfLine`
- Tries to match an end of line (either `\r\n`, `\r` or `\n`)
- `lazy`
- Takes a function that just returns a parser _(a thunk)_. This defers the evaluation of the given parser. Useful for writing recursive parsers.
- `failure`
- Always returns a failing parser with the given `errorMessage`. Typically used inside a contextual parser.
### Combinators
- `sequenceOf`
- Accepts multiple parsers, which must all match successfully in the given order otherwise it fails.
- `many`
- Accepts a single parser, which may match zero or infinite times.
- `many1`
- Accepts a single parser, which must match at least once or infinite times otherwise it fails.
- `separatedBy`
- Tries to match a given `value` separated by a given `separator`
- Only captures the `value`
- `anyOf`
- Tries to match all `parsers` and returns the first successful one.
- `optional`
- The given `parser` may or may not match. This combinator can not fail.
- `between`
- Tries to match a given `inner` surrounded by a given `outerLeft` and `outerRight`. The `outerRight` parser is optional and defaults to `outerLeft`.
- `everythingUntil`
- Tries to match everything until (`value`) the separator.