Skip to content

Commit

Permalink
Merge pull request #199 from inhabitedtype/consumed-fail
Browse files Browse the repository at this point in the history
make consumed fail if p commits
  • Loading branch information
thedufer authored May 8, 2020
2 parents 1ba2998 + 4b4ec9b commit 6dcdbe3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/angstrom.ml
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,14 @@ let scan_string state f =
let consume_with p f =
{ run = fun input pos more fail succ ->
let start = pos in
let parser_committed_bytes = Input.parser_committed_bytes input in
let succ' input' pos' more' _ =
let len = pos' - start in
let consumed = Input.apply input' start len ~f in
succ input' pos' more' consumed
if parser_committed_bytes <> Input.parser_committed_bytes input'
then fail input' pos' more' [] "consumed: parser committed"
else (
let len = pos' - start in
let consumed = Input.apply input' start len ~f in
succ input' pos' more' consumed)
in
p.run input pos more fail succ'
}
Expand Down
2 changes: 2 additions & 0 deletions lib_test/test_angstrom.ml
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ let combinators =
["abc"] "ab";
check_s ~msg:"with more input" (consumed (string "abc"))
["a"; "bc"] "abc";
check_fail ~msg:"with commit" (consumed (char 'a' *> commit *> char 'b'))
["a"; "b"];
let integer =
option '+' (char '-') *> take_while (function '0'..'9' -> true | _ -> false)
in
Expand Down

0 comments on commit 6dcdbe3

Please sign in to comment.