Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to parse kotlin code?

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?

like image 259
sab Avatar asked Aug 30 '17 09:08

sab


People also ask

How to parse HTML in Android using Kotlin?

This example demonstrates how to parse HTML in Android using Kotlin. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the given dependency in the build.gradle (Module: app)

How to create a Kotlin object from a string in Java?

Create a UsingGson.kt file under the serialize folder and copy-paste the following code into the file. We are sure you have understood that the first step creates a JSON representation of our object, and the second step creates a class that will be used to create a Kotlin object from the string.

What are some tools to manipulate Kotlin source code?

You can try Kastree -- simple library to manipulate Kotlin source code as a set of AST objects. Show activity on this post. Besides the tools mentioned in other answers, here is another one someone may find useful:

What are the advantages of Kotlin language?

And kotlin language is very easy to write and idiomatic. Not only evaluate expressions with +,-,*,/ but also can parse and evaluate functions like sin, cos ,log etc.


1 Answers

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>
like image 68
sab Avatar answered Sep 17 '22 17:09

sab