<div dir="ltr"><div>Ok, to answer my own question, I changed nested_comment to<br><br>    nested_comment :: P (RealLocated Token) -> Action<br>    nested_comment cont span buf len = do<br>      input <- getInput<br>      go (reverse $ lexemeToString buf len) (1::Int) input<br><br></div>It now starts off with the already lexed part.<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 29, 2014 at 9:04 PM, Alan & Kim Zimmerman <span dir="ltr"><<a href="mailto:alan.zimm@gmail.com" target="_blank">alan.zimm@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>As part of my ongoing efforts to round-trip source code, I have bumped into an issue around file header pragmas, e.g.<br><br></div><div>    {-# LANGUAGE PatternSynonyms #-}<br>    {-# Language DeriveFoldable #-}<br>    {-# options_ghc -w #-}<br><br></div><div><br></div>In normal mode, when not called from headerInfo, the file header pragmas are lexed enough to generate a warning about an invalid pragma if enabled, and then lexed to completion and returned as an `ITblockComment` if `Opt_KeepRawTokenStream` is enabled.<br><br></div>The relevant Alex rule is<br><br><div>    <0> {<br>      -- In the "0" mode we ignore these pragmas<br>      "{-#"  $whitechar* $pragmachar+ / { known_pragma fileHeaderPrags }<br>                         { nested_comment lexToken }<br>    }<br><br></div><div>The problem is that the tokens returned are <br>    <br>    ITblockComment " PatternSynonyms #"<br>    ITblockComment " DeriveFoldable #"<br>    ITblockComment " -w #"<br><br></div><div>It is not possible to reproduce the original comment from these.<br><br><br></div><div>It looks like nested comment ignores what has been lexed so far<br><br>    nested_comment :: P (RealLocated Token) -> Action<br>    nested_comment cont span _str _len = do<br>    ...<br><br></div><div>So my question is, is there any way to make the returned comment include the prefix part? Perhaps be a specific variation of nested_comment that uses str and len.<span class="HOEnZb"><font color="#888888"><br><br></font></span></div><span class="HOEnZb"><font color="#888888"><div>Alan<br></div></font></span></div>
</blockquote></div><br></div>