[augeas-devel] Wildcarded key/value pairs and nested blocks (dovecot lens development)

Serge Smetana serge.smetana at gmail.com
Thu Mar 7 15:33:02 UTC 2013


Hi Raphaël,

Trying to use Build.block_newlines construct

   let any = Rx.no_spaces
   let value = any . (Rx.space . any)*
   let commands  = /include|include_try/
   let block_names = /dict|userdb|passdb|protocol|service|plugin|namespace|map/
   let nested_block_names =  /fields|unix_listener|fifo_listener|inet_listener/
   let keys = Rx.word - commands - block_names - nested_block_names

   let entry = [ indent . key keys. eq . (Sep.opt_space . store value)? . eol ]
   let command = [ command_start . key commands . Sep.space . store
Rx.fspath . eol ]

   let block_args   = Sep.space . store any

   let nested_block = [ indent . key block_names . block_args? .
Build.block_newlines entry comment . eol ]
   let block = [ indent . key block_names . block_args? .
Build.block_newlines (entry|nested_block)* comment . eol]

   let lns = (comment|empty|entry|command|block)*

If I try to compile this I get an exception: ambiguous concatenation

      First regexp: /([
\t]*)(dict|userdb|passdb|protocol|service|plugin|namespace|map)((([
\t]+)([^ \t\n]+))?)/
      Second regexp: /([ \t\n]+\\{([ \t\n]*\n)?)((((([
\t]*)((dict[.0-9A-Z_a-z-][.0-9A-Z_a-z-]| ...... <long regexp
here>.....

      'userdb {# {\n}' can be split into
      'userdb|=| {# {\n}'

     and
      'userdb {#|=| {\n}'

I guess this is because of optional block_args? in lens definition.
But my old variant without Build.block* construct works:

  let block_open        = del /[ \t]*\{/ "{"
  let block_close       = del /\}/ "}"

  .... same as above

  let nested_block =
       [ indent . key nested_block_names . block_args? . block_open . eol
       . (entry | empty | comment)*
       . indent . block_close . eol ]

   let block =
       [ indent . key block_names . block_args? . block_open . eol
       . (entry | empty | comment | nested_block )*
      . indent . block_close . eol ]

On Wed, Mar 6, 2013 at 6:10 PM, Raphaël Pinson
<raphael.pinson at camptocamp.com> wrote:
>
> On Wed, Mar 6, 2013 at 4:54 PM, Serge Smetana <serge.smetana at gmail.com>
> wrote:
>>
>> Hi Raphaël,
>>
>> Thank you very much for the comments.
>> I cannot apply all of them because currently we use Augeas 0.10 but
>> will make changes for the rest.
>>
>> My main question was is there any way to describe keys as regexp
>> instead of having fixed list and to have lens for the blocks without
>> "overlapping lenses" exception?
>
>
>
> Sure, you can use regexps for keys. You can write things like:
>
>     key /(no)?flag/
>
> or:
>
>     key /one|two|three/
>
> for example.
>
>
> As for the blocks, you could have a look at the way keepalived was written
> before Build.block* constructs were introduced. Keep in mind that
> Build.block* constructs cost me quite a few hours of headaches to properly
> cover edge cases, and implementing these cases manually will be hard.
>
>
>
> Raphaël
>
>
>
>>
>>
>> Thank you.
>>
>> Serge
>>
>> On Wed, Mar 6, 2013 at 9:35 AM, Raphaël Pinson
>> <raphael.pinson at camptocamp.com> wrote:
>> > Hi Serge,
>> >
>> >
>> > Great job! I've left some comments on github directly.
>> >
>> >
>> > Regards,
>> >
>> > Raphaël
>> >
>> >
>> > On Tue, Mar 5, 2013 at 7:28 PM, Serge Smetana <serge.smetana at gmail.com>
>> > wrote:
>> >>
>> >> Hello,
>> >>
>> >> I'm trying to create lens for Dovecot config.
>> >> I'm already have working lens here:
>> >>
>> >>
>> >> https://github.com/smetana/augeas/commit/0cbd6b88e0f1bf2e281fa3ea16803abbf8b3d770
>> >>
>> >> But it is too "tight" because of the fixed list of keywords for the
>> >> entries.
>> >> Dovecot supports blocks and nested blocks like
>> >>
>> >> service auth {
>> >>   unix_listener auth-userdb {
>> >>      ...
>> >>   }
>> >> }
>> >>
>> >> and if I create wildcarded lens for simple entry
>> >>
>> >>    let entry = [ indent . key Rx.word. eq . (store value)? . eol ]
>> >>
>> >> I am unable to create lens for the block
>> >>
>> >>    let block_names = ("protocol" | "service" | "plugin" | "namespace" |
>> >> "map" )
>> >>    let block =
>> >>        [ indent . key block_names . block_args? . block_open . eol
>> >>        . (entry | empty | comment)*
>> >>        . indent . block_close . eol ]
>> >>
>> >> I end up with exception: overlapping lenses in tree union.put
>> >>     Example matched by both:  { "protocol" }
>> >>
>> >> Is there any way to define possible keys as something like a
>> >> subsctraction (Rx.word - block_names)
>> >> meaning "match anything but not /protocol|service|map/"?
>> >>
>> >> Thank you!
>> >> Great job!
>> >>
>> >> Serge
>> >>
>> >> _______________________________________________
>> >> augeas-devel mailing list
>> >> augeas-devel at redhat.com
>> >> https://www.redhat.com/mailman/listinfo/augeas-devel
>> >
>> >
>> >
>> >
>> > --
>> > Raphaël Pinson
>> > Administrateur Systèmes & Réseaux
>> > Camptocamp France
>> > Savoie Technolac
>> > BP 352
>> > 48, avenue du Lac du Bourget
>> > 73372 Le Bourget du Lac, Cedex
>> > www.camptocamp.com
>
>
>
>
> --
> Raphaël Pinson
> Administrateur Systèmes & Réseaux
> Camptocamp France
> Savoie Technolac
> BP 352
> 48, avenue du Lac du Bourget
> 73372 Le Bourget du Lac, Cedex
> www.camptocamp.com




More information about the augeas-devel mailing list