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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
From 2d253859c9e8f447449a77187d5dc5a21828b8c7 Mon Sep 17 00:00:00 2001
From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Date: Sat, 12 Dec 2015 17:49:51 +0200
Subject: [PATCH 17/19] Shellvars: allow wrapping command sequences
---
lenses/shellvars.aug | 10 +++++-----
lenses/tests/test_shellvars.aug | 14 +++++++++++++-
2 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/lenses/shellvars.aug b/lenses/shellvars.aug
index f7f4c47..5a48f11 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]#*|\\\\./
let dquot =
let char = /[^"\\]|\\\\./ | Rx.cl
in "\"" . char* . "\"" (* " Emacs, relax *)
@@ -46,7 +46,7 @@ module Shellvars =
let dollar_arithm = /\$\(\([^\)#\n]*\)\)/
let anyquot = (char|dquot|squot|dollar_assign|dollar_arithm)+ | bquot | dbquot
- let sto_to_semicol = store (anyquot . (Rx.space . anyquot)*)
+ let sto_to_semicol = store (anyquot . (Rx.cl_or_space . anyquot)*)
(* Array values of the form '(val1 val2 val3)'. We do not handle empty *)
(* arrays here because of typechecking headaches. Instead, they are *)
@@ -95,7 +95,7 @@ module Shellvars =
let builtin =
Util.indent . label "@builtin"
. store shell_builtin_cmds
- . (Util.del_ws_spc
+ . (Sep.cl_or_space
. [ label "args" . sto_to_semicol ])?
let keyword (kw:string) = Util.indent . Util.del_str kw
@@ -107,7 +107,7 @@ module Shellvars =
. ( Util.del_ws_spc . store Rx.integer )?
let action (operator:string) (lbl:string) (sto:lens) =
- [ del (Rx.opt_space . operator . Rx.opt_space) (" " . operator . " ")
+ [ del (Rx.cl_or_opt_space . operator . Rx.cl_or_opt_space) (" " . operator . " ")
. label ("@".lbl) . sto ]
let action_pipe = action "|" "pipe"
@@ -158,7 +158,7 @@ module Shellvars =
in let and = action_and entry
in let or = action_or entry
in Util.indent . label "@command" . store (word - reserved_key)
- . [ Sep.space . label "@arg" . sto_to_semicol]?
+ . [ Sep.cl_or_space . label "@arg" . sto_to_semicol]?
. ( pipe | and | or )?
let entry_eol = entry_eol_nocommand
diff --git a/lenses/tests/test_shellvars.aug b/lenses/tests/test_shellvars.aug
index 2c810cb..9a1878c 100644
--- a/lenses/tests/test_shellvars.aug
+++ b/lenses/tests/test_shellvars.aug
@@ -168,7 +168,7 @@ unset ONBOOT # We do not want this var
(* Allow wrapping builtin arguments to multiple lines *)
test Shellvars.lns get "ulimit -c \\\nunlimited\nulimit \\\n -x 123\n" =
{ "@builtin" = "ulimit" { "args" = "-c \\\nunlimited" } }
- { "@builtin" = "ulimit" { "args" = "\\\n -x 123" } }
+ { "@builtin" = "ulimit" { "args" = "-x 123" } }
(* Test semicolons *)
test lns get "VAR1=\"this;is;a;test\"\nVAR2=this;\n" =
@@ -668,6 +668,18 @@ test Shellvars.lns get "cat /etc/issue | grep -q \"Debian\" && echo moo || echo
{ "@arg" = "baa" } } } } } } } }
+(* Wrapped command sequences *)
+
+test Shellvars.lns get "foo && \\\nbar baz \\\n|| qux \\\n quux\\\ncorge grault\n" =
+ { "@command" = "foo"
+ { "@and"
+ { "@command" = "bar"
+ { "@arg" = "baz" }
+ { "@or" { "@command" = "qux" { "@arg" = "quux\\\ncorge grault" } } }
+ }
+ }
+ }
+
(* Local Variables: *)
(* mode: caml *)
(* End: *)
--
2.5.0
|