<div dir="ltr"><div style>Hello, I'm using the GHC lexer to parse some haskell code containing a language pragma, in GHC 7.4.2</div><div><br></div><div><font face="courier new, monospace">module Main where</font></div>
<div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">import GHC</font></div><div><font face="courier new, monospace">import GHC.Paths ( libdir )</font></div><div><font face="courier new, monospace">import Lexer</font></div>
<div><font face="courier new, monospace">import qualified MonadUtils as GMU</font></div><div><font face="courier new, monospace">import StringBuffer</font></div><div><font face="courier new, monospace">import FastString (mkFastString)</font></div>
<div><font face="courier new, monospace">import SrcLoc</font></div><div><font face="courier new, monospace">import ErrUtils (mkPlainErrMsg)</font></div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">main::IO()</font></div>
<div><font face="courier new, monospace">main = do</font></div><div><font face="courier new, monospace"> let contents="{-# LANGUAGE CPP #-}\nmodule Main where\nmain=undefined"</font></div><div><font face="courier new, monospace"> runGhc (Just libdir) $ do</font></div>
<div><font face="courier new, monospace"> flg <- getSessionDynFlags</font></div><div><font face="courier new, monospace"> let sb=stringToStringBuffer contents</font></div><div><font face="courier new, monospace"> let lexLoc = mkRealSrcLoc (mkFastString "<interactive>") 1 1</font></div>
<div><font face="courier new, monospace"> let prTS = lexTokenStream sb lexLoc flg</font></div><div><font face="courier new, monospace"> case prTS of</font></div><div><font face="courier new, monospace"> POk _ toks -> GMU.liftIO $ print $ map (show . unLoc) toks</font></div>
<div><font face="courier new, monospace"> PFailed l msg -> GMU.liftIO $ print $ mkPlainErrMsg l msg</font></div><div><br></div><div style>This prints:</div><div style><font face="courier new, monospace">["ITblockComment \" CPP #\"","ITmodule","ITconid \"Main\"","ITwhere","ITvocurly","ITvarid \"main\"","ITequal","ITvarid \"undefined\""]</font><br>
</div><div style><br></div><div style>Why is the first token ITblockComment and not ITlanguage_prag? Do I need to enable something special to get pragma tokens?</div><div style><br></div><div style>Thanks!</div><div><br></div>
-- <br>JP Moresmau<br><a href="http://jpmoresmau.blogspot.com/">http://jpmoresmau.blogspot.com/</a>
</div>