sirthias / pegdown

A pure-Java Markdown processor based on a parboiled PEG parser supporting a number of extensions
http://pegdown.org
Apache License 2.0
1.29k stars 217 forks source link

Visitor<T> instead of Visitor #151

Open voiser opened 9 years ago

voiser commented 9 years ago

Hi,

In order to perform AST transformations, like filtering or transcompiling, the Visitor interface could be redefined like:

interface Visitor<T> {
   ...
   T visit(BlahBlahNode node);
   ...
}

And the Node interface should offer something like:

interface Node {
    T accept(Visitor<T> v)
}

That would let us do something like:

MyASTNode transformed = rootNode.visit(new Visitor<MyASTNode>  {...})

Current visitors could be declared as:

class ... implements Visitor<Void>

I think this change would have a low impact in the code.

What do you think?