Feature: NeoLang command line program
This commit is contained in:
parent
f43c2dde2e
commit
1698d78439
40
NeoLang/src/main/java/io/neolang/command/Main.kt
Normal file
40
NeoLang/src/main/java/io/neolang/command/Main.kt
Normal 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 ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user