applying upstream patch for github.com/vektah/goparsify/issues/3
This commit is contained in:
parent
b9b0f69ccf
commit
9bc60a2311
@ -35,7 +35,6 @@ func NoAutoWS(parser Parserish) Parser {
|
|||||||
// Any matches the first successful parser and returns its result
|
// Any matches the first successful parser and returns its result
|
||||||
func Any(parsers ...Parserish) Parser {
|
func Any(parsers ...Parserish) Parser {
|
||||||
parserfied := ParsifyAll(parsers...)
|
parserfied := ParsifyAll(parsers...)
|
||||||
// Records which parser was successful for each byte, and will use it first next time.
|
|
||||||
|
|
||||||
return NewParser("Any()", func(ps *State, node *Result) {
|
return NewParser("Any()", func(ps *State, node *Result) {
|
||||||
ps.WS(ps)
|
ps.WS(ps)
|
||||||
@ -45,13 +44,7 @@ func Any(parsers ...Parserish) Parser {
|
|||||||
}
|
}
|
||||||
startpos := ps.Pos
|
startpos := ps.Pos
|
||||||
|
|
||||||
longestError := ps.Error
|
var longestError Error
|
||||||
if ps.Cut <= startpos {
|
|
||||||
ps.Recover()
|
|
||||||
} else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, parser := range parserfied {
|
for _, parser := range parserfied {
|
||||||
parser(ps, node)
|
parser(ps, node)
|
||||||
if ps.Errored() {
|
if ps.Errored() {
|
||||||
@ -72,14 +65,14 @@ func Any(parsers ...Parserish) Parser {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some matches one or more parsers and returns the value as .Child[n]
|
// Some matches zero or more parsers and returns the value as .Child[n]
|
||||||
// an optional separator can be provided and that value will be consumed
|
// an optional separator can be provided and that value will be consumed
|
||||||
// but not returned. Only one separator can be provided.
|
// but not returned. Only one separator can be provided.
|
||||||
func Some(parser Parserish, separator ...Parserish) Parser {
|
func Some(parser Parserish, separator ...Parserish) Parser {
|
||||||
return NewParser("Some()", manyImpl(0, parser, separator...))
|
return NewParser("Some()", manyImpl(0, parser, separator...))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Many matches zero or more parsers and returns the value as .Child[n]
|
// Many matches one or more parsers and returns the value as .Child[n]
|
||||||
// an optional separator can be provided and that value will be consumed
|
// an optional separator can be provided and that value will be consumed
|
||||||
// but not returned. Only one separator can be provided.
|
// but not returned. Only one separator can be provided.
|
||||||
func Many(parser Parserish, separator ...Parserish) Parser {
|
func Many(parser Parserish, separator ...Parserish) Parser {
|
||||||
|
@ -88,6 +88,17 @@ func TestAny(t *testing.T) {
|
|||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// see https://github.com/vektah/goparsify/issues/3
|
||||||
|
t.Run("doesn't succeed early after caller error", func(t *testing.T) {
|
||||||
|
str := "str"
|
||||||
|
str1 := Seq("str", "1")
|
||||||
|
str2 := Any("str2")
|
||||||
|
p := Any(str1, str2, str)
|
||||||
|
_, ps := runParser("str", p)
|
||||||
|
require.False(t, ps.Errored())
|
||||||
|
require.Equal(t, "", ps.Get())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSome(t *testing.T) {
|
func TestSome(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user