public
Description: The Nu programming language.
Homepage: http://programming.nu
Clone URL: git://github.com/timburks/nu.git
More string-printing improvements.

Now strings are printed in their quoted and escaped forms
when they are displayed in nush or the Cocoa console.

This change set also adds proper escaping of backslashes
and double-quotes in displayed strings.
timburks (author)
Sat May 03 20:32:54 -0700 2008
commit  47961068bbd8293c337bf60c4824a226aef53402
tree    b1f7ad3792d67504a089c6c2864e4d16c03029e4
parent  49b1304ba9b5de8ee9418f581eb1aaee363ab4b5
...
1740
1741
1742
1743
1744
1745
 
 
1746
1747
1748
1749
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1750
1751
1752
 
 
1753
1754
1755
1756
1757
 
1758
1759
 
 
 
 
 
1760
1761
1762
...
1778
1779
1780
1781
1782
1783
 
 
1784
1785
1786
...
1740
1741
1742
 
 
 
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
 
 
 
1777
1778
 
1779
1780
1781
1782
1783
1784
1785
1786
...
1802
1803
1804
 
 
 
1805
1806
1807
1808
1809
0
@@ -1740,23 +1740,47 @@ _nucell(_nucell(_nusymbol((const char[]){115,101,116,0}),
0
 _nucell(_nusymbol((const char[]){64,105,110,115,101,114,116,105,111,110,80,111,105,110,116,0}),
0
 _nucell(_nusymbol((const char[]){64,115,116,97,114,116,79,102,73,110,112,117,116,0}),
0
 _nunull()))),
0
-_nucell(_nucell(_nusymbol((const char[]){115,101,108,102,0}),
0
-_nucell(_nusymbol((const char[]){119,114,105,116,101,58,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){115,101,110,100,0}),
0
+_nucell(_nucell(_nusymbol((const char[]){115,101,116,0}),
0
+_nucell(_nusymbol((const char[]){114,101,115,117,108,116,0}),
0
 _nucell(_nucell(_nusymbol((const char[]){64,112,97,114,115,101,114,0}),
0
 _nucell(_nusymbol((const char[]){101,118,97,108,58,0}),
0
 _nucell(_nusymbol((const char[]){99,111,100,101,0}),
0
 _nunull()))),
0
+_nunull()))),
0
+_nucell(_nucell(_nusymbol((const char[]){105,102,0}),
0
+_nucell(_nucell(_nusymbol((const char[]){115,101,110,100,0}),
0
+_nucell(_nusymbol((const char[]){114,101,115,117,108,116,0}),
0
+_nucell(_nusymbol((const char[]){114,101,115,112,111,110,100,115,84,111,83,101,108,101,99,116,111,114,58,0}),
0
+_nucell(_nustring((const char[]){101,115,99,97,112,101,100,83,116,114,105,110,103,82,101,112,114,101,115,101,110,116,97,116,105,111,110,0}),
0
+_nunull())))),
0
+_nucell(_nucell(_nusymbol((const char[]){116,104,101,110,0}),
0
+_nucell(_nucell(_nusymbol((const char[]){115,101,116,0}),
0
+_nucell(_nusymbol((const char[]){115,116,114,105,110,103,84,111,68,105,115,112,108,97,121,0}),
0
+_nucell(_nucell(_nusymbol((const char[]){115,101,110,100,0}),
0
+_nucell(_nusymbol((const char[]){114,101,115,117,108,116,0}),
0
+_nucell(_nusymbol((const char[]){101,115,99,97,112,101,100,83,116,114,105,110,103,82,101,112,114,101,115,101,110,116,97,116,105,111,110,0}),
0
+_nunull()))),
0
+_nunull()))),
0
+_nunull())),
0
+_nucell(_nucell(_nusymbol((const char[]){101,108,115,101,0}),
0
+_nucell(_nucell(_nusymbol((const char[]){115,101,116,0}),
0
+_nucell(_nusymbol((const char[]){115,116,114,105,110,103,84,111,68,105,115,112,108,97,121,0}),
0
+_nucell(_nucell(_nusymbol((const char[]){115,101,110,100,0}),
0
+_nucell(_nusymbol((const char[]){114,101,115,117,108,116,0}),
0
 _nucell(_nusymbol((const char[]){115,116,114,105,110,103,86,97,108,117,101,0}),
0
 _nunull()))),
0
 _nunull()))),
0
+_nunull())),
0
+_nunull())))),
0
 _nucell(_nucell(_nusymbol((const char[]){115,101,108,102,0}),
0
 _nucell(_nusymbol((const char[]){119,114,105,116,101,58,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){78,83,83,116,114,105,110,103,0}),
0
-_nucell(_nusymbol((const char[]){99,97,114,114,105,97,103,101,82,101,116,117,114,110,0}),
0
-_nunull())),
0
+_nucell(_nusymbol((const char[]){115,116,114,105,110,103,84,111,68,105,115,112,108,97,121,0}),
0
 _nunull()))),
0
-_nunull()))))),
0
+_nucell(_nucell(_nusymbol((const char[]){115,101,108,102,0}),
0
+_nucell(_nusymbol((const char[]){119,114,105,116,101,58,0}),
0
+_nucell(_nustring((const char[]){10,0}),
0
+_nunull()))),
0
+_nunull()))))))),
0
 _nucell(_nucell(_nusymbol((const char[]){99,97,116,99,104,0}),
0
 _nucell(_nucell(_nusymbol((const char[]){101,120,99,101,112,116,105,111,110,0}),
0
 _nunull()),
0
@@ -1778,9 +1802,8 @@ _nunull())),
0
 _nunull()))),
0
 _nucell(_nucell(_nusymbol((const char[]){115,101,108,102,0}),
0
 _nucell(_nusymbol((const char[]){119,114,105,116,101,58,0}),
0
-_nucell(_nucell(_nusymbol((const char[]){78,83,83,116,114,105,110,103,0}),
0
-_nucell(_nusymbol((const char[]){99,97,114,114,105,97,103,101,82,101,116,117,114,110,0}),
0
-_nunull())),
0
+_nucell(_nucell(_nustring((const char[]){10,0}),
0
+_nunull()),
0
 _nunull()))),
0
 _nucell(_nucell(_nusymbol((const char[]){64,112,97,114,115,101,114,0}),
0
 _nucell(_nusymbol((const char[]){114,101,115,101,116,0}),
...
337
338
339
340
341
 
 
 
 
 
 
342
343
344
345
346
347
 
348
349
350
...
337
338
339
 
 
340
341
342
343
344
345
346
347
348
349
350
 
351
352
353
354
0
@@ -337,14 +337,18 @@
0
                               (set code (@parser parse: stringToEvaluate))
0
                               (unless (@parser incomplete)
0
                                       (set @insertionPoint @startOfInput)
0
- (self write:(send (@parser eval: code) stringValue))
0
- (self write:(NSString carriageReturn)))
0
+ (set result (@parser eval: code))
0
+ (if (send result respondsToSelector:"escapedStringRepresentation")
0
+ (then (set stringToDisplay (send result escapedStringRepresentation)))
0
+ (else (set stringToDisplay (send result stringValue))))
0
+ (self write:stringToDisplay)
0
+ (self write:"\n"))
0
                               (catch (exception)
0
                                      ;; don't use string interpolation here, it calls the parser again
0
                                      (self write:(exception name))
0
                                      (self write:": ")
0
                                      (self write:(exception reason))
0
- (self write:(NSString carriageReturn))
0
+ (self write:("\n"))
0
                                      (@parser reset)
0
                                      (set @insertionPoint @startOfInput))))
0
                      (else
...
250
251
252
253
254
 
255
256
257
...
263
264
265
 
 
 
 
 
 
266
267
268
...
250
251
252
 
 
253
254
255
256
...
262
263
264
265
266
267
268
269
270
271
272
273
0
@@ -250,8 +250,7 @@ extern id Nu__null;
0
     for (int i = 0; i < length; i++) {
0
         unichar c = [self characterAtIndex:i];
0
         if (c < 32) {
0
- switch (c)
0
- {
0
+ switch (c) {
0
                 case 0x07: [result appendString:@"\\a"]; break;
0
                 case 0x08: [result appendString:@"\\b"]; break;
0
                 case 0x09: [result appendString:@"\\t"]; break;
0
@@ -263,6 +262,12 @@ extern id Nu__null;
0
                     [result appendFormat:@"\\x%02x", c];
0
             }
0
         }
0
+ else if (c == '"') {
0
+ [result appendString:@"\\\""];
0
+ }
0
+ else if (c == '\\') {
0
+ [result appendString:@"\\\\"];
0
+ }
0
         else if (c < 127) {
0
             [result appendCharacter:c];
0
         }
...
913
914
915
916
917
 
 
 
 
 
 
 
 
 
 
918
919
920
...
913
914
915
 
 
916
917
918
919
920
921
922
923
924
925
926
927
928
0
@@ -913,8 +913,16 @@ static int nu_parse_escape_sequences(NSString *string, int i, int imax, NSMutabl
0
                             #endif
0
                         {
0
                             id result = [expression evalWithContext:context];
0
- if (result)
0
- printf("%s\n", [[result stringValue] cStringUsingEncoding:NSUTF8StringEncoding]);
0
+ if (result) {
0
+ id stringToDisplay;
0
+ if ([result respondsToSelector:@selector(escapedStringRepresentation)]) {
0
+ stringToDisplay = [result escapedStringRepresentation];
0
+ }
0
+ else {
0
+ stringToDisplay = [result stringValue];
0
+ }
0
+ printf("%s\n", [stringToDisplay cStringUsingEncoding:NSUTF8StringEncoding]);
0
+ }
0
                         }
0
                         #ifdef DARWIN
0
                         @catch (id exception)

Comments

    No one has commented yet.