blob: cc75fd30981516522c1672854aea9d52475f8d42 (
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
|
From be89b820d5eecce26fbb5a779ce743cedef5c1c9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= <raphael.pinson@camptocamp.com>
Date: Mon, 13 Jul 2015 10:03:21 +0200
Subject: [PATCH 01/19] Shellvars: accept [] and [[]] builtins
Fix GH #188
---
lenses/shellvars.aug | 9 +++++++++
lenses/tests/test_shellvars.aug | 5 +++++
2 files changed, 14 insertions(+)
diff --git a/lenses/shellvars.aug b/lenses/shellvars.aug
index 25bb82b..b988972 100644
--- a/lenses/shellvars.aug
+++ b/lenses/shellvars.aug
@@ -105,6 +105,13 @@ module Shellvars =
. Util.del_str "return"
. ( Util.del_ws_spc . store Rx.integer )?
+ let condition =
+ let sto_cond = store /[^[#; \t\n][^#;\n]+[^]#; \t\n]|[^[]#; \t\n]+/
+ in let cond (start:string) (end:string) = [ label "type" . store start ]
+ . Util.del_ws_spc . sto_cond
+ . Util.del_ws_spc . Util.del_str end
+ in Util.indent . label "@condition" . (cond "[" "]" | cond "[[" "]]")
+
(************************************************************************
* Group: CONDITIONALS AND LOOPS
@@ -169,6 +176,7 @@ module Shellvars =
| entry_eol_item bare_export
| entry_eol_item builtin
| entry_eol_item return
+ | entry_eol_item condition
let entry_noeol =
let entry_item (item:lens) = [ item ] in
@@ -178,6 +186,7 @@ module Shellvars =
| entry_item bare_export
| entry_item builtin
| entry_item return
+ | entry_item condition
let rec rec_entry =
let entry = comment | entry_eol | rec_entry in
diff --git a/lenses/tests/test_shellvars.aug b/lenses/tests/test_shellvars.aug
index 7a89f11..778a8d2 100644
--- a/lenses/tests/test_shellvars.aug
+++ b/lenses/tests/test_shellvars.aug
@@ -536,6 +536,11 @@ fi\n" =
test lns get "var[alpha_beta,gamma]=something\n" =
{ "var[alpha_beta,gamma]" = "something" }
+ (* GH #188: support more conditions *)
+ test Shellvars.lns get "[ -f $FILENAME ]\n" =
+ { "@condition" = "-f $FILENAME"
+ { "type" = "[" } }
+
(* Local Variables: *)
(* mode: caml *)
(* End: *)
--
2.5.0
|