summaryrefslogtreecommitdiff
path: root/combinator.go
diff options
context:
space:
mode:
authorAdam Scarr <adam@vektah.net>2017-08-10 21:58:14 +1000
committerAdam Scarr <adam@vektah.net>2017-08-10 22:01:06 +1000
commita0e66b1c46ec57218f8a95a21ace7cbbceb29ec2 (patch)
tree630056d07ca6b44f7a747b7872ba422c6c301d85 /combinator.go
parentaf542eff9e1e51561a9efa37685ee07b1d01b53e (diff)
Document cuts
Diffstat (limited to 'combinator.go')
-rw-r--r--combinator.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/combinator.go b/combinator.go
index 7a811bc..1572e6c 100644
--- a/combinator.go
+++ b/combinator.go
@@ -45,13 +45,12 @@ func Any(parsers ...Parserish) Parser {
for _, parser := range parserfied {
node := parser(ps)
if ps.Errored() {
- if ps.Cut > startpos {
- longestError = ps.Error
- break
- }
if ps.Error.pos > longestError.pos {
longestError = ps.Error
}
+ if ps.Cut > startpos {
+ break
+ }
ps.Recover()
continue
}
@@ -91,7 +90,7 @@ func manyImpl(min int, op Parserish, sep ...Parserish) Parser {
for {
node := opParser(ps)
if ps.Errored() {
- if len(result.Child) < min {
+ if len(result.Child) < min || ps.Cut > ps.Pos {
ps.Pos = startpos
return result
}
@@ -116,8 +115,9 @@ func Maybe(parser Parserish) Parser {
parserfied := Parsify(parser)
return NewParser("Maybe()", func(ps *State) Result {
+ startpos := ps.Pos
node := parserfied(ps)
- if ps.Errored() {
+ if ps.Errored() && ps.Cut <= startpos {
ps.Recover()
}