Skip to content

Commit

Permalink
Merge pull request #74 from mattjbray/many-till-lazy
Browse files Browse the repository at this point in the history
many_till: Don't be greedy.
  • Loading branch information
seliopou authored Mar 19, 2017
2 parents 4c01875 + cad596a commit 18a04f0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/angstrom.ml
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ let many1 p =

let many_till p t =
fix (fun m ->
(lift2 cons p m) <|> (t *> return []))
(t *> return []) <|> (lift2 cons p m))

let sep_by1 s p =
fix (fun m ->
Expand Down
3 changes: 3 additions & 0 deletions lib_test/test_angstrom.ml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ let combinators =
check_lc ~msg:"single char" (many (char 'a')) ["a"] ['a'];
check_lc ~msg:"two chars" (many (char 'a')) ["aa"] ['a'; 'a'];
end
; "many_till", `Quick, begin fun () ->
check_lc ~msg:"not greedy" (many_till any_char (char '-')) ["ab-ab-"] ['a'; 'b'];
end
; "sep_by1", `Quick, begin fun () ->
let parser = sep_by1 (char ',') (char 'a') in
check_lc ~msg:"single char" parser ["a"] ['a'];
Expand Down

0 comments on commit 18a04f0

Please sign in to comment.