Skip to content

Commit a4d0589

Browse files
committed
fix errors like parse error still printed in color when -plaintext is set
1 parent e375f6a commit a4d0589

File tree

8 files changed

+20
-78
lines changed

8 files changed

+20
-78
lines changed

codeCore/src/prog8/code/core/IErrorReporter.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ interface IErrorReporter {
1313
}
1414

1515
fun noErrorForLine(position: Position): Boolean
16+
17+
fun print_single_error(errormessage: String)
1618
}

codeGenCpu6502/test/Dummies.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ internal class ErrorReporterForTests(private val throwExceptionAtReportIfErrors:
6868

6969
override fun noErrors(): Boolean = errors.isEmpty()
7070
override fun noErrorForLine(position: Position) = !errors.any { ":${position.line}:" in it }
71+
override fun print_single_error(errormessage: String) { /* prints nothing in tests */ }
7172

7273
override fun report() {
7374
infos.forEach { println("UNITTEST COMPILATION REPORT: INFO: $it") }

codeGenIntermediate/test/Dummies.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ internal class ErrorReporterForTests(private val throwExceptionAtReportIfErrors:
6666

6767
override fun noErrors(): Boolean = errors.isEmpty()
6868
override fun noErrorForLine(position: Position) = !errors.any { ":${position.line}:" in it }
69+
override fun print_single_error(errormessage: String) { /* prints nothing in tests */ }
6970

7071
override fun report() {
7172
infos.forEach { println("UNITTEST COMPILATION REPORT: INFO: $it") }

compiler/src/prog8/compiler/Compiler.kt

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,7 @@ fun compileProgram(args: CompilerArguments): CompilationResult? {
200200
}
201201
return CompilationResult(resultingProgram!!, ast, compilationOptions, importedFiles)
202202
} catch (px: ParseError) {
203-
System.out.flush()
204-
System.err.print("\n\u001b[91m") // bright red
205-
System.err.println("${px.position.toClickableStr()} parse error: ${px.message}".trim())
206-
System.err.print("\u001b[0m") // reset
203+
args.errors.print_single_error("${px.position.toClickableStr()} parse error: ${px.message}".trim())
207204
} catch (ac: ErrorsReportedException) {
208205
if(args.printAst1 && resultingProgram!=null) {
209206
println("\n*********** COMPILER AST *************")
@@ -220,32 +217,17 @@ fun compileProgram(args: CompilerArguments): CompilationResult? {
220217
}
221218
}
222219
if(!ac.message.isNullOrEmpty()) {
223-
System.out.flush()
224-
System.err.print("\n\u001b[91m") // bright red
225-
System.err.println(ac.message)
226-
System.err.print("\u001b[0m") // reset
220+
args.errors.print_single_error(ac.message!!)
227221
}
228222
} catch (nsf: NoSuchFileException) {
229-
System.out.flush()
230-
System.err.print("\n\u001b[91m") // bright red
231-
System.err.println("File not found: ${nsf.message}")
232-
System.err.print("\u001b[0m") // reset
223+
args.errors.print_single_error("File not found: ${nsf.message}")
233224
} catch (ax: AstException) {
234-
System.out.flush()
235-
System.err.print("\n\u001b[91m") // bright red
236-
System.err.println(ax.toString())
237-
System.err.print("\u001b[0m") // reset
225+
args.errors.print_single_error(ax.toString())
238226
} catch (x: Exception) {
239-
print("\n\u001b[91m") // bright red
240-
println("\n* internal error *")
241-
print("\u001b[0m") // reset
242-
System.out.flush()
227+
args.errors.print_single_error("\ninternal error")
243228
throw x
244229
} catch (x: NotImplementedError) {
245-
print("\n\u001b[91m") // bright red
246-
println("\n* internal error: missing feature/code *")
247-
print("\u001b[0m") // reset
248-
System.out.flush()
230+
args.errors.print_single_error("\ninternal error: missing feature/code")
249231
throw x
250232
}
251233

compiler/src/prog8/compiler/ErrorReporter.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ internal class ErrorReporter(val colors: IConsoleColors): IErrorReporter {
9595
override fun noErrors() = messages.none { it.severity==MessageSeverity.ERROR }
9696
override fun noErrorForLine(position: Position) = !messages.any { it.position.line==position.line && it.severity!=MessageSeverity.INFO }
9797

98+
override fun print_single_error(errormessage: String) {
99+
System.out.flush()
100+
colors.error(System.err)
101+
System.err.println(errormessage)
102+
colors.normal(System.err)
103+
}
98104

99105
interface IConsoleColors {
100106
fun error(printer: PrintStream)

compiler/test/helpers/ErrorReporterForTests.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ internal class ErrorReporterForTests(private val throwExceptionAtReportIfErrors:
3333

3434
override fun noErrors(): Boolean = errors.isEmpty()
3535
override fun noErrorForLine(position: Position) = !errors.any { ":${position.line}:" in it }
36+
override fun print_single_error(errormessage: String) { /* prints nothing in tests */ }
3637

3738
override fun report() {
3839
infos.forEach { println("UNITTEST COMPILATION REPORT: INFO: $it") }

docs/source/todo.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
TODO
22
====
33

4+
- can goto array[idx] be optimized (array as @nosplit) ?
5+
46
...
57

68

examples/test.p8

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,59 +6,6 @@
66
main {
77

88
sub start() {
9-
uword buffer = memory("buffer", 100, 0)
10-
uword buffer2 = memory("buffer2", 100, 0)
11-
sys.memset(buffer, 100, 0)
12-
sys.memset(buffer2, 100, 0)
13-
str contents = petscii:"<- this is the contents of the file ->"
9+
a=33
1410

15-
txt.print("string size=")
16-
txt.print_uw(len(contents))
17-
txt.nl()
18-
txt.print(contents)
19-
txt.nl()
20-
txt.print_ubhex(contents[3],true)
21-
txt.spc()
22-
txt.print_ubhex(contents[4],true)
23-
txt.spc()
24-
txt.print_ubhex(contents[5],true)
25-
txt.nl()
26-
txt.nl()
27-
28-
diskio.save("@:testfile", contents, len(contents))
29-
uword end_address = diskio.load_raw("testfile", buffer)
30-
uword size = end_address - buffer
31-
txt.print("file size=")
32-
txt.print_uw(size)
33-
txt.nl()
34-
txt.print_uwhex(peekw(buffer), true)
35-
txt.spc()
36-
txt.print(buffer+2)
37-
txt.nl()
38-
txt.print_ubhex(buffer[2+3],true)
39-
txt.spc()
40-
txt.print_ubhex(buffer[2+4],true)
41-
txt.spc()
42-
txt.print_ubhex(buffer[2+5],true)
43-
txt.nl()
44-
txt.nl()
45-
46-
diskio.f_open("testfile")
47-
size = diskio.f_read_all(buffer2)
48-
diskio.f_close()
49-
txt.print("file size=")
50-
txt.print_uw(size)
51-
txt.nl()
52-
txt.print_uwhex(peekw(buffer2), true)
53-
txt.spc()
54-
txt.print(buffer2+2)
55-
txt.nl()
56-
txt.print_ubhex(buffer2[2+3],true)
57-
txt.spc()
58-
txt.print_ubhex(buffer2[2+4],true)
59-
txt.spc()
60-
txt.print_ubhex(buffer2[2+5],true)
61-
txt.nl()
62-
txt.nl()
63-
}
6411
}

0 commit comments

Comments
 (0)