1 (* Demonstrate how quotes can be stripped from values. *)
2 (* Values can be enclosed in single or double quotes, if they *)
3 (* contain spaces they _have_ to be enclosed in quotes. Since *)
4 (* everything's regular, we can't actually match a closing quote *)
5 (* to the opening quote, so "hello' will be accepted, too. *)
7 module Pass_strip_quotes =
9 let nuttin = del /(""|'')?/ "''"
10 let bare = del /["']?/ "" . store /[a-zA-Z0-9]+/ . del /["']?/ ""
11 let quoted = del /["']/ "'" . store /.*[ \t].*/ . del /["']/ "'"
13 let lns = [ label "foo" . bare ]
14 | [ label "foo" . quoted ]
15 | [ label "foo" . nuttin ]
17 test lns get "'hello'" = { "foo" = "hello" }
18 test lns get "'hello world'" = { "foo" = "hello world" }
20 let hw = "'hello world'"
21 let set_hw = set "/foo" "hello world"
22 test lns put "hello" after set_hw = hw
23 test lns put "'hello world'" after set "/foo" "hello" = "'hello'"
25 test lns put "" after set_hw = hw
26 test lns put "\"\"" after set_hw = hw