[augeas-devel] Re: [Interfaces] Draft lense

Free Ekanayaka free at 64studio.com
Thu Aug 21 21:42:33 UTC 2008


Hi Raphaël,

|--==> Raphaël Pinson writes:

  RP> Let's see...

  RP> The expected tree for 'auto\\\nA# A\n' is

  RP> { "auto"
  RP>    { "1" = "A"
  RP>       { "comment" = "A" } } }

  RP> and this is what the first lens does alright (btw David if you read this, I
  RP> think it would be great if lens conflicts would print the tree generated by
  RP> the lenses, it would greatly help to understand the issue).
  RP> But it seems that a second lens does

  RP> { "auto"
  RP>    { "1" = "A# A" } }

  RP> '#' is not a valid character in an iface name, but we have:

  RP> let value_to_spc = store /[^\\ \t\n]+/
  RP> let array (r:regexp) (t:string) = del r t . label t . counter t . [ spc .
  RP> seq t . value_to_spc ]+


  RP> See the issue? Just turning your value_to_spc in to a [^\\# \t\n] should fix
  RP> this.

Thanks for explanation, very clear. Excluding "#" from the characters
of the stored value fixed the issue, so that single-line entries work now
perfectly.

However if I try to support trailing comments with multi-line entries
like:

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

I'm getting another error:

lenses/interfaces.aug:30.3-.71:Failed to compile mapping
lenses/interfaces.aug:30.19-.69:exception: ambiguous tree concatenation
      '#comment/' can be split into
      '|=|#comment/'

     and
      '#comment/|=|'

    First lens: lenses/interfaces.aug:30.19-.49
    Second lens: lenses/interfaces.aug:30.52-.69

and I can't figure out why.

Do the messages "ambiguous tree concatenation" and "ambiguous
concatenation" actually differ?

Also I don't fully understand what does the "|=|" stand for, Below you
find the current version of the code.

Thanks,

Free

================ 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 eol = del "\n" "\n"
   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" . (comment|eol) ]
   let hotplug = [ type "allow-hotplug" . (comment|eol) ]
   let iface   = [ type "iface" . entry "family" . entry "method" . eol . (option | comment | empty)* ]
   let mapping = [ type "mapping" . (comment|eol) . (option|comment|empty)* ]

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

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

   let filter = incl "/etc/network/interfaces"
              . Util.stdexcl

   let xfm = transform lns filter





More information about the augeas-devel mailing list