[augeas-devel] Having trouble differentiating quoted vs unquoted string

Matthew Palmer matt at anchor.net.au
Thu Aug 13 02:39:52 UTC 2009


On Wed, Aug 12, 2009 at 02:59:35PM -0700, David Lutterkort wrote:
> 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 ]

Yeah, more or less.

> 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.

That's ugly and prone to error, but I could talk my way into doing that if I
absolutely had to.  However, there are other SSH options that can be a
comma-separated list of value, which then need to be quoted (but not
necessarily, if you've only got one value to set that doesn't contain
spaces).  That one we can't trick with leaving the quotes in place...

So, here's my "test" lens for the simple quoted/unquoted line scenario
(though using single quotes as the quoting character, to simplify the
escaping):

let unquoted_line = seq "count" . del /'?/ "" . store /[^' \t\n][^' \t\n]*/ . del /'?/ ""

let quoted_line = seq "count" . Util.del_str "'" . store /[^'\n]* [^'\n]*/ . Util.del_str "'"

let line = (unquoted_line|quoted_line) . Util.eol

let lns = line*

However, augparse tells me that this is overlapping, and that '' (exactly
that -- the single quotes there are augparse's, not mine) matches both. 
I've got an explicit and required space character in the middle there, so
how can that second regexp (in quoted_line) match the empty string?

- Matt




More information about the augeas-devel mailing list