Parsing in Clojure via a Backtracking State Monad
1–5 of 5 posts
Re: Parsing in Clojure via a Backtracking State Monad
#2Re: Parsing in Clojure via a Backtracking State Monad
#3there is a port of haskell parsec library to clojure at http://github.com/mmikulicic/clarsec/
Re: Parsing in Clojure via a Backtracking State Monad
#4there is a port of haskell parsec library to clojure at http://github.com/mmikulicic/clarsec/
There is also another parser combinator library called fnparse at http://github.com/joshua-choi/fnparse
I wrote clarsec because I was in hurry and the "kotka"'s sources weren't available.
Re: Parsing in Clojure via a Backtracking State Monad
#5(def parse-number (domonad [sign (optional parse-sign "+") [type digits] (choice parse-integer parse-float) _ eof] [type (apply str (cons sign digits))])))
The fact that you can fail on the eof and backtrack into the choice (if it is possible) is the main advantage. It lets you lay out your parser in a logical way.