From cb47cc557e19c38f8a6f04ac6f2af2c1a8a1c12a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Pinson?= Date: Mon, 3 Aug 2015 14:47:13 +0200 Subject: [PATCH 15/19] Shellvars: support pipes in commands --- lenses/shellvars.aug | 12 ++++++++---- lenses/tests/test_shellvars.aug | 8 ++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lenses/shellvars.aug b/lenses/shellvars.aug index f9e03ff..f68f5bb 100644 --- a/lenses/shellvars.aug +++ b/lenses/shellvars.aug @@ -116,11 +116,18 @@ module Shellvars = . ( action "&&" "@and" | action "||" "@or" )* in Util.indent . label "@condition" . (cond "[" "]" | cond "[[" "]]") - let command = + (* Entry types *) + let entry_eol_item (item:lens) = [ item . comment_or_eol ] + let entry_item (item:lens) = [ item ] + + (* Command *) + let rec command = let reserved_key = /exit|shift|return|ulimit|unset|export|source|\.|if|for|select|while|until|then|else|fi|done|case|eval|alias/ in let word = /[A-Za-z0-9_.-\/]+/ + in let pipe = del /[ \t]*\|[ \t]*/ " | " in Util.indent . label "@command" . store (word - reserved_key) . [ Sep.space . label "@arg" . sto_to_semicol]? + . (pipe . (entry_eol_item command | entry_item command) )* (************************************************************************ * Group: CONDITIONALS AND LOOPS @@ -179,8 +186,6 @@ module Shellvars = . Util.indent . Util.del_str "}" . eol ] let entry_eol = - let entry_eol_item (item:lens) = - [ item . comment_or_eol ] in entry_eol_item source | entry_eol_item kv | entry_eol_item unset @@ -193,7 +198,6 @@ module Shellvars = | entry_eol_item command let entry_noeol = - let entry_item (item:lens) = [ item ] in entry_item source | entry_item kv | entry_item unset diff --git a/lenses/tests/test_shellvars.aug b/lenses/tests/test_shellvars.aug index f065ce4..e0bf7fb 100644 --- a/lenses/tests/test_shellvars.aug +++ b/lenses/tests/test_shellvars.aug @@ -622,6 +622,14 @@ test Shellvars.lns get "echo foobar 'and this is baz' { "@arg" = "with args" } } +(* Test: Shellvars.lns + Support pipes in commands *) +test Shellvars.lns get "echo \"$STRING\" | grep foo\n" = + { "@command" = "echo" + { "@arg" = "\"$STRING\"" } + { "@command" = "grep" + { "@arg" = "foo" } } } + (* Local Variables: *) (* mode: caml *) (* End: *) -- 2.5.0