RichTokenStream support
authorChaddai Fouche <chaddai.fouche@gmail.com>
Thu, 18 Sep 2008 16:52:56 +0000 (16:52 +0000)
committerChaddai Fouche <chaddai.fouche@gmail.com>
Thu, 18 Sep 2008 16:52:56 +0000 (16:52 +0000)
commit36104d7a0d66df895c8275e3aa7cfe35a322ff04
tree208417c921908f79aff2ab210ac0d20f8af2db57
parentc9bf1a2ccbf93198488b1446977e50b0a5f6ecf5
RichTokenStream support

This patch adds support for raw token streams, that contain more
information than normal token streams (they contains comments at
least). The "lexTokenStream" function brings this support to the
Lexer module. In addition to that, functions have been added to
the GHC module to make easier to recover of the token stream of
a module ("getTokenStream").

Building on that, I added what could be called "rich token
stream": token stream to which have been added the source string
corresponding to each token, the function addSourceToToken takes
a StringBuffer and a starting SrcLoc and a token stream and build
this rich token stream. getRichTokenStream is a convenience
function to get a module rich token stream. "showRichTokenStream"
use the SrcLoc information in such a token stream to get a string
similar to the original source (except unsignificant
whitespaces). Thus "putStrLn . showRichTokenStream =<<
getRichTokenStream s mod" should print a valid module source, the
interesting part being to modify the token stream between the get
and the show of course.
compiler/main/DynFlags.hs
compiler/main/GHC.hs
compiler/parser/Lexer.x