Add variables, update file handling
This commit is contained in:
parent
09787d7113
commit
00d679715d
|
@ -1,4 +1,3 @@
|
||||||
// comment lmao
|
|
||||||
egg notepad
|
egg notepad
|
||||||
init {
|
init {
|
||||||
sendMessage "Hello there!"
|
sendMessage "Hello there!"
|
||||||
|
@ -9,6 +8,8 @@ init {
|
||||||
js {
|
js {
|
||||||
alert("this is an alert! i repeat - this is an alert!");
|
alert("this is an alert! i repeat - this is an alert!");
|
||||||
}
|
}
|
||||||
|
val dingus = "dongusify"
|
||||||
|
var dongus = "dingusify"
|
||||||
}
|
}
|
||||||
|
|
||||||
onRecieving egg * * {
|
onRecieving egg * * {
|
||||||
|
|
|
@ -30,6 +30,40 @@ fun splitList(input: String): List<String> {
|
||||||
return result
|
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>) {
|
fun main(args: Array<String>) {
|
||||||
println("Chookspeak Language Processor")
|
println("Chookspeak Language Processor")
|
||||||
println("Let's Go!")
|
println("Let's Go!")
|
||||||
|
@ -44,17 +78,12 @@ fun main(args: Array<String>) {
|
||||||
println("Your Chookspeak file does not exist.")
|
println("Your Chookspeak file does not exist.")
|
||||||
return
|
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()
|
val file = fileLocation.readLines()
|
||||||
var lineCounter = 1
|
var lineCounter = 1
|
||||||
var commenting = 0
|
var commenting = 0
|
||||||
var eggName = ""
|
var eggName = ""
|
||||||
var status = mutableListOf<String>()
|
val status = mutableListOf<String>()
|
||||||
|
val variables = mutableListOf<String>()
|
||||||
for (line in file) {
|
for (line in file) {
|
||||||
val lineArgsUnfiltered = splitList(line)
|
val lineArgsUnfiltered = splitList(line)
|
||||||
val lineArgs = lineArgsUnfiltered.filterNot { it == "" }
|
val lineArgs = lineArgsUnfiltered.filterNot { it == "" }
|
||||||
|
@ -80,8 +109,8 @@ fun main(args: Array<String>) {
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
eggName = lineArgs[1]
|
eggName = lineArgs[1]
|
||||||
outputIndexJS.appendText("function egg$eggName() {\n")
|
files.generatedIndexJS.add("function egg$eggName() {")
|
||||||
outputHTML.appendText("""<div id="$eggName" style="display: hidden">${"\n"}""")
|
files.generatedHTML.add("""<div id="$eggName" style="display: hidden">""")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (lineArgs[0] == "}") {
|
if (lineArgs[0] == "}") {
|
||||||
|
@ -98,18 +127,39 @@ fun main(args: Array<String>) {
|
||||||
}
|
}
|
||||||
if (status == listOf("init")) {
|
if (status == listOf("init")) {
|
||||||
if (lineArgs[0] == "log") {
|
if (lineArgs[0] == "log") {
|
||||||
outputIndexJS.appendText("console.log(${lineArgs[1]});\n")
|
files.generatedIndexJS.add("console.log(${lineArgs[1]});")
|
||||||
}
|
}
|
||||||
if (lineArgs[0] == "sendMessage") {
|
if (lineArgs[0] == "sendMessage") {
|
||||||
outputIndexJS.appendText("""const egg${eggName}Message = { "type" = "egg-$eggName", "username" = username, "token" = md5(password), "content": ${lineArgs[1]}};${"\n"}""")
|
files.generatedIndexJS.add("""const egg${eggName}Message = { "type" = "egg-$eggName", "username" = username, "token" = md5(password), "content": ${lineArgs[1]}};${""}""")
|
||||||
outputIndexJS.appendText("ws.send(JSON.stringify(egg${eggName}Message))\n")
|
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") {
|
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") {
|
if (status == listOf("init", "js") && lineArgs[0] != "js") {
|
||||||
outputIndexJS.appendText("${lineArgs.joinToString(" ")}\n")
|
files.generatedIndexJS.add("${lineArgs.joinToString(" ")}")
|
||||||
}
|
}
|
||||||
lineCounter ++
|
lineCounter ++
|
||||||
} else if (commenting == 1) {
|
} else if (commenting == 1) {
|
||||||
|
@ -118,6 +168,7 @@ fun main(args: Array<String>) {
|
||||||
commenting = 0
|
commenting = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
outputIndexJS.appendText("}\n")
|
files.generatedIndexJS.add("}")
|
||||||
outputHTML.appendText("</div>\n")
|
files.generatedHTML.add("</div>")
|
||||||
|
files.write()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user