Argument parsing
This commit is contained in:
parent
32165a90f5
commit
8e6a34a231
5 changed files with 63 additions and 8 deletions
42
src/Main.kt
42
src/Main.kt
|
@ -1,15 +1,45 @@
|
|||
import com.sun.org.apache.bcel.internal.util.Args
|
||||
import com.xenomachina.argparser.ArgParser
|
||||
import com.xenomachina.argparser.mainBody
|
||||
import interpreter.FileLoader
|
||||
import io.GhentPrologArgParser
|
||||
import io.Logger
|
||||
import prolog.Program
|
||||
import prolog.ast.logic.Clause
|
||||
import repl.Repl
|
||||
|
||||
fun main() {
|
||||
// TODO Make this a command line argument
|
||||
// Turn on debug mode
|
||||
Logger.level = Logger.Level.DEBUG
|
||||
fun main(args: Array<String>) = mainBody {
|
||||
// Parse command line arguments
|
||||
val parsedArgs = ArgParser(args).parseInto(::GhentPrologArgParser)
|
||||
|
||||
FileLoader().load("tests/parser/resources/parent.pl")
|
||||
parsedArgs.run {
|
||||
val loader = FileLoader()
|
||||
|
||||
Repl().start()
|
||||
// Set the verbosity level
|
||||
Logger.level = verbosity
|
||||
|
||||
// Check if script was provided
|
||||
for (file in script) {
|
||||
loader.load(file)
|
||||
}
|
||||
|
||||
// Check if REPL was requested
|
||||
if (repl) {
|
||||
Repl().start()
|
||||
} else {
|
||||
Logger.warn("REPL not started. Use -r or --repl to start the REPL.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun help() {
|
||||
println("""
|
||||
Ghent Prolog: A Prolog interpreter in Kotlin
|
||||
|
||||
Options:
|
||||
-s, --source <file> Specify the source file to load
|
||||
-r, --repl Start the REPL (default)
|
||||
-v, --verb
|
||||
-h, --help Show this help message
|
||||
""".trimIndent())
|
||||
}
|
||||
|
|
Reference in a new issue