chiark / gitweb /
Syntax: Use &\ for escaping; abolish \&
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 9 Dec 2019 14:49:43 +0000 (14:49 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 28 Dec 2019 22:19:08 +0000 (22:19 +0000)
"\&" causes lots of trouble, including difficulty specifying certain
resulting strings.

Previously I proposed a scheme using &$@ but this is only useful to
provide a way to write &s.

The $-doubling regime which will come later wants a way to produce a
single literal $, so introduce that now using the same syntax.
And &\ feels quite natural to me.

Incompatible change.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
README
generate

diff --git a/README b/README
index 67ce6cc..d15a9f4 100644 (file)
--- a/README
+++ b/README
@@ -247,7 +247,9 @@ So pathname syntax is a subset of:
     '&' [ '^' | '~' ] [ lc | '/' | '.' | '=' ]
 
 &&             =>      &&              for convenience in shell runes
-\&             =>      &               general escaping mechanism
+
+&\&            =>      &               general escaping mechanism
+&\$            =>      $
 
 & thing thing... &
 &^ thing thing... &
@@ -285,7 +287,7 @@ So pathname syntax is a subset of:
 
        Notably
                STUFFSTUFF              => STUFFSTUFF
-               \STUFF                  => STUFF
+               STUFF\STUFF             => STUFF
                STUFF:changequote &     => set escape back to &
 
 &TARGETS_things
index ba66f86..dd6df29 100755 (executable)
--- a/generate
+++ b/generate
@@ -151,11 +151,11 @@ sub process_input_mk ($$$$$$$$$) {
            $buffering_output='';
        }
        for (;;) {
-           unless (s{^(.*?)(\\)?(?=$esc)}{}) { o $_; last; }
+           unless (s{^(.*?)$esc}{}) { o $_; last; }
            o $1;
-           if ($2) { s#^$esc##; o $$esclitr; next; }
-           s{^$esc}{} or die "$_ ?";
-           if (s{^$esc}{}) { o "$$esclitr$$esclitr" }
+           if (s{^\\$esc}{}) { o "$$esclitr" }
+           elsif (s{^\\\$}{}) { o '$' }
+           elsif (s{^$esc}{}) { o "$$esclitr$$esclitr" }
            elsif (s{^TARGETS(?:_([0-9a-zA-Z_]+))?(?=\W)}{}) {
                my $t = $1 // 'all';
                o target_varname($var_prefix, $t);