Alright thanks for your comprehensive answer! I think I got something to work with :)<div><br clear="all">Cheers,<br><br>Tom<br>
<br><br><div class="gmail_quote">On Tue, Mar 8, 2011 at 8:09 PM, Stephen Tetley <span dir="ltr">&lt;<a href="mailto:stephen.tetley@gmail.com">stephen.tetley@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Hi Tom<br>
<br>
Here&#39;s how I&#39;d do comment annotation in the Parser:<br>
<br>
<br>
&gt; type Comment = String<br>
&gt; type Identifier = String<br>
<br>
I suspect data carrying tokens need to pair the data and the comment<br>
so Happy can treat them as a positional reference e.g. $1<br>
<br>
&gt; data Token =<br>
&gt;   TK_identifier (Identifier,Comment)<br>
&gt; | TK_kywd_module Comment<br>
&gt; | ...<br>
<br>
<br>
Productions now have to use smart constructors:<br>
<br>
&gt;<br>
&gt; module    :: { Module }<br>
&gt;           : &#39;%module&#39; mname  defs<br>
&gt;                 { mkModule $1 $2 $3  }<br>
&gt;<br>
<br>
<br>
<br>
&gt; data Module = Module { mod_comment :: Comment<br>
&gt;                      , mod_name    :: String<br>
&gt;                      , mod_body    :: [Def]<br>
&gt;                      }<br>
<br>
<br>
<br>
The &#39;smart&#39; constructor takes the comment before the module<br>
delacration, any comment between the module start token and the module<br>
name is ignored...<br>
<br>
&gt; mkModule :: Comment -&gt; (String,Comment) -&gt; [Def] -&gt; Module<br>
&gt; mkModule outer_comment (mname, _) defs =<br>
&gt;    Module outer_comment mname defs<br>
<br>
<br>
<br>
As for error handling, the strategy is to add error handling<br>
productions after &quot;good&quot; productions.<br>
<br>
Now module can &quot;handle&quot; a missing module name:<br>
<br>
&gt;<br>
&gt; module    :: { Module }<br>
&gt;           : &#39;%module&#39; mname  defs<br>
&gt;                 { mkModule $1 $2 $3  }<br>
&gt;           : &#39;&#39;%module&#39; defs<br>
&gt;                 { badModule $1 $2 }<br>
<br>
<br>
&gt;<br>
&gt; badModule :: Comment [Def] -&gt; Module<br>
&gt; badModule outer_comment defs = Module outer_comment fake_name defs<br>
&gt;   where<br>
&gt;     fake_name = &quot;ERR - parser error reading module name&quot;<br>
&gt;<br>
<br>
Ideally the smart constructors should be in a monad that supports<br>
error logging like Writer.<br>
<br>
As you can see this isn&#39;t a great way of doing things but I&#39;m not sure<br>
you have any other options. Personally I&#39;d see if I could live with<br>
&quot;first fail&quot; instead.<br>
<br>
Best wishes<br>
<font color="#888888"><br>
Stephen<br>
</font><div><div></div><div class="h5"><br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br></div>