mirror of
https://codeberg.org/liliesh/pigeon.git
synced 2026-03-18 22:08:36 +01:00
Did some minor things
This commit is contained in:
parent
6feaada7da
commit
b6d4238dcd
2 changed files with 64 additions and 5 deletions
1
.idea/misc.xml
generated
1
.idea/misc.xml
generated
|
|
@ -1,4 +1,3 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
|
|
|
|||
68
src/Main.kt
68
src/Main.kt
|
|
@ -1,5 +1,65 @@
|
|||
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
||||
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
||||
fun main() {
|
||||
println("Gurr Gurr");
|
||||
import java.io.BufferedReader
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.io.InputStreamReader
|
||||
import java.util.Scanner
|
||||
import kotlin.jvm.Throws
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
var hadError = false
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun main(args: Array<String>) {
|
||||
if(args.size > 1){
|
||||
println("Usage: pigeon [script]")
|
||||
exitProcess(64)
|
||||
} else if (args.size == 1) {
|
||||
runFile(args[0])
|
||||
} else {
|
||||
runPrompt()
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun runFile(path: String) {
|
||||
val bytes = File(path).readBytes()
|
||||
run(bytes.toString())
|
||||
|
||||
if (hadError){
|
||||
exitProcess(65)
|
||||
}
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun runPrompt() {
|
||||
val input = InputStreamReader(System.`in`)
|
||||
val reader = BufferedReader(input)
|
||||
|
||||
while (true) {
|
||||
print("> ")
|
||||
val line = reader.readLine()
|
||||
if (line == null)
|
||||
break
|
||||
|
||||
run(line)
|
||||
hadError = false
|
||||
}
|
||||
}
|
||||
|
||||
fun run(source: String) {
|
||||
val scanner = Scanner(source)
|
||||
val tokens = scanner.tokens()
|
||||
|
||||
tokens.forEach { token ->
|
||||
println("$token")
|
||||
}
|
||||
}
|
||||
|
||||
fun error(line: Int, message: String) {
|
||||
report(line, "", message)
|
||||
}
|
||||
|
||||
fun report(line: Int, where: String, message: String) {
|
||||
System.err.println("[line $line] Error $where: $message")
|
||||
hadError = true
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue