Skip to content

Commit

Permalink
add generate functions
Browse files Browse the repository at this point in the history
  • Loading branch information
seniorjoinu committed Sep 16, 2020
1 parent 7302e7e commit f11c160
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ dependencies {
implementation 'com.github.kittinunf.fuel:fuel-coroutines:2.2.3'
implementation 'co.nstant.in:cbor:0.9'
implementation 'net.i2p.crypto:eddsa:0.3.0'
implementation 'com.github.square:kotlinpoet:1.6.0'
implementation 'com.github.h0tk3y.betterParse:better-parse-jvm:0.4.0'

api 'com.github.square:kotlinpoet:1.6.0'

testImplementation(
'org.junit.jupiter:junit-jupiter:5.6.2',
'org.spockframework:spock-core:2.0-M3-groovy-3.0',
Expand Down
29 changes: 28 additions & 1 deletion src/main/kotlin/senior/joinu/candid/CandidCodeGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.github.h0tk3y.betterParse.grammar.parseToEnd
import com.squareup.kotlinpoet.FileSpec
import senior.joinu.candid.idl.IDLGrammar
import senior.joinu.candid.transpile.KtTranspiler
import java.io.File
import java.nio.charset.Charset
import java.nio.charset.StandardCharsets
import java.nio.file.Path
Expand All @@ -23,7 +24,33 @@ object CandidCodeGenerator {
) : Source()
}

fun generateFor(
fun generate(
input: Source,
file: File,
genPackage: String = "",
) {
generateFor(input, genPackage).writeTo(file)
}

fun generate(
input: Source,
file: Path,
genPackage: String = "",
) {
generateFor(input, genPackage).writeTo(file)
}

fun generate(
input: Source,
genPackage: String = "",
): String {
val sb = StringBuilder()
generateFor(input, genPackage).writeTo(sb)

return sb.toString()
}

internal fun generateFor(
input: Source,
genPackage: String = ""
): FileSpec {
Expand Down

0 comments on commit f11c160

Please sign in to comment.