Compare commits

...
3 Commits
Author SHA1 Message Date
b 5d1f4940ce Write doc comments for the Seq family 2026-08-20 20:41:56 -06:00
b 7560d53d62 Finish renaming Seq2 to Seq 2026-08-20 20:35:40 -06:00
b 18ad9c301a Let Todo take other types than *testing.T 2026-08-20 20:35:07 -06:00
6 changed files with 13 additions and 5 deletions
-1
View File
@@ -1,6 +1,5 @@
Think about not requiring so much Pos() when making messages Think about not requiring so much Pos() when making messages
Think about changing "consume" to "commit" Think about changing "consume" to "commit"
Document Seq
Should MakeState be private now that there's Run? Should MakeState be private now that there's Run?
What's Megaparsec got that we ain't got? What's Megaparsec got that we ain't got?
chainl chainl
+1 -1
View File
@@ -11,6 +11,6 @@ func Token[Out, WSOut any](whitespace gigaparsec.Parser[byte, WSOut]) func(p gig
return result.Consume(false), err return result.Consume(false), err
} }
return func(p gigaparsec.Parser[byte, Out]) gigaparsec.Parser[byte, Out] { return func(p gigaparsec.Parser[byte, Out]) gigaparsec.Parser[byte, Out] {
return gigaparsec.Seq2(p, gigaparsec.Repeat(0, ignoreWS), func(val Out, _ []struct{}) Out { return val }) return gigaparsec.Seq(p, gigaparsec.Repeat(0, ignoreWS), func(val Out, _ []struct{}) Out { return val })
} }
} }
+1
View File
@@ -1,6 +1,7 @@
{{/* SPDX-License-Identifier: Unlicense */ -}} {{/* SPDX-License-Identifier: Unlicense */ -}}
{{define "func"}}{{if gt . 1 -}} {{define "func"}}{{if gt . 1 -}}
// Seq{{if gt . 2}}{{.}}{{end}} runs {{.}} parsers in sequence and maps their collected results with f.
func Seq{{if gt . 2}}{{.}}{{end}}[In, Out{{range .Count}}, T{{.}}{{end}} any]( func Seq{{if gt . 2}}{{.}}{{end}}[In, Out{{range .Count}}, T{{.}}{{end}} any](
{{- range .Count}} {{- range .Count}}
p{{.}} Parser[In, T{{.}}],{{end}} p{{.}} Parser[In, T{{.}}],{{end}}
+1 -1
View File
@@ -91,7 +91,7 @@ func Bind9[In, Out, T, T2, T3, T4, T5, T6, T7, T8, T9 any](
return gp.Bind(gp.Bind(gp.Bind(gp.Bind(gp.Bind(gp.Bind(gp.Bind(gp.Bind(gp.Bind(p, f), f2), f3), f4), f5), f6), f7), f8), f9) return gp.Bind(gp.Bind(gp.Bind(gp.Bind(gp.Bind(gp.Bind(gp.Bind(gp.Bind(gp.Bind(p, f), f2), f3), f4), f5), f6), f7), f8), f9)
} }
func Seq2[In, Out, T, T2 any]( func Seq[In, Out, T, T2 any](
p gp.Parser[In, T], p gp.Parser[In, T],
p2 gp.Parser[In, T2], p2 gp.Parser[In, T2],
f func(T, T2) Out, f func(T, T2) Out,
+2 -2
View File
@@ -16,7 +16,7 @@ import (
"pgregory.net/rapid" "pgregory.net/rapid"
) )
func Todo(t *testing.T) { func Todo[T interface{Errorf(string,...any)}](t T) {
t.Errorf("TODO") t.Errorf("TODO")
} }
@@ -90,7 +90,7 @@ func TestBind(t *testing.T) {
t.Run("returns an error if the second parser returns an error", Todo) t.Run("returns an error if the second parser returns an error", Todo)
t.Run("succeeds if both parsers succeed", rapid.MakeCheck(func(t *rapid.T) { t.Run("succeeds if both parsers succeed", rapid.MakeCheck(func(t *rapid.T) {
// s := rapid.SliceOfN(rapid.Byte(), 0, 100) // s := rapid.SliceOfN(rapid.Byte(), 0, 100)
t.Errorf("TODO") Todo(t)
})) }))
/* /*
If the first parser fails, then consumption depends on the first parser. If the first parser fails, then consumption depends on the first parser.
+8
View File
@@ -4,6 +4,7 @@
package gigaparsec package gigaparsec
// Seq runs 2 parsers in sequence and maps their collected results with f.
func Seq[In, Out, T, T2 any]( func Seq[In, Out, T, T2 any](
p Parser[In, T], p Parser[In, T],
p2 Parser[In, T2], p2 Parser[In, T2],
@@ -38,6 +39,7 @@ func Seq[In, Out, T, T2 any](
} }
} }
// Seq3 runs 3 parsers in sequence and maps their collected results with f.
func Seq3[In, Out, T, T2, T3 any]( func Seq3[In, Out, T, T2, T3 any](
p Parser[In, T], p Parser[In, T],
p2 Parser[In, T2], p2 Parser[In, T2],
@@ -83,6 +85,7 @@ func Seq3[In, Out, T, T2, T3 any](
} }
} }
// Seq4 runs 4 parsers in sequence and maps their collected results with f.
func Seq4[In, Out, T, T2, T3, T4 any]( func Seq4[In, Out, T, T2, T3, T4 any](
p Parser[In, T], p Parser[In, T],
p2 Parser[In, T2], p2 Parser[In, T2],
@@ -139,6 +142,7 @@ func Seq4[In, Out, T, T2, T3, T4 any](
} }
} }
// Seq5 runs 5 parsers in sequence and maps their collected results with f.
func Seq5[In, Out, T, T2, T3, T4, T5 any]( func Seq5[In, Out, T, T2, T3, T4, T5 any](
p Parser[In, T], p Parser[In, T],
p2 Parser[In, T2], p2 Parser[In, T2],
@@ -206,6 +210,7 @@ func Seq5[In, Out, T, T2, T3, T4, T5 any](
} }
} }
// Seq6 runs 6 parsers in sequence and maps their collected results with f.
func Seq6[In, Out, T, T2, T3, T4, T5, T6 any]( func Seq6[In, Out, T, T2, T3, T4, T5, T6 any](
p Parser[In, T], p Parser[In, T],
p2 Parser[In, T2], p2 Parser[In, T2],
@@ -284,6 +289,7 @@ func Seq6[In, Out, T, T2, T3, T4, T5, T6 any](
} }
} }
// Seq7 runs 7 parsers in sequence and maps their collected results with f.
func Seq7[In, Out, T, T2, T3, T4, T5, T6, T7 any]( func Seq7[In, Out, T, T2, T3, T4, T5, T6, T7 any](
p Parser[In, T], p Parser[In, T],
p2 Parser[In, T2], p2 Parser[In, T2],
@@ -373,6 +379,7 @@ func Seq7[In, Out, T, T2, T3, T4, T5, T6, T7 any](
} }
} }
// Seq8 runs 8 parsers in sequence and maps their collected results with f.
func Seq8[In, Out, T, T2, T3, T4, T5, T6, T7, T8 any]( func Seq8[In, Out, T, T2, T3, T4, T5, T6, T7, T8 any](
p Parser[In, T], p Parser[In, T],
p2 Parser[In, T2], p2 Parser[In, T2],
@@ -473,6 +480,7 @@ func Seq8[In, Out, T, T2, T3, T4, T5, T6, T7, T8 any](
} }
} }
// Seq9 runs 9 parsers in sequence and maps their collected results with f.
func Seq9[In, Out, T, T2, T3, T4, T5, T6, T7, T8, T9 any]( func Seq9[In, Out, T, T2, T3, T4, T5, T6, T7, T8, T9 any](
p Parser[In, T], p Parser[In, T],
p2 Parser[In, T2], p2 Parser[In, T2],