Hi David, On Sat, May 8, 2010 at 1:04 AM, David Lutterkort <[email protected]> wrote: > On Thu, 2010-05-06 at 16:35 +0200, Frederik Wagner wrote: >> @David: I included all your earlier suggestions about single values >> w/o quotes and single as well as double quoted lists. > > Yes, I am very happy that you got that to work. > >> There are still two issues, where somebody might help: >> 1. escaped characters are not handled (i.e. in a double quoted list >> backpace escaped whitespaces or double quotes are not possible). This >> does not work by simply including them in the "dqchar" regexp. Why?! > > You need to build a slightly more complicated regexp. For example, > Shellvars.dquot is > > let dquot = /"([^"\\\n]|\\\\.)*"/ > > In English: a double quoted string is a string that starts and ends with > '"', and contains any individual character except for '"' and '\n' or > any two-character sequence '\.' - might take a little to wrap your head > around ;)
yes... hmm, but I'm not sure why in '\\\\.' 4 backslashes are needed for the the ecpade chars (it only works like this, but I don't get it clear). Can you give me a hint? > > For your lens, you'd have to change list to take the full regexp for the > word you're parsing, e.g. /([^"\\\n]|\\\\.)*/ instead of an individual > character; something like (warning: not tested) > > let list(word:regexp) = > let list_value = store word in > ... Done. I included your patch and the extended the escaped char handling. Find attached the two patches on top of my original patch. > >> 2. When adding new values, the 'quote' key (defining the type of >> quotes used) has to be added _before_ any other value. I do not >> understand why the tree has to be sorted? > > The Augeas tree is orderd, i.e. the order in which nodes appear in a > tree matters - that's a consequence of the fact that the tree reflects a > file, which itself is ordered. o.k., so a user has to know some structure of the lens. > It would sometimes be nice, like in this case, to say "don't worry where > the 'quote' node appears, always act as if it were the first > node" (i.e., output the quote character before outputting any 'value' > nodes), but there's no way to do that in Augeas currently. Would be a > nice addition though[1] ;) yes it would, but for the moment I'm happy if I have this running so far :-) Hope the lens is o.k. now?! Thanks for the help and bye, Frederik > > David > > [1] Boomerang (http://www.seas.upenn.edu/~harmony/) has functionality to > sort etc. > > >
From e5f8faf9fc0ae9744fcb8fecb670ef6d5c239b3e Mon Sep 17 00:00:00 2001 From: Frederik Wagner <[email protected]> Date: Tue, 18 May 2010 11:32:34 +0200 Subject: [PATCH 2/3] Shellvars_list: change to fixed label 'value' Shellvars_list tree now uses a fixed label 'value' instead of a seq. --- lenses/shellvars_list.aug | 10 ++-- lenses/tests/test_shellvars_list.aug | 85 +++++++++++++++------------------- 2 files changed, 42 insertions(+), 53 deletions(-) diff --git a/lenses/shellvars_list.aug b/lenses/shellvars_list.aug index 25cbfc2..4a801b3 100644 --- a/lenses/shellvars_list.aug +++ b/lenses/shellvars_list.aug @@ -19,19 +19,19 @@ module Shellvars_list = (* lists values of the form ... val1 val2 val3 ... *) let list(ch:regexp) = let list_value = store ch+ in - indent . counter "values" . - [ seq "values" . list_value ] . - [ del /[ \t\n]+/ " " . seq "values" . list_value ]* . indent + indent . + [ label "value" . list_value ] . + [ del /[ \t\n]+/ " " . label "value" . list_value ]* . indent (* handle single quoted lists *) let squote_arr = [ label "quote" . store /'/ ] . (list sqchar)? . del /'/ "'" (* similarly handle double qouted lists *) - let dquote_arr = [ label "quote" . store /"/ ] . (list dqchar)? . del /"/ "\"" + let dquote_arr = [ label "quote" . store /"/ ] . (list dqchar)? . del /"/ "\"" (* handle unquoted single value *) - let unquot_val = [ label "quote" . store "" ] . counter "vals" . [seq "vals" . store char+]? + let unquot_val = [ label "quote" . store "" ] . [label "value" . store char+]? (* lens for key value pairs *) diff --git a/lenses/tests/test_shellvars_list.aug b/lenses/tests/test_shellvars_list.aug index aa6a2fa..612ab47 100644 --- a/lenses/tests/test_shellvars_list.aug +++ b/lenses/tests/test_shellvars_list.aug @@ -10,50 +10,45 @@ LOADER_TYPE=\"grub\" " test Shellvars_list.lns get list_vals = - { "#comment" = "Some comment" } - { "MODULES_LOADED_ON_BOOT" - { "quote" = "\"" } - { "1" = "ipv6" } - { "2" = "sunrpc" } - } - { } - { "DEFAULT_APPEND" - { "quote" = "\"" } - { "1" = "showopts" } - { "2" = "noresume" } - { "3" = "console=tty0" } - { "4" = "console=ttyS0,115200n8" } - { "5" = "ro" } - } - { } - { "LOADER_TYPE" - { "quote" = "\"" } - { "1" = "grub" } - } - + { "#comment" = "Some comment" } + { "MODULES_LOADED_ON_BOOT" + { "quote" = "\"" } + { "value" = "ipv6" } + { "value" = "sunrpc" } } + { } + { "DEFAULT_APPEND" + { "quote" = "\"" } + { "value" = "showopts" } + { "value" = "noresume" } + { "value" = "console=tty0" } + { "value" = "console=ttyS0,115200n8" } + { "value" = "ro" } } + { } + { "LOADER_TYPE" + { "quote" = "\"" } + { "value" = "grub" } } (* append a value *) test Shellvars_list.lns put "VAR=\"test1\t \ntest2\"\n" after - set "VAR/01" "test3" + set "VAR/value[last()+1]" "test3" = "VAR=\"test1\t \ntest2 test3\"\n" (* in double quoted lists, single quotes are allowed *) test Shellvars_list.lns get "VAR=\"test'1 test2\"\n" = - { "VAR" + { "VAR" { "quote" = "\"" } - { "1" = "test'1" } - { "2" = "test2" } - } + { "value" = "test'1" } + { "value" = "test2" } } (* add new value, delete one and append something *) (* !!! order of adding 'quote' key and values seeems to be relevant!!! *) (* ---> first the quote *) test Shellvars_list.lns put list_vals after set "FAILSAVE_APPEND/quote" "\"" ; - set "FAILSAVE_APPEND/01" "console=ttyS0" ; + set "FAILSAVE_APPEND/value[last()+1]" "console=ttyS0" ; rm "LOADER_TYPE" ; - rm "MODULES_LOADED_ON_BOOT/1" ; - set "DEFAULT_APPEND/01" "teststring" + rm "MODULES_LOADED_ON_BOOT/value[1]" ; + set "DEFAULT_APPEND/value[last()+1]" "teststring" = "# Some comment MODULES_LOADED_ON_BOOT=\"sunrpc\" @@ -65,7 +60,7 @@ FAILSAVE_APPEND=\"console=ttyS0\" (* test of single quotes (leading/trailing whitespaces are kept *) (* leading/trailing) *) test Shellvars_list.lns put "VAR=' \t test1\t \ntest2 '\n" after - set "VAR/01" "test3" + set "VAR/value[last()+1]" "test3" = "VAR=' \t test1\t \ntest2 test3 '\n" (* change quotes (leading/trailing whitespaces are lost *) @@ -75,46 +70,40 @@ FAILSAVE_APPEND=\"console=ttyS0\" (* double quotes are allowed in single quoted lists *) test Shellvars_list.lns get "VAR='test\"1 test2'\n" = - { "VAR" + { "VAR" { "quote" = "'" } - { "1" = "test\"1" } - { "2" = "test2" } - } + { "value" = "test\"1" } + { "value" = "test2" } } (* emtpy list with quotes *) test Shellvars_list.lns get "VAR=''\n" = - { "VAR" - { "quote" = "'" } - } + { "VAR" { "quote" = "'" } } - (* unquoted value *) + (* unquoted value *) test Shellvars_list.lns get "VAR=test\n" = - { "VAR" + { "VAR" { "quote" = "" } - { "1" = "test" } - } + { "value" = "test" } } - (* append to unquoted value *) + (* append to unquoted value *) test Shellvars_list.lns put "VAR=test1\n" after set "VAR/quote" "\""; - set "VAR/01" "test2" + set "VAR/value[last()+1]" "test2" = "VAR=\"test1 test2\"\n" (* empty entry *) test Shellvars_list.lns get "VAR=\n" = - { "VAR" - { "quote" = "" } - } + { "VAR" { "quote" = "" } } (* set value w/o quotes to empty value... *) test Shellvars_list.lns put "VAR=\n" after - set "VAR/01" "test" + set "VAR/value[last()+1]" "test" = "VAR=test\n" (* ... or no value *) test Shellvars_list.lns put "" after set "VAR/quote" ""; - set "VAR/1" "test" + set "VAR/value" "test" = "VAR=test\n" (* Local Variables: *) -- 1.7.0
From 4e2f65566c2e5a03fb1d02fbb1753ab27a78f078 Mon Sep 17 00:00:00 2001 From: Frederik Wagner <[email protected]> Date: Tue, 18 May 2010 13:43:26 +0200 Subject: [PATCH 3/3] Shellvars_list: added handling of escaped chars --- lenses/shellvars_list.aug | 16 ++++++++-------- lenses/tests/test_shellvars_list.aug | 15 ++++++++++----- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lenses/shellvars_list.aug b/lenses/shellvars_list.aug index 4a801b3..78b7f2b 100644 --- a/lenses/shellvars_list.aug +++ b/lenses/shellvars_list.aug @@ -12,26 +12,26 @@ module Shellvars_list = let empty = Util.empty let indent = Util.indent - let sqchar = /[^ '\t\n]/ - let dqchar = /[^ "\t\n]/ - let char = /[^ "'\t\n]/ + let sqword = /[^ '\t\n]+/ + let dqword = /([^ "\\\t\n]|\\\\.)+/ + let uqword = /([^ "'\\\t\n]|\\\\.)+/ (* lists values of the form ... val1 val2 val3 ... *) - let list(ch:regexp) = - let list_value = store ch+ in + let list(word:regexp) = + let list_value = store word in indent . [ label "value" . list_value ] . [ del /[ \t\n]+/ " " . label "value" . list_value ]* . indent (* handle single quoted lists *) - let squote_arr = [ label "quote" . store /'/ ] . (list sqchar)? . del /'/ "'" + let squote_arr = [ label "quote" . store /'/ ] . (list sqword)? . del /'/ "'" (* similarly handle double qouted lists *) - let dquote_arr = [ label "quote" . store /"/ ] . (list dqchar)? . del /"/ "\"" + let dquote_arr = [ label "quote" . store /"/ ] . (list dqword)? . del /"/ "\"" (* handle unquoted single value *) - let unquot_val = [ label "quote" . store "" ] . [label "value" . store char+]? + let unquot_val = [ label "quote" . store "" ] . [label "value" . store uqword+]? (* lens for key value pairs *) diff --git a/lenses/tests/test_shellvars_list.aug b/lenses/tests/test_shellvars_list.aug index 612ab47..f1153af 100644 --- a/lenses/tests/test_shellvars_list.aug +++ b/lenses/tests/test_shellvars_list.aug @@ -33,16 +33,15 @@ LOADER_TYPE=\"grub\" set "VAR/value[last()+1]" "test3" = "VAR=\"test1\t \ntest2 test3\"\n" - (* in double quoted lists, single quotes are allowed *) - test Shellvars_list.lns get "VAR=\"test'1 test2\"\n" = + (* in double quoted lists, single quotes and escaped values are allowed *) + test Shellvars_list.lns get "VAR=\"test'1 test2 a\ \\\"longer\\\"\ test\"\n" = { "VAR" { "quote" = "\"" } { "value" = "test'1" } - { "value" = "test2" } } + { "value" = "test2" } + { "value" = "a\ \\\"longer\\\"\ test" } } (* add new value, delete one and append something *) - (* !!! order of adding 'quote' key and values seeems to be relevant!!! *) - (* ---> first the quote *) test Shellvars_list.lns put list_vals after set "FAILSAVE_APPEND/quote" "\"" ; set "FAILSAVE_APPEND/value[last()+1]" "console=ttyS0" ; @@ -85,6 +84,12 @@ FAILSAVE_APPEND=\"console=ttyS0\" { "quote" = "" } { "value" = "test" } } + (* uquoted value with escaped space etc. *) + test Shellvars_list.lns get "VAR=a\\ \\\"long\\\"\\ test\n" = + { "VAR" + { "quote" = "" } + { "value" = "a\\ \\\"long\\\"\\ test" } } + (* append to unquoted value *) test Shellvars_list.lns put "VAR=test1\n" after set "VAR/quote" "\""; -- 1.7.0
_______________________________________________ augeas-devel mailing list [email protected] https://www.redhat.com/mailman/listinfo/augeas-devel
