Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(parcom): init #79

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

feat(parcom): init #79

wants to merge 2 commits into from

Conversation

pskfyi
Copy link
Owner

@pskfyi pskfyi commented May 17, 2023

TODO:


  • feat(parser): init; add combinator module (d0ee007)

    Parser combinator libraries provide composable parsers used for constructing more complex parsers. This first draft is robust enough for simple DSLs. Notably it does not implement backtracking or a chain combinator, which would allow for more advanced branching. However the TS implementation is very powerful, capable of inferring the return types from complex parsers without explicit compiler hints in userland.

    • The base Parser class handles core functionality like .fallback(), into(), .not(), .then(), .optional, .ignore, .zeroOrMore, and .oneOrMore.

    • StringParser with shorthand factory string() provides a specialized Parser with string-specific .split(), .trim, .trimStart, and .trimEnd.

    • ArrayParser with shorthand factory sequence() provides a specialized Parser with array-specific .flat, .item(), .items(), .join(), and .toObject().

    • RegExpParser with shorthand factory regexp() provides a specialized Parser with RegExp-specific .match, .group(), .groups(), and .or().

    • any() composes multiple parsers into one that matches the first success.

    • Common helpers whitespace, blankLink, inlineString, multilineString, and end are provided, also exported under string (ex. string.inline, string.whitespace) for convenience.

    As a proof-of-concept, the conventional commit parser was refactored to use this module, also exporting the full Language.

@pskfyi pskfyi force-pushed the init-parcom branch 3 times, most recently from 99f646d to e01a2a3 Compare May 19, 2023 15:56
AustinArey
AustinArey previously approved these changes May 20, 2023
Copy link
Collaborator

@AustinArey AustinArey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewing...

@pskfyi
Copy link
Owner Author

pskfyi commented May 21, 2023

Hey thanks! This is still in draft - please don't feel the need to review. Of course you're free to look and weigh in if you choose. Just know that it may radically change out from under you.

@pskfyi pskfyi dismissed AustinArey’s stale review May 23, 2023 03:08

Not yet ready

This was referenced May 23, 2023
pskfyi added a commit that referenced this pull request May 23, 2023
…}`; docs

This refactor brings this helper type in line with [the original inspiration](https://twitter.com/mattpocockuk/status/1622730173446557697). During #79 I encountered situations where the `& {}` was necessary to coax the compiler into untangling complex types. I also learned that the `Record`-based type constraint was unnecessary and that it has uses beyond just handling intersections, so I opted to fully implement the original helper except with a shorter name. I also took this opportunity to add a readme entry.
pskfyi added a commit that referenced this pull request May 23, 2023
…}`; docs

This refactor brings this helper type in line with [the original inspiration](https://twitter.com/mattpocockuk/status/1622730173446557697). During #79 I encountered situations where the `& {}` was necessary to coax the compiler into untangling complex types. I also learned that the `Record`-based type constraint was unnecessary and that it has uses beyond just handling intersections, so I opted to fully implement the original helper except with a shorter name. I also took this opportunity to add a readme entry.
@pskfyi pskfyi mentioned this pull request May 23, 2023
pskfyi added a commit that referenced this pull request May 26, 2023
…; docs

This refactor brings this helper type in line with [the original inspiration](https://twitter.com/mattpocockuk/status/1622730173446557697). During #79 I encountered situations where the `& {}` was necessary to coax the compiler into untangling complex types. I also learned that the `Record`-based type constraint was unnecessary and that it has uses beyond just handling intersections, so I opted to fully implement the original helper except with a shorter name. I also took this opportunity to add a readme entry.
AustinArey pushed a commit that referenced this pull request May 26, 2023
…; docs

This refactor brings this helper type in line with [the original inspiration](https://twitter.com/mattpocockuk/status/1622730173446557697). During #79 I encountered situations where the `& {}` was necessary to coax the compiler into untangling complex types. I also learned that the `Record`-based type constraint was unnecessary and that it has uses beyond just handling intersections, so I opted to fully implement the original helper except with a shorter name. I also took this opportunity to add a readme entry.
@pskfyi pskfyi changed the base branch from main to cursor May 28, 2023 04:31
@pskfyi pskfyi force-pushed the cursor branch 2 times, most recently from 3285c61 to d6ab735 Compare May 28, 2023 06:16
@pskfyi pskfyi force-pushed the init-parcom branch 3 times, most recently from d0ee007 to cb1bc3c Compare May 28, 2023 09:08
Base automatically changed from cursor to main May 28, 2023 22:12
pskfyi added 2 commits May 28, 2023 16:00
[Parser combinator](https://en.wikipedia.org/wiki/Parser_combinator) libraries provide composable parsers used for constructing more complex parsers. This first draft is robust enough for simple DSLs. Notably it does not implement backtracking or a chain combinator, which would allow for more advanced branching. However the TS implementation is very powerful, capable of inferring the return types from complex parsers without explicit compiler hints in userland.

- The base `Parser` class handles core functionality like `.fallback()`, `into()`, `.not()`, `.then()`, `.optional`, `.ignore`, `.zeroOrMore`, and `.oneOrMore`.

- `StringParser` with shorthand factory `string()` provides a specialized `Parser` with string-specific `.split()`, `.trim`, `.trimStart`, and `.trimEnd`.

- `ArrayParser` with shorthand factory `sequence()` provides a specialized `Parser` with array-specific `.flat`, `.item()`, `.items()`, `.join()`, and `.toObject()`.

- `RegExpParser` with shorthand factory `regexp()` provides a specialized `Parser` with RegExp-specific `.match`, `.group()`, `.groups()`, and `.or()`.

- `any()` composes multiple parsers into one that matches the first success.

- Common helpers `whitespace`, `blankLink`, `inlineString`, `multilineString`, and `end` are provided, also exported under `string` (ex. `string.inline`, `string.whitespace`) for convenience.
@pskfyi
Copy link
Owner Author

pskfyi commented May 30, 2023

Using this PR as a workplace to get the last bits of this organized. A new PR will be opened when it's ready, and this will be closed. The new branch is init-parser.

@pskfyi
Copy link
Owner Author

pskfyi commented Jun 3, 2023

All checklist items completed in #107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants