a test to ensure chars1_if p = take1_if p >|= Slice.to_string

This commit is contained in:
Simon Cruanes 2021-09-25 20:47:26 -04:00
parent e06cd516f0
commit b8fa400465
No known key found for this signature in database
GPG key ID: 4AC01D0849AA62B6
2 changed files with 14 additions and 0 deletions

View file

@ -512,6 +512,19 @@ let chars1_if ?descr p = {
~err ~err
} }
(*$QR
Q.(printable_string) (fun s ->
let pred = (function 'a'..'z' | 'A' .. 'Z' | '{' | '}' -> true | _ -> false) in
let p1 = chars1_if pred in
let p2 = take1_if pred >|= Slice.to_string in
parse_string p1 s = parse_string p2 s)
*)
(*$T
let pred = (function 'a'..'z' | 'A' .. 'Z' | '{' | '}' -> true | _ -> false) in \
parse_string (chars_if pred) "coucou{lol} 123" = Ok "coucou{lol}"
*)
exception Fold_fail of state * string exception Fold_fail of state * string
let chars_fold ~f acc0 = { let chars_fold ~f acc0 = {

View file

@ -318,6 +318,7 @@ val chars_if : (char -> bool) -> string t
val chars1_if : ?descr:string -> (char -> bool) -> string t val chars1_if : ?descr:string -> (char -> bool) -> string t
(** Like {!chars_if}, but accepts only non-empty strings. (** Like {!chars_if}, but accepts only non-empty strings.
[chars1_if p] fails if the string accepted by [chars_if p] is empty. [chars1_if p] fails if the string accepted by [chars_if p] is empty.
[chars1_if p] is equivalent to [take1_if p >|= Slice.to_string].
@param descr describes what kind of character was expected, in case of error *) @param descr describes what kind of character was expected, in case of error *)
val endline : char t val endline : char t