-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Conversation
99f646d
to
e01a2a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing...
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. |
…}`; 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.
…}`; 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.
…; 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.
…; 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.
3285c61
to
d6ab735
Compare
d0ee007
to
cb1bc3c
Compare
[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.
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 |
All checklist items completed in #107 |
TODO:
whitespace
)@example
s to all functionsArrayParser
&sequence()
StringParser
&string()
RegexParser
®ex()
Cursor
AddText
andTextCursor
#84Intersect
->Pretty
#87Flat
respects non-tuple arrays #103infoString
error.name
properties #104·
#105IndentedCodeBlockDetails["indented"]
FencedCodeBlockDetails["char"]
md/codeBlock/findAll
to return full details (remove last use of code block regex)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 factorystring()
provides a specializedParser
with string-specific.split()
,.trim
,.trimStart
, and.trimEnd
.ArrayParser
with shorthand factorysequence()
provides a specializedParser
with array-specific.flat
,.item()
,.items()
,.join()
, and.toObject()
.RegExpParser
with shorthand factoryregexp()
provides a specializedParser
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
, andend
are provided, also exported understring
(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
.