-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9167c5
commit f75d531
Showing
5 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Hello, {{name}}! | ||
#if {{wishNiceDay}} #then | ||
Have a nice day :) | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "Iliyan", | ||
"wishNiceDay": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,41 @@ | ||
package com.ivy.quickcode | ||
|
||
import com.ivy.quickcode.data.QCVariableValue | ||
import kotlinx.serialization.json.Json | ||
import kotlinx.serialization.json.JsonPrimitive | ||
import kotlinx.serialization.json.boolean | ||
import kotlinx.serialization.json.booleanOrNull | ||
import java.nio.file.Files | ||
import java.nio.file.Paths | ||
|
||
fun main(args: Array<String>) { | ||
println("QuickCode compiler TODO...") | ||
if (args.size != 2) { | ||
println("Invalid arguments!") | ||
return | ||
} | ||
|
||
val template = readFileContent(args[0]) | ||
val inputJson = readFileContent(args[1]) | ||
val rawInput: Map<String, JsonPrimitive> = Json.decodeFromString(inputJson) | ||
val input = rawInput.map { (key, value) -> | ||
key to when { | ||
value.isString -> QCVariableValue.Str(value.content) | ||
value.booleanOrNull != null -> QCVariableValue.Bool(value.boolean) | ||
else -> error("Unsupported input type \"$key\"") | ||
} | ||
}.toMap() | ||
|
||
println("Input:") | ||
println(input) | ||
|
||
val compiler = QuickCodeCompiler() | ||
val result = compiler.execute(template, input) | ||
println("----------------") | ||
println("----------------") | ||
println(result) | ||
} | ||
|
||
fun readFileContent(relativePath: String): String { | ||
val path = Paths.get(relativePath) | ||
return Files.readString(path) | ||
} |