ngx I don't want to interfere in the discussion but IMHO, the AST must be as faithful to the bnf as possible.
Oh, not to worry. By all means, interfere in the discussion! (After all, if we were intent on having a private conversation, we have the means to do that as well, so if it's here...)
I think the thing is that if you're going to have a Java grammar and tell people: "Here, you can use this in your own projects" then, yeah, it really has to just generate the most bloody-minded AST with ALL the information. And it does. You have every last superfluous delimiter and so on. This is simply because, since we can't anticipate all the ways this would be used, we don't throw away any information a user might conceivably need.
But then it might frequently be unwieldy to use, but I don't really know for sure whether the more common solution is to work with that AST and ignore all the extraneous information, or just with a Visitor, traverse the tree and generate something more streamlined for what you are doing and then work with that.
Oh, by the way, I notice that the example code you provide uses legacy syntax. Also, when you write: "using one of my numerous node finding methods", I have to think that you are aware that there are more modern versions of that sort of thing already by default in the generated Node.java. The thing is that, because of all the refactoring in JavaCC 21 (I should really start saying CongoCC all the time) the ones I put in are much more modern, idiomatic Java, so where you have something like:
if (n.childs[2].id == JJT_OBJECT_WRITE) {
the newer more approved way would be more like:
if (n.getChild(2) instanceof ObjectWrite) {
I guess in the original JJTree generated API, the generated ASTXXX Node objects have an id field that is a static final int (not a type-safe Enum!) that represents the node's "type". I don't know whether this kind of thing is a result of slavishly copying the way older C-based tools like YACC or Bison worked. I mean, once you're in an OOP language like Java, it just makes more sense to just use the language's type system, no? (Even back then using a much older version of Java.)
Well, I'd have to think you're using the newer API in new code, no? And also, with generics, the code is more type-safe, like where you have ArrayList<SimpleNode>, you can use the specialized node subclass instead, like:
List<MethodDeclaration> methods = node.childrenOfType(MethodDeclaration.class);
And you can write things that are much more elegant, maybe like:
for (MethodDeclaration md : compilationUnit.descendants(MethodDeclaration.class, md->md.isPublic()) {
...
}
(The descendants method can have a second parameter that is a Predicate, which can be written using a lambda, so...)
So the above snippet would recursively iterate over all the MethodDeclaration objects in the source file that are public. (And look, Ma! No casting!)
Well, maybe you think I point out these things just to show off a bit. (And you'd be right...) But it's not such a big deal either. I got satisfaction out of doing that, but it's also kind of obvious, really, I think. I mean, once you see that all these features were added to the Java language, like generics and lambdas, it just becomes kind of obvious to use them this way in a generic Node traversal sort of API, don't you think? So, it's really kind of amazing when you look at the legacy JavaCC, just how stuck in a kind of time warp that whole thing is. Just about no use of any language feature that came after Java 1!
So that old thing is there and you have had people for years pretending that it's an active project, but really, properly understood, the situation is laughable. It's a kind of museum piece really. But then you approach people who are still using that and tell them that there is a much more modernized version of the tool and far more often than not, you can't even get them to look at it!
Well, maybe with a sexy new name like Congo... But, really, my earlier belief that you could largely get the older user base to switch over, that just turned out to be false. A few people, like you, but overall, that just doesn't work very much. There's a need to market this to new users, probably people who never used a parser generator before. I think that's more where the future of this project lies. Oh well, 'nuff said for now....