Move Map and Run onto Parser, and document stuff

This commit is contained in:
b
2026-08-20 23:14:00 -06:00
parent 6b201fbb69
commit 22a6eb7335
5 changed files with 27 additions and 24 deletions
+2 -2
View File
@@ -9,7 +9,7 @@ import (
// Token wraps a parser to discard all whitespace after the parsed input.
// whitespace is a parser that will consume non-empty whitespace.
func Token[Out any](whitespace gigaparsec.Parser[byte, struct{}]) func(p gigaparsec.Parser[byte, Out]) gigaparsec.Parser[byte, Out] {
mappedWS := gigaparsec.Map(whitespace, func(struct{}) struct{} { return struct{}{} })
mappedWS := whitespace.Map(func(struct{}) struct{} { return struct{}{} })
var ignoreWS gigaparsec.Parser[byte, struct{}] = func(s gigaparsec.State[byte]) (gigaparsec.Result[byte, struct{}], error) {
result, err := mappedWS(s)
return result.Consume(false), err
@@ -25,5 +25,5 @@ func isWhitespaceASCII(b byte) bool {
// WhitespaceASCII consumes one ASCII whitespace character: space, tab, LF, CR, vertical tab, or form feed.
func WhitespaceASCII() gigaparsec.Parser[byte, struct{}] {
return gigaparsec.Map(gigaparsec.Satisfy(isWhitespaceASCII), func(byte) struct{} { return struct{}{} })
return gigaparsec.Satisfy(isWhitespaceASCII).Map(func(byte) struct{} { return struct{}{} })
}
+1 -1
View File
@@ -21,7 +21,7 @@ func ExampleToken() {
)
tokenize := gigaparsec.Repeat(0, bytes.Token[string](bytes.WhitespaceASCII())(ptokens))
tokens, _ := gigaparsec.Run(tokenize, strings.NewReader("(alpha + 42) -5 "))
tokens, _ := tokenize.Run(strings.NewReader("(alpha + 42) -5 "))
for _, token := range tokens {
fmt.Println(token)
}