<div dir="ltr"><div><div>It is a structure proposed to capture extra commas in record declarations, which I have abused for use here.<br><br></div>I have subsequently realised that I am using it to capture EVERY comma, and sometimes semicolons, so its naming is even worse for my use.<br><br></div>Hence I am pretty sure it is something that should change, but I am not sure whether it should change in the hsSyn or be captured in annotations, or what the best mixture between those two is.<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 9, 2014 at 6:03 PM, Carter Schonwald <span dir="ltr"><<a href="mailto:carter.schonwald@gmail.com" target="_blank">carter.schonwald@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">One small question I have is this: why's it called a comma list?</p>
<div class="gmail_quote"><div><div class="h5">On Oct 8, 2014 12:33 PM, "Alan & Kim Zimmerman" <<a href="mailto:alan.zimm@gmail.com" target="_blank">alan.zimm@gmail.com</a>> wrote:<br type="attribution"></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div>I am currently working annotations into the parser, provided them as a separate structure at the end of the parse, indexed to the original by SrcSpan and AST element type.<br><br></div>The question I have is how to capture commas and semicolons in lists of items.<br><br></div>There are at least three ways of doing this<br><br></div>1. Make sure each of the items is Located, and add the possible comma location to the annotation structure for it.<br><br></div>This has the drawback that all instances of the AST item annotation have the possible comma location in them, and it does not cope with multiple separators where these are allowed.<br><br><br></div>2. Introduce a new hsSyn structure to explicitly capture comma-separated lists.<br><br></div>This is the current approach I am taking, modelled on the OrdList implementation, but with an extra constructor to capture the separator location.<br><br></div>Thus<br><br>```<br>data HsCommaList a<br>  = Empty<br>  | Cons a (HsCommaList a)<br>  | ExtraComma SrcSpan (HsCommaList a)<br>       -- ^ We need a SrcSpan for the annotation<br>  | Snoc (HsCommaList a) a<br>  | Two (HsCommaList a) -- Invariant: non-empty<br>        (HsCommaList a) -- Invariant: non-empty<br>```<br><br><br></div>3. Change the lists to be of type `[Either SrcSpan a]` to explicitly capture the comma locations in the list.<br><br><br></div>4. A fourth way is to add a list of SrcSpan to the annotation for the parent structure of the list, simply tracking the comma positions. This will make working with the annotations complicated though.<br><br><br></div>I am currently proceeding with option 2, but would appreciate some comment on whether this is the best approach to take.  <br><br>Option 2 will allow the AST to capture the extra commas in record constructors, as suggested by SPJ in the debate on that feature.<br><br><br></div>Regards<br></div>  Alan<br><div><div><br></div></div></div>
<br></div></div>_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/ghc-devs" target="_blank">http://www.haskell.org/mailman/listinfo/ghc-devs</a><br>
<br></blockquote></div>
</blockquote></div><br></div>