[augeas-devel] how to make lens accept both quoted and unquoted values with trailing comments

Timur Batyrshin erthad at gmail.com
Wed Nov 12 13:25:46 UTC 2014


Hi,

Actually I've tried that too but changed later to manual quoting as it
seemed to me easier to debug that.

I've tried several cases and none of them worked (sorry for much text):


1. Use quote module with the same union operation.
module Testtest =

let to_comment_re = /[^";# \t\n][^;#\n]*[^;# \t\n]|[^";# \t\n]/
let sto_to_comment = Sep.opt_space . store to_comment_re

let quoted_value_re = /[^"]*/
let quoted_value = Sep.opt_space . Quote.do_dquote (store quoted_value_re)

let value = sto_to_comment | quoted_value


# augparse /tmp/testtest.aug
Syntax error in lens definition
/tmp/testtest.aug:9.0-.41:Failed to compile value
/tmp/testtest.aug:9.12-.41:exception: overlapping lenses in tree union.put
    Example matched by both:
    First lens: /tmp/testtest.aug:4.21-.56:
    Second lens: /tmp/testtest.aug:7.19-.74:


2. Replace union by do_dquote_opt_nil:
module Testtest =

let to_comment_re = /[^";# \t\n][^;#\n]*[^;# \t\n]|[^";# \t\n]/
let sto_to_comment = Sep.opt_space . store to_comment_re

let quoted_value_re = /[^"]*/
let quoted_value = Sep.opt_space . Quote.do_dquote_opt_nil (store
to_comment_re)

let value = quoted_value

$ augparse /tmp/testtest.aug
Syntax error in lens definition
/tmp/testtest.aug:7.0-.80:Failed to compile quoted_value
/usr/share/augeas/lenses/dist/quote.aug:96.2-.43:exception: ambiguous
concatenation
      First regexp: /("?)([^";# \t\n][^;#\n]*[^;# \t\n]|[^";# \t\n])/
      Second regexp: /"?/
      'AA"' can be split into
      'AA|=|"'

     and
      'AA"|=|'

    First lens: /usr/share/augeas/lenses/dist/quote.aug:96.2-.43:
    Second lens: /usr/share/augeas/lenses/dist/quote.aug:37.21-.32:


3.  If I specify to_comment_re as the following (just remove " characters
from it):

let to_comment_re = /[^;# \t\n][^;#\n]*[^;# \t\n]|[^;# \t\n]/

I get the following error:

$ augparse /tmp/testtest.aug
Syntax error in lens definition
/tmp/testtest.aug:7.0-.80:Failed to compile quoted_value
/usr/share/augeas/lenses/dist/quote.aug:96.2-.43:exception: ambiguous
concatenation
      First regexp: /"?/
      Second regexp: /[^;# \t\n][^;#\n]*[^;# \t\n]|[^;# \t\n]/
      '"A' can be split into
      '|=|"A'

     and
      '"|=|A'

    First lens: /usr/share/augeas/lenses/dist/quote.aug:37.21-.32:
    Second lens: /tmp/testtest.aug:7.59-.79:


I think I've tried several similar cases with " added or removed but still
get the similar results.
That's why I've sent a message here to ask for help with understanding
better of how to handle such cases.


Thanks,
Timur


On Wed, Nov 12, 2014 at 3:37 PM, Raphaël Pinson <
raphael.pinson at camptocamp.com> wrote:

> Hi,
>
> The best way to process these now is to use the Quote module, which makes
> use of square lenses. There's quite a few examples using it already.
>
>
> Raphaël
>
>
> On Tue, Nov 11, 2014 at 5:04 PM, Timur Batyrshin <erthad at gmail.com> wrote:
>
>> Hi all,
>>
>> I'm trying to create a lens that accepts both quoted and unquoted values
>> and is able to process trailing comments of both ; and #-style
>>
>> Here is my lens (actually it is only a part of bigger pre-1.1
>> inifile-based one but this is enough to reproduce the issue):
>>
>> module Testtest =
>>
>> let to_comment_re = /[^";# \t\n][^;#\n]*[^;# \t\n]|[^";# \t\n]/
>> let sto_to_comment = Sep.opt_space . store to_comment_re
>>
>> let quote = del "\"" "\""
>> let quoted_value_re = /[^"]*/
>> let quoted_value = Sep.opt_space . (quote . (store quoted_value_re) .
>> quote)
>>
>> let value = sto_to_comment | quoted_value
>>
>>
>> When I try to process it with augparse I see the following result:
>>
>> $ augparse /tmp/testtest.aug
>> Syntax error in lens definition
>> /tmp/testtest.aug:10.0-.41:Failed to compile value
>> /tmp/testtest.aug:10.12-.41:exception: overlapping lenses in tree
>> union.put
>>     Example matched by both:
>>     First lens: /tmp/testtest.aug:4.21-.56:
>>     Second lens: /tmp/testtest.aug:8.19-.76:
>>
>> How should I deal with errors like that?
>> I understand that augeas can't figure out if it should quote my value or
>> not when writing it but I have no ideas how to make it separate between
>> them.
>> How do you usually handle the case like this one?
>>
>>
>> Thanks,
>> Timur
>>
>> _______________________________________________
>> augeas-devel mailing list
>> augeas-devel at redhat.com
>> https://www.redhat.com/mailman/listinfo/augeas-devel
>>
>
>
>
> --
> Raphaël Pinson
> Infrastructure Developer & Training Leader
> +33 479 26 57 93
> +33 781 90 00 79
>
> 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/20141112/8b97dbee/attachment.htm>


More information about the augeas-devel mailing list