[augeas-devel] Named key
David Lutterkort
lutter at redhat.com
Wed Apr 21 15:57:48 UTC 2010
On Wed, 2010-04-21 at 02:54 -0400, Francis Giraldeau wrote:
> While developing the httpd lens, there are some xml-like elements, where
> open and close tags must be the same. We can do this now with lens and a
> string argument, like this small html example (I removed "<>" chars and
> element content to simplify the example) :
>
> let elem (name:string) = [ key name . del ws " " . del name name ]
> let doc = elem "body" | elem "html" | elem "img" ...
>
> The drawback of this method is that we have to list every element name
> that may occur in a document. Such a lens will not be able to handle
> arbitrary xml document.
>
> We need to get a reference on a matched key value. To start discussion
> on that, let's say we add a new keyword "as" to reference a value as a
> string type. Then, we could use this name elsewhere in the same subtree.
Implementing that kind of constraint on arbitrary lenses will be quite a
bit of work (though I wouldn't turn down patches for that)
I was thinking to address the matching tag issue with a specialized
builtin lens square: regexp -> lens -> lens, with the behavior that
square re l := key re . l . del k k
where 'k' is whatever the key matched. For nested XML tags, that would
mean we'd do something like (omitting whitespace headaches and
atributes)
let xml (body:lens) =
let b = del ">" ">" . body . del "</" "</" in
del "<" "<" . square /[a-z]+/ b . del ">" ">"
David
More information about the augeas-devel
mailing list