Hi, I would suggest to have a look at fnparse[1]. It's really cool. A commit-log parser might look like this:
(def linebreak
(alt (conc (opt (lit \return)) (lit \newline))
(lit \return)))
(def hex-digit
(alt-lit-seq "0123456789abcdef"))
(def checksum
(semantics (rep+ hex-digit) #(apply str %)))
(def commit
(complex [_ (conc-lit-seq "commit ")
commit-id checksum
_ linebreak
_ (conc-lit-seq "parent ")
parent-id checksum
_ (rep= 2 linebreak)
msg (semantics (rep* (except anything
(conc linebreak
(conc-lit-seq
"commit "))))
#(apply str %))]
{:id commit-id :parent parent-id :message msg}))
(def commit-log
(rep* commit))
This should parse a log like:
commit a2b5927f24c
parent c726fe5211a
This is
the
message
commit 285abb36e12
parent 81f2e35bc61
Another
message.
The result would be:
[{:id a2b5927f24c :parent c726fe5211a :message "This is\nthe\nmessage"}
{:id 285abb36e12 :parent 81f2e35bc61 :message "Another\nmessage."}]
Note, the code is not tested, but should be close.
Hope this helps.
Sincerely
Meikel
[1]: http://github.com/joshua-choi/fnparse/tree/master
smime.p7s
Description: S/MIME cryptographic signature
