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
|
From a70c92f52136398ffbe6e5fd70effd3984e84a5f Mon Sep 17 00:00:00 2001
From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Date: Thu, 4 Dec 2014 14:31:26 +0200
Subject: [PATCH 03/15] Shellvars: allow partial quoting, mixing multiple
styles
---
lenses/shellvars.aug | 8 ++++----
lenses/tests/test_shellvars.aug | 4 ++++
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/lenses/shellvars.aug b/lenses/shellvars.aug
index b988972..d25e8ca 100644
--- a/lenses/shellvars.aug
+++ b/lenses/shellvars.aug
@@ -34,7 +34,7 @@ module Shellvars =
let xchgs = Build.xchgs
let semicol = del /;?/ ""
- let char = /[^`;() '"\t\n]|\\\\"/
+ let char = /[^`;() '"\t\n\\]|\\\\./
let dquot =
let char = /[^"\\]|\\\\./ | Rx.cl
in "\"" . char* . "\"" (* " Emacs, relax *)
@@ -45,7 +45,7 @@ module Shellvars =
let dollar_assign = /\$\([^\(\)#\n]*\)/
let dollar_arithm = /\$\(\([^\)#\n]*\)\)/
- let anyquot = (dquot|squot)+ | bquot | dbquot | dollar_assign | dollar_arithm
+ let anyquot = (char|dquot|squot|dollar_assign|dollar_arithm)+ | bquot | dbquot
let to_semicol_re = /[^#; \t\n][^#;\n]+[^#; \t\n]|[^#; \t\n]+/
let sto_to_semicol = store to_semicol_re
@@ -60,7 +60,7 @@ module Shellvars =
(* arrays here because of typechecking headaches. Instead, they are *)
(* treated as a simple value *)
let array =
- let array_value = store (char+ | anyquot) in
+ let array_value = store anyquot in
del /\([ \t]*/ "(" . counter "values" .
[ seq "values" . array_value ] .
[ del /[ \t\n]+/ " " . seq "values" . array_value ] *
@@ -70,7 +70,7 @@ module Shellvars =
(* but fairly close. *)
let simple_value =
let empty_array = /\([ \t]*\)/ in
- store (char* | anyquot | empty_array)
+ store (anyquot | empty_array)?
let export = [ key "export" . Util.del_ws_spc ]
let kv = Util.indent . export? . key key_re
diff --git a/lenses/tests/test_shellvars.aug b/lenses/tests/test_shellvars.aug
index a2d4f28..864cb6c 100644
--- a/lenses/tests/test_shellvars.aug
+++ b/lenses/tests/test_shellvars.aug
@@ -399,6 +399,10 @@ esac\n" =
test Shellvars.lns get "FOO=``bar``\n" =
{ "FOO" = "``bar``" }
+ (* Partial quoting is allowed *)
+ test Shellvars.lns get "FOO=\"$bar\"/'baz'/$(quux)$((1 + 2))\n" =
+ { "FOO" = "\"$bar\"/'baz'/$(quux)$((1 + 2))" }
+
(* unset can be used on wildcard variables *)
test Shellvars.lns get "unset ${!LC_*}\n" =
{ "@unset"
--
2.1.0
|