Crinja: How to traverse a template's nodes?

For a static site generator I want to know all the files a Crinja template includes or extends so I can mark the template as changed.

Currently I am doing this, which works but doesn’t catch them all:

    deps = [] of String
    nodes = \
        .select { |n| n.@name == "include" }.each { |n|
      deps << "kv://#{n.@arguments[0].value}"

I can’t figure out how to visit all the tree and catch all the TagNodes. I have looked at the source code and I guess some kind of Visitor? Any help appreciated.

PS: I also would love to be able to get a list of all the names of filters used in a template for similar reasons.

Yes, you’d use the visitor pattern for this.
I can’t tell exactly how to build this visitor off the top of my head.