about summary refs log tree commit diff stats
path: root/089scenario_filesystem.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-08-20 19:29:45 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-08-20 19:44:07 -0700
commit3369875ccd0e42a8639509a400d2d9cb1356d79a (patch)
tree20272a7d874d1d35f94aebe0c847a91e819dd9c4 /089scenario_filesystem.cc
parent18261f194d34d6d8aa2f359052796c4f6d373c1b (diff)
downloadmu-3369875ccd0e42a8639509a400d2d9cb1356d79a.tar.gz
3233 - change how Mu escapes strings
Thanks Sam Putman for helping think through this idea.

When you encounter a backslash, strip it out and pass through any
following run of backslashes. If we 'escaped' a single following
character like C, then the character '\' would be the same as:

  '\\' escaped once
  '\\\\' escaped twice
  '\\\\\\\\' escaped thrice (8 backslashes)

..and so on, the number of backslashes doubling each time. Instead, our
approach is to make the character '\' the same as:

  '\\' escaped once
  '\\\' escaped twice
  '\\\\' escaped thrice

..and so on, the number of backslashes merely increasing by one each
time.

This approach only works as long as backslashes aren't also overloaded
to create special characters. So Mu doesn't follow C's approach of
overloading backslashes both to escape quote characters and also as a
notation for unprintable characters like '\n'.
Diffstat (limited to '089scenario_filesystem.cc')
-rw-r--r--089scenario_filesystem.cc8
1 files changed, 2 insertions, 6 deletions
diff --git a/089scenario_filesystem.cc b/089scenario_filesystem.cc
index 120d30b7..8acdac0b 100644
--- a/089scenario_filesystem.cc
+++ b/089scenario_filesystem.cc
@@ -54,13 +54,9 @@ scenario assume-filesystem [
   local-scope
   assume-filesystem [
     # file 'a' containing a '|'
-    # ugly as hell that this requires 8 (!) backslashes for 3 '[' block escapes
-    # todo: use Sam Putman's idea to change the delimitors for the '[' blocks
-    # to:
-    #   [''[ ... ['[ ... [ ... ] ... ]'] ... ]'']
-    # That way we'd need just a single backslash -- to escape the |...| environment.
+    # need to escape '\' once for each block
     [a] <- [
-      |x\\\\\\\\|yz|
+      |x\\\\|yz|
     ]
   ]
   data:address:array:file-mapping <- get *filesystem:address:filesystem, data:offset