type token = LPAR | RPAR | NOT | AND | ID of string;; type 'a option = None | Some of 'a;; open Parser;; test letter "hello world";; test letter "1hello world";; test digit "1hello world";; test digit "hello world";; test (sat ((=) 'h')) "hello world";; sat;; test (sat ((=) 'H')) "hello world";; eoi;; test eoi "hello world";; test eoi "";; test any "hello";; test any "1ello";; test any " ello";; test any "";; test (oneof "hW") "hello World";; test (oneof "hW") "ello World";; test (oneof "hW") "World";; test (letter <|> digit) "hello world";; test (letter <|> digit) "1hello world";; test (letter <|> digit) " 1hello world";; test ( letter >>= fun c -> letter) "hello world" ;; test ( letter >>= fun c -> letter >>= fun d -> (c,d)) "hello world" ;; test ( letter >>= fun c -> letter >>= fun d -> return (c,d)) "hello world" ;; test ( letter >> letter) "hello world" ;; "()()(()())";; let rec a = a;; let rec a () = a ();; let rec count_spaces () = (space >> count_spaces () >>= fun i -> return (i+1)) <|> (any >> count_spaces () >>= fun i -> return i) <|> (eoi >> return 0);; test (count_spaces ()) " hello world";; failwith "left" >> failwith "right";; failwith "left" >>= failwith "right";; failwith "left" >>= fun _ -> failwith "right";; Third try (enforce evaluation) let rec count_spaces () = (space >>= fun _ -> count_spaces () >>= fun i -> return (i+1)) <|> (any >>= fun _ -> count_spaces () >>= fun i -> return i) <|> (eoi >> return 0);; let rec count_spaces () = (space >>= fun _ -> count_spaces () >>= fun i -> return (i+1)) <|> (any >>= fun _ -> count_spaces () >>= fun i -> return i) <|> (eoi >> return 0);; test (count_spaces ()) " hello world";; [1;2;3];; "[1;2;3];; "[1;2;3]";; ;; "[1;2;3]";; test (between p1 p2 p3 ) "[1;2;3]";; test (char '[') "[1;2;3]";; test (char ']') "[1;2;3]";; test (between (char '[') (many any) (char ']') ) "[1;2;3]";; test (between (char '[') (many (noneof "]")) (char ']') ) "[1;2;3]";; test (sep_by (char ';') (many1 digit) ) "1;2;3" ;; let p2 = (sep_by (char ';') (many1 digit) );; test (between (char '[') p2 (char ']') ) "[1;2;3]";; test (between (char '[') p2 (char ']') ) "[1;20;3]";; ;; test (between (char '[') p2 (char ']') ) "[1;20;3]";; test (between (char '[') p2 (char ']') ) "[1;x;3]";; open AriParser;; test (e ()) "2+3*4";; test (e ()) "2+3+4";; test (e ()) "2+(3+4)";; test (e ()) "(2+3)+4";; test (many1 any) "Harald";; test (many1 any) "Harald.Zankl@uibk.ac.at";; test (many1 letter) "Harald.Zankl@uibk.ac.at";; test (many1 letter >>= fun n1 -> char '.') "Harald.Zankl@uibk.ac.at";; test (many1 letter >>= fun n1 -> char '.' >> return n1) "Harald.Zankl@uibk.ac.at";;