I’m experimenting with the (fantastic!) purescript-language-cst-parser library but I’m struggling a little bit with its traversals.
I’m trying to extract all bound identifiers and their types from a module, but keeping the hierarchy information when the identifier is bound in a
where, etc. clauses.
For instance (ignoring the fact I also need the types), traversing the module:
module MyModule where import Prelude f :: Int f = a + b where a = 1 b = 2 g :: String g = ""
would give me a result similar to:
[ [ "f" ], [ "f", "a" ], [ "f", "b" ], [ "g" ] ]
or any other data structure, like a tree, that keeps this hierarchy.
I don’t have a whole lot of experience doing this kind of thing, but in the past I’ve solved this problem by writing a traversal function that allowed me to run separate functions for both before and after a certain node was visited (a mix of top-down and bottom-up?), and using a
State monad to keep intermediate results. Probably a naive solution in the eyes of someone who’s experienced in writing parsers.
Any pointers on how I can accomplish this with