diff --git a/TODO.txt b/TODO.txt index f8b1934..d36a81f 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,3 +1,6 @@ +Add a convenient way to run parsers +Add repetition parsers to avoid some recursion +Think about not requiring so much Pos() when making messages Rename Seq2 to Seq Document Seq Add SPDX tags diff --git a/bytes/regexp.go b/bytes/regexp.go index dd3d7d6..aec7c53 100644 --- a/bytes/regexp.go +++ b/bytes/regexp.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "regexp" - "strings" "unicode/utf8" "git.codemonkeysoftware.net/b/gigaparsec" @@ -56,12 +55,10 @@ func (rr *RuneReader) Count() uint64 { return rr.cursor.Pos() - rr.start } -func Regexp(str string) gigaparsec.Parser[byte, string] { - if !strings.HasPrefix(str, "^") && !strings.HasPrefix(str, `\A`) { - str = "^" + str - } - re := regexp.MustCompile(str) - expected := fmt.Sprintf("match `%s`", str) +func Regexp(pattern string) gigaparsec.Parser[byte, string] { + pattern = fmt.Sprintf(`^(?:%s)`, pattern) + re := regexp.MustCompile(pattern) + expected := fmt.Sprintf("match `%s`", pattern) return func(input gigaparsec.State[byte]) (gigaparsec.Result[byte, string], error) { r := NewRuneReader(input.Cursor()) idx := re.FindReaderIndex(r)