Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds the following features:
new math example
The previous math example was removed, see #58 . The new example essentially does the same thing but the implementation is different.
I had a lot of trouble writing this, but I think the implementation is now pretty good. It's also tested somewhat well.
fix maybe combinator return type
The previous type indicated a return type must be present, but in the implementation it's actually possible to not parse anything new and return the result of the previous parser. This is now reflected in the type.
This is a breaking change, but should not matter because the next release was going to have breaking changes anyway.
add many1 combinator
This is like
many
but it makes sure at least one match was made by the parser. Themany
combinator allows 0 matches.add parjser.debug() method
This is a development time feature. You can now temporarily add the
.debug()
method to any parser like this:When the parser has parsed something, the result is logged to the console. This allowed me to find errors in my math example and it was very useful.
Here is an example of the message:
add constant type inference to many parsers
In typescript, the value
"a"
can be seen as having both typesstring
and"a"
. By default the type checker infers the broader typestring
, but may be instructed to infer the narrower "constant" type"a"
by usingconst str = "a" as const
.This can also be done when using generic types in functions with
function foo<const T>(value: T)
- in this case the generic type is inferred to the more narrow"a"
.This is very useful when constructing parsers, I think. Now we can have this:
This is also useful when working with type unions. Because of this extra type safety, you can avoid doing additional type casts altogether.
This should also be backward compatible.