how to parse kotlin code?
Besides the tools mentioned in other answers, here is another one someone may find useful:
https://github.com/kotlinx/ast
You can try Kastree -- simple library to manipulate Kotlin source code as a set of AST objects.
https://github.com/cretz/kastree
You would need to either find a Kotlin parser, or write your own.
For this subset of parsing you may be able to cheat, as data
is a keyword, so if you see data with non letters each side you know it is the keyword.
For ?
, it depends which meaning you want, the elvis one can be detected by the dot else try the nullable meaning if the ?
is next to a letter.
I use antlr4 to do it. And I create an open source lib: https://github.com/sarahBuisson/kotlin-parser
<dependency
<groupId>com.github.sarahbuisson</groupId>
<artifactId>kotlin-parser</artifactId>
</dependency>