From 3c55c13c294b031d2210331c3d6c3b12b3640618 Mon Sep 17 00:00:00 2001 From: Kaarle Ritvanen Date: Thu, 4 Dec 2014 14:31:26 +0200 Subject: [PATCH 01/10] 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 073f69b..60091a9 100644 --- a/lenses/shellvars.aug +++ b/lenses/shellvars.aug @@ -31,7 +31,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 *) @@ -42,7 +42,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 @@ -57,7 +57,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 ] * @@ -67,7 +67,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 42fc2bd..e4fd79f 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" -- 1.8.3.1