Hi,<br><br>TokenParser supports two kinds of comments, the multi-line comments (ie. {- -}) and the single line comments (ie. -- \n).<br><br>The language I am trying to parse, however, has comments which are neither. The -- acts like a single line comment which extends to the end of the line usually, but can also be truncated to before the end of the line by another --. For example:<br>
<br> noncomment -- comment comment<br> noncomment -- comment comment -- noncomment noncomment -- comment -- noncomment<br> noncomment<br><br>I haven't been able to get the TokenParser to work with this style of comment. The best I could do was copy the whole Token module and modify the code:<br>
<br>data LanguageDef st <br> = LanguageDef <br> { {- snip -}<br> <b>, commentLine :: String</b><br> {- snip -}<br> } <br><br> {- snip -}<br><br>makeTokenParser languageDef<br> = TokenParser{ {- snip -} }<br>
where<br> {- snip -}<br> whiteSpace <br> | noLine && noMulti = skipMany (simpleSpace <b><|> customComment</b> <?> "")<br> | noLine = skipMany (simpleSpace <b><|> customComment</b> <|> multiLineComment <?> "")<br>
| noMulti = skipMany (simpleSpace <b><|> customComment</b> <|> oneLineComment <?> "")<br> | otherwise = skipMany (simpleSpace <b><|> customComment</b> <|> oneLineComment <|> multiLineComment <?> "")<br>
where<br> noLine = null (commentLine languageDef)<br> noMulti = null (commentStart languageDef) <br> <b>customComment =<br> do{commentCustom languageDef<br> ;return()<br> }</b><br>
<br>Then I put my specialised comment parser in the customComment field:<br><br>languageDef = TOKEN.LanguageDef<br> { {- snip -}<br> , TOKEN.commentCustom = customComment<br> {- snip -}<br> }<br> where<br>
customComment = do<br> string "--"<br> untilLineCommentEnd<br> return ()<br><br> untilLineCommentEnd = do<br> c <- manyTill anyChar (string "\n" <|> try (string "--"))<br>
return ()<br><br>Anyone know of a way I could reuse the TokenParser code rather than copy and tweaking it?<br><br>Thanks<br><br>-John<br><br>