I need to analyse kotlin files code, to detect the keyword "data" and "?".
The issue is I don't find any libs like JavaParser. I don't need powerfull tools, just something who return me the number of the lines.
Any idea?
I need to analyse kotlin files code, to detect the keyword "data" and "?".
The issue is I don't find any libs like JavaParser. I don't need powerfull tools, just something who return me the number of the lines.
Any idea?
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>
Besides the tools mentioned in other answers, here is another one someone may find useful:
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.
You can try Kastree -- simple library to manipulate Kotlin source code as a set of AST objects.
See this [0] Kotlin code parsing related discussion. They talk about using antlr v4 grammar to parse the Kotlin code.
I have not yet written a Kotlin language grammar for it.
But I have implemented a parser in Kotlin, id that is any use.
It is Kotlin common code, so should work for any target platform.
There is an article about it here, and the code is on github.
https://medium.com/@dr.david.h.akehurst/agl-your-dsl-in-the-web-c9f54595691b
© 2022 - 2024 — McMap. All rights reserved.