From 37a817680eb162a21fa6e2eac8feda5973dfb465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= 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