Regexp: put pattern in a group to fix associativity
This commit is contained in:
parent
9171809e2b
commit
9673903dd7
3
TODO.txt
3
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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user