Add variables, update file handling

This commit is contained in:
Maxwell Jeffress 2024-12-14 20:31:56 +11:00
parent 09787d7113
commit 00d679715d
2 changed files with 69 additions and 17 deletions

View File

@ -1,4 +1,3 @@
// comment lmao
egg notepad
init {
sendMessage "Hello there!"
@ -9,6 +8,8 @@ init {
js {
alert("this is an alert! i repeat - this is an alert!");
}
val dingus = "dongusify"
var dongus = "dingusify"
}
onRecieving egg * * {

View File

@ -30,6 +30,40 @@ fun splitList(input: String): List<String> {
return result
}
object files {
val outputIndexJS = File("out/index.js")
val outputMessageJS = File("out/message.js}")
val outputHTML = File("out/index.html")
val generatedIndexJS = mutableListOf<String>()
val generatedMessageJS = mutableListOf<String>()
val generatedHTML = mutableListOf<String>()
fun write() {
outputIndexJS.writeText("")
outputMessageJS.writeText("")
outputHTML.writeText("")
for (item in generatedHTML) {
outputHTML.appendText("$item\n")
}
for (item in generatedMessageJS) {
outputMessageJS.appendText("$item\n")
}
for (item in generatedIndexJS) {
outputIndexJS.appendText("$item\n")
}
}
}
fun testValidity(input: List<String>, num: Int): Int {
println("Testing validity of ${input.toString()}...")
if (input[1] != "=") {
println("""Error at line $num: Define your variable with "=", not "${input[1]}"""")
return 1
}
return 0
}
fun main(args: Array<String>) {
println("Chookspeak Language Processor")
println("Let's Go!")
@ -44,17 +78,12 @@ fun main(args: Array<String>) {
println("Your Chookspeak file does not exist.")
return
}
val outputIndexJS = File("out/index.js")
val outputMessageJS = File("out/message.js}")
val outputHTML = File("out/index.html")
outputIndexJS.writeText("")
outputMessageJS.writeText("")
outputHTML.writeText("")
val file = fileLocation.readLines()
var lineCounter = 1
var commenting = 0
var eggName = ""
var status = mutableListOf<String>()
val status = mutableListOf<String>()
val variables = mutableListOf<String>()
for (line in file) {
val lineArgsUnfiltered = splitList(line)
val lineArgs = lineArgsUnfiltered.filterNot { it == "" }
@ -80,8 +109,8 @@ fun main(args: Array<String>) {
return
} else {
eggName = lineArgs[1]
outputIndexJS.appendText("function egg$eggName() {\n")
outputHTML.appendText("""<div id="$eggName" style="display: hidden">${"\n"}""")
files.generatedIndexJS.add("function egg$eggName() {")
files.generatedHTML.add("""<div id="$eggName" style="display: hidden">""")
}
}
if (lineArgs[0] == "}") {
@ -98,18 +127,39 @@ fun main(args: Array<String>) {
}
if (status == listOf("init")) {
if (lineArgs[0] == "log") {
outputIndexJS.appendText("console.log(${lineArgs[1]});\n")
files.generatedIndexJS.add("console.log(${lineArgs[1]});")
}
if (lineArgs[0] == "sendMessage") {
outputIndexJS.appendText("""const egg${eggName}Message = { "type" = "egg-$eggName", "username" = username, "token" = md5(password), "content": ${lineArgs[1]}};${"\n"}""")
outputIndexJS.appendText("ws.send(JSON.stringify(egg${eggName}Message))\n")
files.generatedIndexJS.add("""const egg${eggName}Message = { "type" = "egg-$eggName", "username" = username, "token" = md5(password), "content": ${lineArgs[1]}};${""}""")
files.generatedIndexJS.add("ws.send(JSON.stringify(egg${eggName}Message))")
}
if (lineArgs[0] == "val") {
if (lineArgs[2] == "=") {
files.generatedIndexJS.add("const ${lineArgs[1]} = ${lineArgs[3]};")
} else {
println("Error on line $lineCounter: Define your value with '=', not ${lineArgs[2]}")
}
}
if (lineArgs[0] == "var") {
if (lineArgs[2] == "=") {
testValidity(lineArgs, lineCounter)
files.generatedIndexJS.add("let ${lineArgs[1]} = ${lineArgs[3]};")
variables.add(lineArgs[1])
} else {
println("Error on line $lineCounter: Define your variable with '=', not ${lineArgs[2]}")
}
}
if (variables.contains(lineArgs[0])) {
if (lineArgs[1] == "=") {
//if ()
}
}
}
if (status == listOf("init", "html") && lineArgs[0] != "html") {
outputHTML.appendText("${lineArgs.joinToString(" ")}\n")
files.generatedHTML.add("${lineArgs.joinToString(" ")}")
}
if (status == listOf("init", "js") && lineArgs[0] != "js") {
outputIndexJS.appendText("${lineArgs.joinToString(" ")}\n")
files.generatedIndexJS.add("${lineArgs.joinToString(" ")}")
}
lineCounter ++
} else if (commenting == 1) {
@ -118,6 +168,7 @@ fun main(args: Array<String>) {
commenting = 0
}
}
outputIndexJS.appendText("}\n")
outputHTML.appendText("</div>\n")
files.generatedIndexJS.add("}")
files.generatedHTML.add("</div>")
files.write()
}