IO Operators
This commit is contained in:
parent
b9f419a59d
commit
82a8fccf87
22 changed files with 450 additions and 199 deletions
39
src/interpreter/FileLoader.kt
Normal file
39
src/interpreter/FileLoader.kt
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
4
src/interpreter/Preprocessor.kt
Normal file
4
src/interpreter/Preprocessor.kt
Normal file
|
@ -0,0 +1,4 @@
|
|||
package interpreter
|
||||
|
||||
class Preprocessor {
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue