[augeas-devel] [Interfaces] Draft lense

Raphaël Pinson raphink at gmail.com
Wed Aug 20 21:20:27 UTC 2008


On Wed, Aug 20, 2008 at 8:58 PM, Free Ekanayaka <free at 64studio.com> wrote:

>
>
>  RP> This is a problem with put. When augeas meets a "comment" node, it
> doesn't
>  RP> know if it's an option named "comment" or a comment, hence the
> conflict. To
>  RP> fix this and make it clearer, we began to rename the comment nodes
> into
>  RP> "#comment" some time ago. My local repository is like this, but it's
> not
>  RP> committed into the main repository yet so I forgot to tell you about
> it. You
>  RP> can change 'label "comment"' in your util.aug and it should fix the
> issue.
>
> Thanks a lot, that fixed the problem indeed. Any chance to get it
> committed in the official repo?
>

It will come soon. David is pretty busy lately, so I'm not going to send a
lot of patches right now, I'll wait for him to be back online so he's not
overwhelmed with patches. Given the direction taken with inifile.aug, I
think #comment should be default in all lenses by next releases.



> The main pending issue now are comments at the end of line, like:
>
> auto lo eth0 # Take me to the net
>
> I've tried to replace eol with (eol|comment):
>
> let auto    = [ array /(allow-)?auto/ "auto" . eol . (comment|empty)* ]
>

Hmm this shouldn't be necessary. "auto" lines are one-liners, contrarily to
iface for example. In iface entries, you have to embed comments because they
can't be seen as standalone when they are in the middle of an iface entry,
but it's not the case for "auto".



> with
>
> let auto    = [ array /(allow-)?auto/ "auto" . (eol|comment). .
> (comment|empty)* ]
>


I would simply write

let auto = [ array /(allow-)?auto/ "auto" . (eol|comment) ]



>
> But I get this error:
>
> lenses/interfaces.aug:26.3-.83:Failed to compile auto
> lenses/interfaces.aug:26.19-.62:exception: ambiguous concatenation
>      'auto\\\nA#A\n' can be split into
>      'auto\\\nA|=|#A\n'
>
>     and
>      'auto\\\nA#A|=|\n'
>


The problem here is actually a bit more complicated than in bbhosts.aug. The
problem is that you have single line entries and multi lines entries. While
single line entries can be followed by comments or empty lines, multi lines
entries cannot, because they include comments and empty lines.

let s_entry = (blah|blih) . (comment|empty)*
let m_entry = (bloh|bluh)

let lns = (comment|empty)* .
             (m_entry | s_entry)*

The idea is this:
   - the file can begin with any amount of comments and empty lines.
   - the entries (what we really care about) can be single line entries
(s_entry) or multi lines entries (m_entry).
   - single line entries can be followed by any amount of comments and empty
lines.
   - multi lines entries cannot be followed by comments and empty lines
immediately. There has to be a s_entry to reintroduce "standalone" comments
and empty lines because m_entry entries include them.

With this pattern, you do not need to deal with comments and empty lines
within s_entry entries, only within m_entry.
When I cannot fix a bit of code in a lens, I try to rethink the whole
structure of the lens, going back to what the lens actually is.

Let's try and see in the code...


============ interfaces.aug ===============
>
> (* Intefraces module for Augeas               *)
> (* Author: Free Ekanayaka <free at 64studio.com> *)
>
> module Interfaces =
>   autoload xfm
>
>   (* Define useful primitives *)
>   let eol          = Util.eol
>   let value_to_eol = store /([^\\ \t\n].*[^\\ \t\n]|[^\\ \t\n])/
>   let value_to_spc = store /[^\\ \t\n]+/
>   let spc = del /([ \t]+|[ \t]*\\\\\n[ \t]*)/ " "
>
>   (* Define comment *)
>   let comment = Util.comment
>   let empty   = Util.empty
>
>   (* Define a generic entry *)
>   let entry (l:string) = [ spc . label l . value_to_spc ]
>
>   (* Define stanzas *)
>    let array (r:regexp) (t:string) = del r t . label t . counter t . [ spc
> . seq t . value_to_spc ]+
>   let type (t:string) = del t t . label t . spc . value_to_spc
>
>   let words  = /(iface|auto|allow-[a-z-]+|mapping)/
>    let option = [  del /[ \t]*/ "   " . key  ( /[a-z-]+/ - words ) . spc .
> value_to_eol . eol ]
>
>    let auto    = [ array /(allow-)?auto/ "auto" . eol . (comment|empty)* ]


let auto = [ array /(allow-)?auto/ "auto" . (comment|eol) ]

This is sufficient to have auto entries with optional trailing comments


  let iface   = [ type "iface" . entry "family" . entry "method" . eol .
> (option | comment | empty)* ]


let iface = [ type "iface" . entry "family" . entry "method" . eol . (option
| comment | empty)* ]

Actually, you might also have a comment at the end of the iface line, no?

let iface = [ type "iface" . entry "family" . entry "method" . (comment|eol)
. (option | comment | empty)* ]



>   let mapping = [ type "mapping" . eol . (option|comment|empty)* ]


Same remark here (if this is valid, and I believe it is)

let mapping = [ type "mapping" . (comment|eol) . (option | comment | empty)*
]



>   let hotplug = [ type "allow-hotplug" . eol . (comment|empty)* ]
>

This is a single line entry, hence

let hotplug = [ type "allow-hotplug" . (comment|eol) ]


>
>   (* Define stanza *)
>   let stanza = (iface | auto | mapping | hotplug)
>

let s_entry = (auto | hotplug) . (comment|empty)*
let m_entry = iface | mapping



>   (* Define lens *)
>    let lns = ( comment | empty )* . stanza*
>


let lns = (comment|empty)* .
             (m_entry | s_entry)*


>
>    let filter = incl "/etc/network/interfaces"
>              . Util.stdexcl
>
>   let xfm = transform lns filter
>


Ciao


Raphael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20080820/5544d45a/attachment.htm>


More information about the augeas-devel mailing list