[augeas-devel] Wildcarded key/value pairs and nested blocks (dovecot lens development)
Serge Smetana
serge.smetana at gmail.com
Thu Mar 7 18:06:47 UTC 2013
Hi Raphaël,
Thank you very much. I finally understood Build.block* and recursive lenses.
Please find the final lens here
https://github.com/smetana/augeas/blob/00f125a39e2fc9512df8deb779650673a4da4609/lenses/dovecot.aug
If you like it I can make pull request to augeas repository.
Thank you,
Serge
On Thu, Mar 7, 2013 at 6:00 PM, Raphaël Pinson
<raphael.pinson at camptocamp.com> wrote:
>
>
> On Thu, Mar 7, 2013 at 4:33 PM, Serge Smetana <serge.smetana at gmail.com>
> wrote:
>>
>> 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
>
>
> This kind of constructs makes augparse (and run) verrrrrrrrrrrrry slooooow.
> It is best to rewrite them as:
>
> let keys = Rx.word - (commands | block_names | nested_block_names)
>
> which is strictly equivalent, but much faster.
>
>
>>
>>
>> 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.
>
>
>
> Yes, precisely. Spaces must belong only to one side of two concatenated
> expressions.
>
>
>>
>> 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 ]
>
>
>
> Build.block_newlines allows things like
>
> unix_listener {# {\n}
>
> where "# {\n" should be a comment.
>
> However, block_args? allows *any* character (including "#" and "{") to be
> present between the key and the opening bracket. I think block_args should
> be refined to only allow the characters you need.
>
>
> Regards,
>
> --
> 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