I am writing a source-to-source conversion using parsec , so I have LanguageDeffor my language and I build a TokenParserfor it using Text.Parsec.Token.makeTokenParser:
myLanguage = LanguageDef { ...
commentStart = "/*"
, commentEnd = "*/"
...
}
-- defines 'stringLiteral', 'identifier', etc...
TokenParser {..} = makeTokenParser myLanguage
Unfortunately, since I defined commentStartand commentEnd, each of the parser compilers in TokenParseris a token parser, implemented in terms of whiteSpace, and whiteSpace- spaces, as well as comments.
What is the correct way to save comments in this situation?
Approaches I can think of:
- Do not define
commentStartand commentEnd. Wrap each of the token parsers in a different combinator that captures comments before parsing each token. makeTokenParser (, , , Text.Parsec.Token, , ?)
?