open Parser;; letter;; digit;; test;; test letter "hello";; test letter "!!!";; digit;; test digit "123";; sat;; sat (fun c -> c = 'a');; test (sat (fun c -> c = 'a')) "asd";; test (sat (fun c -> c = 'a')) "bsd";; eoi;; test eoi "test";; test eoi "";; oneof;; (oneof "abc");; test (oneof "abc") "asd";; test (oneof "abc") "test";; (digit <|> letter);; test (digit <|> letter) "asd123";; test (digit <|> letter) "123qwe"";; test (digit <|> letter) "123qwe";; test (digit <|> letter) "!!";; test (digit <|> letter <|> oneof "?!") "!!";; (digit >>= fun d1 -> digit >>= fun d2 -> return (d1, d2));; test (digit >>= fun d1 -> digit >>= fun d2 -> return (d1, d2)) "1234";; test (digit >>= fun d1 -> digit >>= fun d2 -> return [d1; d2]) "1234";; let rec count_spaces = (space >>= fun i -> return (i+1)) <|> let rec count_spaces = (space >> count_space >>= fun i -> return (i+1)) <|> (any >> count_spaces >>= fun i -> return i) <|> (eoi >> return 0);; let rec count_spaces = (space >> count_spaces >>= fun i -> return (i+1)) <|> (any >> count_spaces >>= fun i -> return i) <|> (eoi >> return 0);; 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 ()) "bla bla";; 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 ()) "bla bla";; test (count_spaces ()) "bla b asd as daq ew la";; test (many space) " qwe";; test (space) " qwe";; type arith = Num of int | Add of arith * arith | Mul of arith * arith;; let n = many1 digit >>= fun r -> return (Num (int_of_string (Strng.to_string r)));; test n "123";; let rec e () = t () >>= e' and e' term = (char '+' >>= fun _ -> t () >>= e' >>= fun t2 -> return (Add (term, t2))) <|> return term and t () = f () >>= t' and t' fact = (char '*' >>= fun _ -> f () >>= t' >>= fun f2 -> return (Mul (fact, f2))) <|> return fact and f () = (char '(' >>= fun _ -> e () >>= fun e1 -> char ')' >> return e1;; let rec e () = t () >>= e' and e' term = (char '+' >>= fun _ -> t () >>= e' >>= fun t2 -> return (Add (term, t2))) <|> return term and t () = f () >>= t' and t' fact = (char '*' >>= fun _ -> f () >>= t' >>= fun f2 -> return (Mul (fact, f2))) <|> return fact and f () = (char '(' >>= fun _ -> e () >>= fun e1 -> char ')' >> return e1) <|> n;; test eoi "";; test (e ()) "3+2*5";;