error/warning colors

This commit is contained in:
Irmen de Jong 2018-12-04 00:54:18 +01:00
parent bf5f7a271e
commit 08224d5367
2 changed files with 10 additions and 0 deletions

View File

@ -136,14 +136,20 @@ fun main(args: Array<String>) {
println("\nTotal compilation+assemble time: ${(endTime-startTime)/1000.0} sec.")
} catch (px: ParsingFailedError) {
System.err.print("\u001b[91m") // bright red
System.err.println(px.message)
System.err.print("\u001b[0m") // reset
exitProcess(1)
} catch (x: Exception) {
print("\u001b[91m") // bright red
println("\n* internal error *")
print("\u001b[0m") // reset
System.out.flush()
throw x
} catch (x: NotImplementedError) {
print("\u001b[91m") // bright red
println("\n* internal error: missing feature/code *")
print("\u001b[0m") // reset
System.out.flush()
throw x
}

View File

@ -20,6 +20,7 @@ fun Module.checkValid(globalNamespace: INameScope, compilerOptions: CompilationO
fun printErrors(errors: List<Any>, moduleName: String) {
val reportedMessages = mutableSetOf<String>()
print("\u001b[91m") // bright red
errors.forEach {
val msg = it.toString()
if(msg !in reportedMessages) {
@ -27,17 +28,20 @@ fun printErrors(errors: List<Any>, moduleName: String) {
reportedMessages.add(msg)
}
}
print("\u001b[0m") // reset color
if(reportedMessages.isNotEmpty())
throw ParsingFailedError("There are ${reportedMessages.size} errors in module '$moduleName'.")
}
fun printWarning(msg: String, position: Position, detailInfo: String?=null) {
print("\u001b[93m") // bright yellow
print("$position Warning: $msg")
if(detailInfo==null)
print("\n")
else
println(": $detailInfo")
print("\u001b[0m") // bright yellow
}