blob: 53f5ddbd55bef4590d3ffee9a83b7e71a2f58bcf (
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 37a817680eb162a21fa6e2eac8feda5973dfb465 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/15] 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.1.0
|