Parsing in Clojure via a Backtracking State Monad (brehaut.net) 16 points by stevenashley 16y ago ↗ HN
[–] ithkuil 16y ago ↗ there is a port of haskell parsec library to clojure at http://github.com/mmikulicic/clarsec/ [–] brehaut 16y ago ↗ There is also another parser combinator library called fnparse at http://github.com/joshua-choi/fnparse [–] ithkuil 16y ago ↗ another one in http://kotka.de/projects/clojure/parser.html, also using the same nomenclature as in Parsec. Very nice but the sources are unreachable.I wrote clarsec because I was in hurry and the "kotka"'s sources weren't available.
[–] brehaut 16y ago ↗ There is also another parser combinator library called fnparse at http://github.com/joshua-choi/fnparse [–] ithkuil 16y ago ↗ another one in http://kotka.de/projects/clojure/parser.html, also using the same nomenclature as in Parsec. Very nice but the sources are unreachable.I wrote clarsec because I was in hurry and the "kotka"'s sources weren't available.
[–] ithkuil 16y ago ↗ another one in http://kotka.de/projects/clojure/parser.html, also using the same nomenclature as in Parsec. Very nice but the sources are unreachable.I wrote clarsec because I was in hurry and the "kotka"'s sources weren't available.
[–] ericn 16y ago ↗ I have a question. With the backtracking parser, does this mean that you can rewrite parse-number like this? :(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.
4 comments
[ 5.5 ms ] story [ 20.3 ms ] threadI wrote clarsec because I was in hurry and the "kotka"'s sources weren't available.
(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.