aboutsummaryrefslogtreecommitdiffstats
path: root/main/augeas/0011-Shellvars-allow-and-constructs-after-condition.patch
blob: cb067beea01f286be55c70096f0d418e1bd7ba20 (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
From 7bad1f085369de5544f8b06e7e0704d7030c3506 Mon Sep 17 00:00:00 2001
From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Date: Mon, 13 Jul 2015 14:51:37 +0300
Subject: [PATCH 11/15] Shellvars: allow && and || constructs after condition

---
 lenses/shellvars.aug            | 8 ++++++--
 lenses/tests/test_shellvars.aug | 8 ++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/lenses/shellvars.aug b/lenses/shellvars.aug
index bb0e875..3fce699 100644
--- a/lenses/shellvars.aug
+++ b/lenses/shellvars.aug
@@ -34,7 +34,7 @@ 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 *)
@@ -98,9 +98,13 @@ module Shellvars =
     . ( Util.del_ws_spc . store Rx.integer )?
 
   let condition =
-       let cond (start:string) (end:string) = [ label "type" . store start ]
+       let action (operator:string) (lbl:string) =
+         [ Sep.opt_space . Util.del_str operator . Sep.opt_space
+         . label lbl . sto_to_semicol ]
+    in let cond (start:string) (end:string) = [ label "type" . store start ]
                                             . Util.del_ws_spc . sto_to_semicol
                                             . Util.del_ws_spc . Util.del_str end
+                                            . ( action "&&" "@and" | action "||" "@or" )*
     in Util.indent . label "@condition" . (cond "[" "]" | cond "[[" "]]")
 
 
diff --git a/lenses/tests/test_shellvars.aug b/lenses/tests/test_shellvars.aug
index a397431..ae432fa 100644
--- a/lenses/tests/test_shellvars.aug
+++ b/lenses/tests/test_shellvars.aug
@@ -596,6 +596,14 @@ esac\n" =
       }
     }
 
+  (* Allow && and || constructs after condition *)
+  test Shellvars.lns get "[ -f $FILENAME ] && do this || or that\n" =
+  { "@condition" = "-f $FILENAME"
+    { "type" = "[" }
+    { "@and" = "do this" }
+    { "@or" = "or that" }
+  }
+
 (* Local Variables: *)
 (* mode: caml       *)
 (* End:             *)
-- 
2.1.0