IO Operators

This commit is contained in:
Tibo De Peuter 2025-04-27 20:11:15 +02:00
parent b9f419a59d
commit 82a8fccf87
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
22 changed files with 450 additions and 199 deletions

View file

@ -0,0 +1,39 @@
package interpreter
import io.Logger
import parser.ScriptParser
import prolog.Program
import prolog.ast.logic.Clause
class FileLoader {
private val parser = ScriptParser()
fun load(filePath: String): () -> Unit {
val input = readFile(filePath)
Logger.debug("Parsing content of $filePath")
val clauses: List<Clause> = parser.parse(input)
Program.load(clauses)
// TODO Pass next commands to execute
return {}
}
fun readFile(filePath: String): String {
try {
Logger.debug("Reading $filePath")
val file = java.io.File(filePath)
if (!file.exists()) {
Logger.error("File $filePath does not exist")
throw IllegalArgumentException("File not found: $filePath")
}
return file.readText()
} catch (e: Exception) {
Logger.error("Error reading file: $filePath")
throw RuntimeException("Error reading file: $filePath", e)
}
}
}

View file

@ -0,0 +1,4 @@
package interpreter
class Preprocessor {
}

View file

@ -1,23 +0,0 @@
package interpreter
import better_parser.PrologParser
class SourceFileReader {
private val parser = PrologParser()
fun readFile(filePath: String) {
return try {
val file = java.io.File(filePath)
if (!file.exists()) {
throw IllegalArgumentException("File not found: $filePath")
}
val content = file.readText()
// Parse the content using SimpleSourceParser
parser.parse(content)
} catch (e: Exception) {
throw RuntimeException("Error reading file: $filePath", e)
}
}
}