[augeas-devel] Wildcarded key/value pairs and nested blocks (dovecot lens development)
Raphaël Pinson
raphael.pinson at camptocamp.com
Thu Mar 7 16:00:18 UTC 2013
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20130307/4cae2f54/attachment.htm>
More information about the augeas-devel
mailing list