【发布时间】:2010-04-29 10:58:53
【问题描述】:
我正在使用Text.ParserCombinators.Parsec 和Text.XHtml 来解析这样的输入:
- 第一个类型 A\n -- 第一个类型 B\n - 第二种 A\n -- 第一个类型 B\n --第二种类型B\n我的输出应该是:
<h1>1 First type A\n</h1>
<h2>1.1 First type B\n</h2>
<h1>2 Second type A\n</h2>
<h2>2.1 First type B\n</h2>
<h2>2.2 Second type B\n</h2>
我已经到了这一部分,但我无法更进一步:
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
这没关系,但它不包括编号。
有什么想法吗?
谢谢!
【问题讨论】:
标签: parsing haskell functional-programming parsec