[augeas-devel] Matching key/value statement

Mol, Xavier (SCC) xavier.mol at kit.edu
Mon Nov 2 09:05:38 UTC 2015


Hi Yclept.



> That is ambiguous concatenation - I removed "(store Rx.word)?" for clarity.

Well, like I said, it was untested. Though this expression does pass the tests imposed by augparse:



let match = [ Util.del_opt_ws "" . key Rx.word . Sep.space_equal . (store Rx.word)? . Util.comment_noindent? ]



Yet I feel like you actually wanted to point out something different with your mail from the start and I cannot comment on that (I'm 
merely a subscriber to this list and not an Augeas developer).



Best regards,

Xavier.



From: Yclept Nemo [mailto:orbisvicis at gmail.com]
Sent: Saturday, October 31, 2015 6:14 PM
To: Mol, Xavier (SCC)
Cc: augeas-devel
Subject: Re: [augeas-devel] Matching key/value statement



On Fri, Oct 30, 2015 at 4:13 AM, Mol, Xavier (SCC) <xavier.mol at kit.edu> wrote:
> let match = [ Util.del_opt_ws . key  Rx.word . Sep.space_equal . (store Rx.word)? . Util.comment_or_eol ]
>
> I haven't tested this, since you did not give a real word example either, so try it for yourself.

Hi,

    let match = [ Util.del_opt_ws "" . key  Rx.word . Sep.space_equal . Util.comment_or_eol ]

That is ambiguous concatenation - I removed "(store Rx.word)?" for clarity.

In the put direction augeas differentiates lenses using child nodes, and nodes using key/value properties. This isn't documented and 
caused me lots of grief. For example
    lenses, ambiguous:      [ (del "a" "a") | (del "b" "b") ]
    lenses, unambiguous:    [ (del "a" "a") | (del "b" "b" . [ label "bleh" ]) ]
    nodes, ambiguous:       [ label "a" . store /a/ ] | [ label "a" . store /a/ . del / / " " ]
    nodes, unambiguous:     [ label "a" . store /a/ ] | ([ label "a" . store /a/ . del / / " " ] . [ label "bleh" ])
    nodes, unambiguous:     [ label "a" . store /a/ ] | [ label "a" . del / / " " ]
This isn't some theoretical limitation, but a shortcoming of augeas.

In the above examples, creating null placeholder nodes renders lenses unusable in the put direction [1], but unnecessary for this 
particular problem. The solution - move the node ambiguities to the lens level, and the lens ambiguities to the node level.

These equivalent statements are both ambiguous:
    Node-level ambiguities:
    let record  = [ key . spaces? . equal . spaces? ]
                | [ key . spaces? . equal . spaces? . comment ]
                | [ key . spaces? . equal . spaces? . value ]
                | [ key . spaces? . equal . spaces? . value . spaces? . comment ]

    Lens-level ambiguities:
    let record  = [ key . spaces? . equal . spaces? . (comment | value | (value . spaces? . comment))?

Merge the node-level ambiguities to create a lens without ambiguities:
    let record  = [ key . spaces? . equal . spaces? . comment? ]
                | [ key . spaces? . equal . spaces? . value . (spaces . comment)? ]

Note the flattened equivalent still has lens-level ambiguities:
    let record  = [ key . spaces? . equal . spaces? . (comment? | value . (spaces? . comment)?)

Anyway, the non-ambiguous version can be made easier to use via a constructor, and the default valueless placeholder changed from "key 
= " to "key =":
    let spaces              = /[ \t]+/ " "
    let spaces_none         = del /[ \t]*/ ""
    let recorder
        (prefix:lens)       =
        let template
            (suffix:lens)   = [ prefix . key . spaces? . equal . suffix ] in
        let suffix_empty    = spaces_none | (spaces? . comment) in
        let suffix_value    = spaces? . value . (spaces? . comment)? in
        let records         = template suffix_empty | template suffix_value in
        records

But the version I want is actually:
    let record  = [ key . spaces? . equal . spaces_none ]
                | [ key . spaces? . equal . spaces? . comment ]
                | [ key . spaces? . equal . spaces? . value . spaces_none ]
                | [ key . spaces? . equal . spaces? . value . spaces? . comment ]

Which simplifies to:
    let record  = [ key . spaces? . equal . (spaces_none | (spaces? . comment)) ]
                | [ key . spaces? . equal . spaces? . value (spaces_none | (spaces? . comment)) ]

And then, nicely without ambiguities, to:
    let record  = [ key . spaces? . equal . (spaces? . value)? . (spaces_none | (spaces? . comment) ]

I'm going to update my ConfigObj lenses soon with functional examples.

Sincerely,

[1] @augeas-devs: placeholder nodes that are ignored in the put direction would be *extremely* useful. Drawing inspiration from perl 
regexes, perhaps using modifier syntax such as "[?>lens]".

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20151102/53bc839f/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 6401 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20151102/53bc839f/attachment.p7s>


More information about the augeas-devel mailing list