I'm writing a program to modify source code files. I need to parse the file (e.g. with megaparsec), modify its Abstract Syntax Tree AST (e.g. with Uniplate), and regenerate the file with as little changes as possible (e.g. preserving spaces, comments, ...).
So, the AST should contain the spaces, for example :
data Identifier = Identifier String String
where the first string is the name of the identifier, and the second is the spaces after it. The same applies for any symbol in the language.
How can I write a parser for Identifier ?