com.strumenta.kolasu.lionweb.ASTGeneratorCLI.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kolasu-lionweb-gen Show documentation
Show all versions of kolasu-lionweb-gen Show documentation
Kolasu classes generation for LIonWeb
@file:JvmName("ASTGeneratorCLI")
package com.strumenta.kolasu.lionweb
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.types.file
import io.lionweb.lioncore.java.language.Language
import io.lionweb.lioncore.java.serialization.JsonSerialization
import java.io.File
import java.io.FileInputStream
class ASTGeneratorCommand : CliktCommand() {
val packageName by argument()
val languageFile by argument().file(mustExist = true, mustBeReadable = true, canBeDir = false)
val destinationDir by argument().file(mustExist = true, canBeFile = false)
val existingKotlinCode by argument().file(mustExist = true, canBeFile = false)
override fun run() {
val existingKotlinClasses = KotlinCodeProcessor().classesDeclaredInDir(existingKotlinCode)
val jsonser = JsonSerialization.getStandardSerialization()
jsonser.instanceResolver.addTree(StarLasuLWLanguage)
val language = jsonser.deserializeToNodes(FileInputStream(languageFile)).first() as Language
val ktFiles = ASTGenerator(packageName, language).generateClasses(existingKotlinClasses)
ktFiles.forEach {
File(destinationDir, it.path).writeText(it.code)
}
}
}
fun main(args: Array) {
ASTGeneratorCommand().main(args)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy