aboutsummaryrefslogtreecommitdiffstats
path: root/main/augeas/0011-Shellvars-pattern-nodes-in-case-entries.patch
blob: dc11176d87f617a5797155b83dc95296e21b5e0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
From 60a542a54819deee9a869815df40f99a4391a8fa Mon Sep 17 00:00:00 2001
From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Date: Mon, 13 Jul 2015 14:43:09 +0300
Subject: [PATCH 11/19] Shellvars: pattern nodes in case entries

Breaking change: case entry values are now in a @pattern subnode.
---
 lenses/shellvars.aug            | 10 +++++----
 lenses/tests/test_shellvars.aug | 48 +++++++++++++++++++++++++++--------------
 2 files changed, 38 insertions(+), 20 deletions(-)

diff --git a/lenses/shellvars.aug b/lenses/shellvars.aug
index f681fcd..ed9cc9c 100644
--- a/lenses/shellvars.aug
+++ b/lenses/shellvars.aug
@@ -34,12 +34,12 @@ module Shellvars =
   let xchgs   = Build.xchgs
   let semicol = del /;?/ ""
 
-  let char  = /[^`;()'"\n\\# \t]#*|\\\\(.|\n)/
+  let char  = /[^`;()'"|\n\\# \t]#*|\\\\(.|\n)/
   let dquot =
        let char = /[^"\\]|\\\\./ | Rx.cl
     in "\"" . char* . "\""                    (* " Emacs, relax *)
   let squot = /'[^']*'/
-  let bquot = /`[^`\n]*`/
+  let bquot = /`[^`\n]+`/
   (* dbquot don't take spaces or semi-colons *)
   let dbquot = /``[^` \t\n;]+``/
   let dollar_assign = /\$\([^\(\)#\n]*\)/
@@ -148,8 +148,10 @@ module Shellvars =
     generic_cond "select" "@select" "do" entry+ "done"
 
   let case (entry:lens) (entry_noeol:lens) =
-    let case_entry = [ label "@case_entry"
-                       . Util.indent . sto_to_semicol
+       let pattern = [ label "@pattern" . sto_to_semicol . Sep.opt_space ]
+    in let case_entry = [ label "@case_entry"
+                       . Util.indent . pattern
+                       . (Util.del_str "|" . Sep.opt_space . pattern)*
                        . Util.del_str ")" . eol
                        . entry* . entry_noeol?
                        . Util.indent . Util.del_str ";;" . eol ] in
diff --git a/lenses/tests/test_shellvars.aug b/lenses/tests/test_shellvars.aug
index 26aec25..d07918d 100644
--- a/lenses/tests/test_shellvars.aug
+++ b/lenses/tests/test_shellvars.aug
@@ -261,11 +261,14 @@ done\n" =
     ;;
 esac\n" =
   { "@case" = "$f"
-    { "@case_entry" = "/tmp/file1"
+    { "@case_entry"
+      { "@pattern" = "/tmp/file1" }
       { ".source" = "/tmp/file1" } }
-    { "@case_entry" = "/tmp/file2"
+    { "@case_entry"
+      { "@pattern" = "/tmp/file2" }
       { ".source" = "/tmp/file2" } }
-    { "@case_entry" = "*"
+    { "@case_entry"
+      { "@pattern" = "*" }
       { "@unset"
         { "1" = "f" } } } }
 
@@ -308,7 +311,8 @@ esac\n" =
 
   esac\n" =
   { "@case" = "$f"
-    { "@case_entry" = "a"
+    { "@case_entry"
+      { "@pattern" = "a" }
       { "B" = "C" } }
     }
 
@@ -325,9 +329,11 @@ esac\n" =
     ;;
   esac\n" =
   { "@case" = "$f"
-    { "@case_entry" = "a"
+    { "@case_entry"
+      { "@pattern" = "a" }
       { "B" = "C" } }
-    { "@case_entry" = "b"
+    { "@case_entry"
+      { "@pattern" = "b" }
       { "A" = "D" } } }
 
 
@@ -348,11 +354,13 @@ unset f
 esac\n" =
   { "@case" = "${INTERFACE}"
     { "#comment" = "comment before" }
-    { "@case_entry" = "eth0"
+    { "@case_entry"
+      { "@pattern" = "eth0" }
       { "#comment" = "comment in" }
       { "OPTIONS" = "()" } }
     { "#comment" = "comment before 2" }
-    { "@case_entry" = "*"
+    { "@case_entry"
+      { "@pattern" = "*" }
       { "#comment" = "comment in 2" }
       { "@unset"
         { "1" = "f" } } }
@@ -364,7 +372,7 @@ esac\n" =
   ;;
   esac\n" =
   { "@case" = "$a"
-    { "@case_entry" = "*" } }
+    { "@case_entry" { "@pattern" = "*" } } }
 
   (* case variables can be surrounded by double quotes *)
   test Shellvars.lns get "case \"${options}\" in
@@ -373,7 +381,8 @@ esac\n" =
   ;;
 esac\n" =
   { "@case" = "\"${options}\""
-    { "@case_entry" = "*debug*"
+    { "@case_entry"
+      { "@pattern" = "*debug*" }
       { "@builtin" = "shift" } } }
 
   (* Double quoted values can have newlines *)
@@ -473,9 +482,11 @@ test2\"\n" =
         1) TestVar=\"test1\" ;;
 esac\n" =
     { "@case" = "$ARG"
-      { "@case_entry" = "0"
+      { "@case_entry"
+        { "@pattern" = "0" }
         { "TestVar" = "\"test0\"" } }
-      { "@case_entry" = "1"
+      { "@case_entry"
+        { "@pattern" = "1" }
         { "TestVar" = "\"test1\"" } } }
 
   (* case: support ;; on the same line with multiple commands *)
@@ -486,11 +497,13 @@ esac\n" =
 	   Bar=3; Baz=4;;
 esac\n" =
     { "@case" = "$ARG"
-      { "@case_entry" = "0"
+      { "@case_entry"
+        { "@pattern" = "0" }
         { "Foo" = "0" }
         { "Bar" = "1" }
       }
-      { "@case_entry" = "1"
+      { "@case_entry"
+        { "@pattern" = "1" }
         { "Foo" = "2" }
         { "Bar" = "3" }
         { "Baz" = "4" }
@@ -572,10 +585,13 @@ fi\n" =
            ;;
 esac\n" =
     { "@case" = "$ARG"
-      { "@case_entry" = "\"foo bar\""
+      { "@case_entry"
+        { "@pattern" = "\"foo bar\"" }
         { "Foo" = "0" }
       }
-      { "@case_entry" = "baz | quux"
+      { "@case_entry"
+        { "@pattern" = "baz" }
+        { "@pattern" = "quux" }
         { "Foo" = "1" }
       }
     }
-- 
2.5.0