
Dear Alan,
Nice going and thanks for undertaking yet another useful AST transformation!
A few thoughts (do with them as you see fit):
- Always called "ann"; doesn't this require OverloadedRecordFields? You're in danger of delaying your modification (scheduled to land in 7.10). Other than that, as before, from a design perspective: yes please.
- In terms of presentation/comments; when I first started looking at (i.e. traversing, selectively printing etc.) the AST, I was always really annoyed that every child in the tree has one extra step of indirection, due to the location annotations being "L loc thing", as opposed to a loc-field as part of the thing. I would simply call it annotation (no talk of external tool writers). In time, I hope GHC-annotations also move to that field.
Regards,
Philip
________________________________
From: Alan & Kim Zimmerman
In general I’m fine with this direction of travel. Some specifics:
· You’d have to be careful to document, for every data constructor in HsSyn, what the association between the [SrcSpan] in the SrcSpanInfo and the “sub-entities” · Many of the sub-entities will have their own SrcSpanInfo wrapped around them, so there’s some unhelpful duplication. Maybe you only want the SrcSpanInfo to list the [SrcSpan]s for the sub-entities (like the syntactic keywords) that do not show up as children in the syntax tree? Anyway do by all means create a GHC Trac wiki page to describe your proposed design, concretely.
Simon
From: ghc-devs [mailto:ghc-devs-bounces@haskell.orgmailto:ghc-devs-bounces@haskell.org] On Behalf Of Alan & Kim Zimmerman Sent: 28 August 2014 15:00 To: ghc-devs@haskell.orgmailto:ghc-devs@haskell.org Subject: GHC AST Annotations
Now that the landmines have hopefully been cleared from the AST via [1] I would like to propose changing the location information in the AST.
Right now the locations of syntactic markers such as do/let/where/in/of in the source are discarded from the AST, although they are retained in the rich token stream.
The haskell-src-exts package deals with this by means of using the SrcSpanInfo data type [2] which contains the SrcSpan as per the current GHC Located type but also has a list of SrcSpan s for the syntactic markers, depending on the particular AST fragment being annotated.
In addition, the annotation type is provided as a parameter to the AST, so that it can be changed as required, see [3].
The motivation for this change is then
1. Simplify the roundtripping and modification of source by explicitly capturing the missing location information for the syntactic markers.
2. Allow the annotation to be a parameter so that it can be replaced with a different one in tools, for example HaRe would include the tokens for the AST fragment leaves.
3. Aim for some level compatibility with haskell-src-exts so that tools developed for it could be easily ported to GHC, for example exactprint [4].
I would like feedback as to whether this would be acceptable, or if the same goals should be achieved a different way.
Regards
Alan
[1] https://phabricator.haskell.org/D157
[2] http://hackage.haskell.org/package/haskell-src-exts-1.15.0.1/docs/Language-H...
[3] http://hackage.haskell.org/package/haskell-src-exts-1.15.0.1/docs/Language-H...
[4] http://hackage.haskell.org/package/haskell-src-exts-1.15.0.1/docs/Language-H...
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.orgmailto:ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs