Haskell Parsec Numeration
- by Martin
I'm using Text.ParserCombinators.Parsec and Text.XHtml to parse an input like this:
- First type A\n
-- First type B\n
- Second type A\n
-- First type B\n
--Second type B\n
And my output should be:
<h11 First type A\n</h1
<h21.1 First type B\n</h2
<h12 Second type A\n</h2
<h22.1 First type B\n</h2
<h22.2 Second type B\n</h2
I have come to this part, but I cannot get any further:
title1= do{
;(count 1 (char '-'))
;s <- many1 anyChar newline
;return (h1 << s)
}
title2= do{
;(count 2 (char '--'))
;s <- many1 anyChar newline
;return (h1 << s)
}
text=do {
;many (choice [try(title1),try(title2)])
}
main :: IO ()
main = do t putStr "Error: " print err
Right x - putStrLn $ prettyHtml x
This is ok, but it does not include the numbering.
Any ideas?
Thanks!