summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMathias Stearn <redbeard0531@gmail.com>2017-12-18 11:49:49 -0500
committerAndreas Rumpf <rumpf_a@web.de>2017-12-18 17:49:49 +0100
commit07fe1aa655dc75eec1a4cf4c697615b5642e8a7c (patch)
treebc8412d9a9b500c340e52caf8efe35128679f701
parent2775cda6e1eaa9e64ccf1f5cd48e2447e059f2b9 (diff)
downloadNim-07fe1aa655dc75eec1a4cf4c697615b5642e8a7c.tar.gz
Use escape sequences rather than hex in string/char literals (#6941)
This should makes documentation easier to read for people who haven't
committed the ascii table to memory.
-rw-r--r--compiler/renderer.nim13
1 files changed, 11 insertions, 2 deletions
diff --git a/compiler/renderer.nim b/compiler/renderer.nim
index 2092fc67c..267ce7de7 100644
--- a/compiler/renderer.nim
+++ b/compiler/renderer.nim
@@ -175,8 +175,17 @@ proc put(g: var TSrcGen, kind: TTokType, s: string) =
 
 proc toNimChar(c: char): string =
   case c
-  of '\0': result = "\\0"
-  of '\x01'..'\x1F', '\x80'..'\xFF': result = "\\x" & strutils.toHex(ord(c), 2)
+  of '\0': result = "\\x00" # not "\\0" to avoid ambiguous cases like "\\012".
+  of '\a': result = "\\a" # \x07
+  of '\b': result = "\\b" # \x08
+  of '\t': result = "\\t" # \x09
+  of '\L': result = "\\L" # \x0A
+  of '\v': result = "\\v" # \x0B
+  of '\f': result = "\\f" # \x0C
+  of '\c': result = "\\c" # \x0D
+  of '\e': result = "\\e" # \x1B
+  of '\x01'..'\x06', '\x0E'..'\x1A', '\x1C'..'\x1F', '\x80'..'\xFF':
+    result = "\\x" & strutils.toHex(ord(c), 2)
   of '\'', '\"', '\\': result = '\\' & c
   else: result = c & ""