Open thumphries opened 7 years ago
I'd love to take a look at this, though I might need to ask a few questions. I've used Lenses in a couple of different Scala libraries, and briefly played around with lens-aeson, but it's all still pretty new to me in Haskell.
Feel free to spend some time on this! The result probably won't be immediately mergeable, but we'll be able to use any prisms you write to build filters and queries down the track.
Take a look at the ones that already exist (there's like five of them, they do all the searching in hgrep): https://github.com/thumphries/hgrep/blob/master/src/Language/Haskell/HGrep/Query.hs#L34
Take a look at a bit of related work I was doing, the topic/filter
branch is probably a better starting point: https://github.com/thumphries/hgrep/commit/91f93a02a40d68e58a914c1f19467fea5e087cd0
In general, if you can write a buncha prisms from HsDecl
to RdrName
or [RdrName]
and clearly label what they're for, preferably with some example Haskell source alongside, that will be really really useful. Create PRs against topic/filter
instead of master
and I'll try my best to answer any questions you have.
Note that I barely know lens, just enough to be dangerous.
I'd also quite like to set up something like tasty-golden
for these prisms.
For each Prism' HsDecl [RdrName]
, have a bunch of Haskell files to use as inputs, and verify that all the right names get matched. That'd also be quite useful, if it sounds more approachable or interesting.
Thanks for all the pointers! I'll give you a shout if i get stuck / have any questions
hi @thumphries i've been pretty ill with a chest infection so i'm only just getting round to looking at this. apologies for the delay!
I could well be missing something but for example, import lists, don't seem to be exposed by HsDecl. It exposes foreign imports, but i don't seem to see anything to find standard imports.
It looks possible using: https://hackage.haskell.org/package/haskell-src-exts (https://hackage.haskell.org/package/haskell-src-exts-1.19.1/docs/Language-Haskell-Exts-Syntax.html#t:ImportDecl)
Don't apologise, there's no hurry! Thanks for spending your time looking and thinking about this, it will be really useful when I try to add complex filtering to hgrep.
I could well be missing something but for example, import lists, don't seem to be exposed by HsDecl. It exposes foreign imports, but i don't seem to see anything to find standard imports.
exactprint gives us a HsModule, so prisms from HsModule to names are what we'd want for things like import lists. You can see the definition of HsModule in HsSyn: https://downloads.haskell.org/~ghc/8.0.2/docs/html/libraries/ghc-8.0.2/HsSyn.html
Need to write as many interesting prisms over HsDecl as we can. Import lists, export lists, patterns, bindings, use sites, weird cases I've missed thus far, etc etc.
These should be in the form
Prism' HsDecl RdrName
orPrism' HsDecl [RdrName]
so they can be trivially added to queries.