[augeas-devel] Having trouble differentiating quoted vs unquoted string
David Lutterkort
lutter at redhat.com
Wed Aug 12 21:59:35 UTC 2009
On Wed, 2009-08-12 at 17:46 +1000, Matthew Palmer wrote:
> I've reduced my problem to something quite trivial; writing a lens that will
> successfully parse/write the following should solve my problem:
>
> "quoted line"
> "unecessarily_quoted_line"
> unquotedline
>
> Unfortunately, whatever I try I get an "overlapping lens in tree union.put"
> error, which I understand the meaning of -- when trying to write a value in
> the tree back to the file, augeas can't decide whether to use the quoted or
> unquoted version.
What gets you into trouble is that you try to strip the quotes in your
lens, I assume you have something like
let val = store word_no_spaces
| del /"/ "\"" . store word_with_spaces . del /"/ "\""
let cmd = [ key "command" . del /=/ "=" . val ]
Augeas makes decisions of which lens to use in the tree -> file
directions solely based on the labels of tree nodes[1], and is therefore
blind to the alternation in val (and therefore complains that the two
sublenses of val overlap).
One way to work around this is to _not_ strip the quotes, and use
something like the attached test module.
David
[1] That is a shortcoming that I would really like to address; it would
require a few days of hacking, which I unfortunately don't have right
now. But if anybody's interested, I am more than happy to explain what
needs to be done.
-------------- next part --------------
module T =
let word_no_spaces = /[A-Za-z0-9]+/
let word_spaces = /"[A-Za-z0-9 ]+"/
let value = store (word_no_spaces|word_spaces)
let lns = [ label "value" . value ]?
test lns get "unquoted" = { "value" = "unquoted" }
test lns get "\"with spaces\"" = { "value" = "\"with spaces\"" }
test lns get "invalid with spaces" = *
test lns get "\"missing quote" = *
test lns put "" after set "/value" "\"with spaces\"" = "\"with spaces\""
test lns put "" after set "/value" "unquoted" = "unquoted"
test lns put "" after set "/value" "with spaces" = *
More information about the augeas-devel
mailing list