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.") println("\nTotal compilation+assemble time: ${(endTime-startTime)/1000.0} sec.")
} catch (px: ParsingFailedError) { } catch (px: ParsingFailedError) {
System.err.print("\u001b[91m") // bright red
System.err.println(px.message) System.err.println(px.message)
System.err.print("\u001b[0m") // reset
exitProcess(1) exitProcess(1)
} catch (x: Exception) { } catch (x: Exception) {
print("\u001b[91m") // bright red
println("\n* internal error *") println("\n* internal error *")
print("\u001b[0m") // reset
System.out.flush() System.out.flush()
throw x throw x
} catch (x: NotImplementedError) { } catch (x: NotImplementedError) {
print("\u001b[91m") // bright red
println("\n* internal error: missing feature/code *") println("\n* internal error: missing feature/code *")
print("\u001b[0m") // reset
System.out.flush() System.out.flush()
throw x throw x
} }

View File

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