[core,swift] Refactor antlr implementation#2463
Conversation
PMD Node implementations don't extend antlr classes anymore
Generated by 🚫 Danger |
7b64fb4 to
fbc93e4
Compare
adangel
left a comment
There was a problem hiding this comment.
@oowekyala Many thanks for this refactoring!
I don't fully understand yet, what you did and how the new nodes/abstractions etc. play together.
We need to make sure, to provide a proper documentation at the end: for developers, who want to
add a new antlr based language (see #2500 and #2501) but also for developers, who want to contribute
to the inners of PMD (like us) -> see #2517 . Otherwise I fear, this won't be maintainable if you
are not an expert...
I assume, that the API right now is not fully fleshed out yet (since we have also already some legacy code
in PMD 7, like joinTokenText) and will mature (also with #2589 which is on my TODO list).
I've started some small parts on https://github.com/pmd/pmd/wiki/PMD-7.0.0-API
(section "AST Visitors").
Please be patient, while I walk through your other PRs.
[swift] Refactor antlr implementation #2463
|
Thanks for merging! Picking up #1881 is in my todo list.
I feel the same way, it's very messy. But what we're doing in the first place is shady, we're fooling antlr parsers into building PMD nodes. This looks more and more like a bad idea tbh. |
Describe the PR
GenericNode<SwiftNode>, take measures to enforce this is safe (eg add SwiftErrorNode, SwiftTerminalNode, add some runtime checks to make sure that antlr only adds children from our implementation).joinTokenTextand deprecated, which we can do since we don't inherit it from ParserRuleContext anymoreIt's still unclear how we can add new attributes to antlr nodes, since they're all generated into the same file.... For the same reason, we might run into trouble if we try to add functionality to the RootNode interface. I guess we can deal with that later
Of note, that the generated tree is not an abstract syntax tree in any way, it's a parse tree. There's a node for every token, or every error, which makes gigantic trees. Antlr recommends building a separate AST if we want one, but then we would have to define all the nodes and visitor interface ourselves... This is a fundamental problem with using antlr, possibly it should be mentioned somewhere in the doc.
Related issues
Ready?
./mvnw clean verifypasses (checked automatically by travis)