Feature: NeoLang command line program

This commit is contained in:
zt515 2017-08-02 17:43:47 +08:00
parent f43c2dde2e
commit 1698d78439

View File

@ -0,0 +1,40 @@
package io.neolang.command
import io.neolang.parser.NeoLangParser
import java.io.FileInputStream
/**
* @author kiva
*/
class Main {
companion object {
@JvmStatic
fun main(args: Array<String>) {
if (args.isEmpty()) {
println("Usage: NeoLang <program.nl>")
return
}
val parser = NeoLangParser()
args.forEach {
val programCode = readFully(it)
parser.setInputSource(programCode)
val ast = parser.parse()
println("Compile `$it' -> $ast")
}
return
}
private fun readFully(file: String): String {
try {
FileInputStream(file).use {
val bytes = ByteArray(it.available())
it.read(bytes)
return String(bytes)
}
} catch (e: Exception) {
return ""
}
}
}
}