EPA: encode keywords directly in AST
I voiced my concerns about the design of in-tree exactprint annotations here: !2418 (comment 338403). The result of the discussion was that we’d go with my proposed design, but implement it post-merge. This ticket is to track the proposed refactoring.
The new design is described as “Plan B” at https://gitlab.haskell.org/ghc/ghc/-/wikis/api-annotations. The idea is to introduce a new data type, HsToken
, defined as follows:
type LHsToken tok p = XRec p (HsToken tok)
data HsToken (tok :: Symbol) = HsTok
Then we record token information directly in the syntax tree:
data HsExpr p
= ...
...
| HsLet (XLet p)
+ !(LHsToken "let")
(LHsLocalBinds p)
+ !(LHsToken "in")
(LHsExpr p)
While working on this, I found the following commands useful:
hadrian/build -j --flavour=Quick --freeze1 test --test-root-dirs=testsuite/tests/printer
hadrian/build -j --flavour=Quick --freeze1 test --test-root-dirs=testsuite/tests/ghc-api/exactprint