mirror of
https://github.com/irmen/prog8.git
synced 2025-01-12 04:30:03 +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
|
package prog8.compiler.target.cbm
|
||||||
|
|
||||||
|
import prog8.ast.antlr.escape
|
||||||
import java.io.CharConversionException
|
import java.io.CharConversionException
|
||||||
|
|
||||||
object Petscii {
|
object Petscii {
|
||||||
@ -1073,7 +1074,7 @@ object Petscii {
|
|||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
val case = if (lowercase) "lower" else "upper"
|
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 -> {
|
else -> {
|
||||||
val case = if (lowercase) "lower" else "upper"
|
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"
|
'\n' -> "\\n"
|
||||||
'\r' -> "\\r"
|
'\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()
|
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("")
|
return es.joinToString("")
|
||||||
|
@ -1,23 +1,27 @@
|
|||||||
%import textio
|
%import textio ; txt.*
|
||||||
%zeropage basicsafe
|
main {
|
||||||
%option no_sysinit
|
|
||||||
|
|
||||||
main {
|
|
||||||
|
|
||||||
byte[] xs1 = "foo1" ; <<<<<<<<<<<<
|
|
||||||
str xs2 = "foo2" ; <<<<<<<<<<<<
|
|
||||||
sub start() {
|
sub start() {
|
||||||
txt.print(xs1)
|
; ATTENTION: uncomment only one problematic line at a time!
|
||||||
stringopt()
|
|
||||||
}
|
|
||||||
|
|
||||||
sub stringopt() {
|
; Normal string literals, i.e. PETSCII encoding
|
||||||
str message = "a"
|
; ---------------------------------------------
|
||||||
|
txt.print("\"") ; fine
|
||||||
|
txt.print("\n") ; fine
|
||||||
|
txt.print("\r") ; fine
|
||||||
|
; txt.print("\\") ; yields CharConversionException
|
||||||
|
; txt.print("xyz\\") ; yields prog8.compiler.AssemblyError
|
||||||
|
|
||||||
txt.print(message)
|
; @-strings, i.e. translated into
|
||||||
txt.nl()
|
; the alternate character encoding (Screencodes/pokes)
|
||||||
message[0] = '@'
|
; ----------------------------------------------------
|
||||||
txt.print(message)
|
txt.print(@"\"") ; fine
|
||||||
txt.nl()
|
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
|
||||||
|
|
||||||
|
; there may be more...
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user