mirror of
https://github.com/irmen/prog8.git
synced 2025-01-11 13:29:45 +00:00
print unmappable character in escaped form in errormessage
This commit is contained in:
parent
f4d83075be
commit
a20efa56eb
@ -1,5 +1,6 @@
|
||||
package prog8.compiler.target.cbm
|
||||
|
||||
import prog8.ast.antlr.escape
|
||||
import java.io.CharConversionException
|
||||
|
||||
object Petscii {
|
||||
@ -1073,7 +1074,7 @@ object Petscii {
|
||||
}
|
||||
else -> {
|
||||
val case = if (lowercase) "lower" else "upper"
|
||||
throw CharConversionException("no ${case}Petscii character for '$chr' (${chr.code})")
|
||||
throw CharConversionException("no ${case}Petscii character for '${escape(chr.toString())}' (${chr.code})")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1110,7 +1111,7 @@ object Petscii {
|
||||
}
|
||||
else -> {
|
||||
val case = if (lowercase) "lower" else "upper"
|
||||
throw CharConversionException("no ${case}Screencode character for '$chr' (${chr.code})")
|
||||
throw CharConversionException("no ${case}Screencode character for '${escape(chr.toString())}' (${chr.code})")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,9 @@ fun escape(str: String): String {
|
||||
'\n' -> "\\n"
|
||||
'\r' -> "\\r"
|
||||
'"' -> "\\\""
|
||||
in '\u8000'..'\u80ff' -> "\\x" + (it.toInt() - 0x8000).toString(16).padStart(2, '0')
|
||||
in '\u8000'..'\u80ff' -> "\\x" + (it.code - 0x8000).toString(16).padStart(2, '0')
|
||||
in '\u0000'..'\u00ff' -> it.toString()
|
||||
else -> "\\u" + it.toInt().toString(16).padStart(4, '0')
|
||||
else -> "\\u" + it.code.toString(16).padStart(4, '0')
|
||||
}
|
||||
}
|
||||
return es.joinToString("")
|
||||
|
@ -1,23 +1,27 @@
|
||||
%import textio
|
||||
%zeropage basicsafe
|
||||
%option no_sysinit
|
||||
%import textio ; txt.*
|
||||
main {
|
||||
sub start() {
|
||||
; ATTENTION: uncomment only one problematic line at a time!
|
||||
|
||||
main {
|
||||
; Normal string literals, i.e. PETSCII encoding
|
||||
; ---------------------------------------------
|
||||
txt.print("\"") ; fine
|
||||
txt.print("\n") ; fine
|
||||
txt.print("\r") ; fine
|
||||
; txt.print("\\") ; yields CharConversionException
|
||||
; txt.print("xyz\\") ; yields prog8.compiler.AssemblyError
|
||||
|
||||
byte[] xs1 = "foo1" ; <<<<<<<<<<<<
|
||||
str xs2 = "foo2" ; <<<<<<<<<<<<
|
||||
sub start() {
|
||||
txt.print(xs1)
|
||||
stringopt()
|
||||
}
|
||||
; @-strings, i.e. translated into
|
||||
; the alternate character encoding (Screencodes/pokes)
|
||||
; ----------------------------------------------------
|
||||
txt.print(@"\"") ; fine
|
||||
txt.print(@"\n") ; yields CharConversionException
|
||||
; txt.print(@"xyz\n") ; yields prog8.compiler.AssemblyError
|
||||
; txt.print(@"\r") ; yields CharConversionException
|
||||
; txt.print(@"xyz\r") ; yields prog8.compiler.AssemblyError
|
||||
; txt.print(@"\\") ; yields CharConversionException
|
||||
; txt.print(@"\\") ; yields prog8.compiler.AssemblyError
|
||||
|
||||
sub stringopt() {
|
||||
str message = "a"
|
||||
|
||||
txt.print(message)
|
||||
txt.nl()
|
||||
message[0] = '@'
|
||||
txt.print(message)
|
||||
txt.nl()
|
||||
}
|
||||
}
|
||||
; there may be more...
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user