[augeas-devel] need help with learning lense grammar

Jennings, Jared L CTR USAF AFMC 46 SK/CCI jared.jennings.ctr at eglin.af.mil
Wed Aug 24 16:50:42 UTC 2011


>     automaster.aug:16.19-21.71:exception: ambiguous concatenation
>           First regexp: /(([^,:#=\n\t ]+))([ \t]+)(((([^,:#=\n\t
> ]+))(,))?)(((([^,:#=\n\t ]+))(:))?)(((([^,:#=\n\t ]+))([ \t]+))?)/
>           Second regexp: /((([^,:#=\n\t ]+))([ \t]+))?/

>     			( [ label "map" . store word ] . sep_spc )? .
>     			( [ label "options" . store word ] . sep_spc )?

The first regexp runs like "(bla, spaces and tabs)?, (bla, comma)?,
(bla, colon)?, (bla, spaces and tabs)?; the second regexp runs like
(bla, spaces and tabs)?. The end of the first regexp matches the same
stuff as the second regexp.

Or, looking at a higher level, the syntaxes for map and options are the
same: a word followed by space; and both are optional. So if only one
occurs, Augeas cannot know whether it is a map or an options.

Here's my automaster.aug for comparison. You've used the existing lenses
to greater effect than I. Mine constricts the definitions of different
words more (e.g., type and format), which can have a simplifying effect
on the final regex. Looks like I'm not dealing with # signs in the
middle of lines though.

module Automaster =
    autoload xfm
    
    let eol = Util.eol
    let comment = Util.comment
    let empty = Util.empty

    let mount_point = store /\/[^# \t\n]+/
    let include = [ label "include" . 
                    del /\+[ \t]*/ "+" .
                    store /[^# \t\n]+/ .
                    eol ]
    let options = [ label "options" . store /-[^ \t\n]+/ ]
    let map_param = 
        let    name = [ label "name" . store /[^: \t\n]+/ ]
        in let type = [ label "type" . store /[a-z]+/ ]
        in let format = [ label "format" . store /[a-z]+/ ]
        in let options = [ label "options" . store /[^ \t\n]+/ ]
        in let prelude = ( type .
                           ( del "," "," . format ) ? .
                           del ":" ":" )
        in ( prelude ? .
             name .
             ( Util.del_ws_spc . options ) ? )
    let map_record = [ label "map" .
                       mount_point . Util.del_ws_spc .
                       map_param .
                       eol ]

    let lns = ( map_record |
                include |
                comment |
                empty ) *

    let relevant = (incl "/etc/auto.master") .
                   Util.stdexcl
    let xfm = transform lns relevant




> -----Original Message-----
> From: augeas-devel-bounces at redhat.com [mailto:augeas-devel-
> bounces at redhat.com] On Behalf Of Joshua Hoblitt
> Sent: Tuesday, August 23, 2011 4:06 PM
> To: augeas-devel at redhat.com
> Subject: [augeas-devel] need help with learning lense grammar
> 
> I've never really tried to use Augeas before yesterday and I've been
> unable to find lenses for the /etc/auto.master and autofs(5) config
> files, so I decided to try to write my own.
> 
> I've looked at the step by step directions and eventually simplified
> things by using pre-existing lenses as examples.
> http://augeas.net/page/Creating_a_lens_step_by_step
> 
> As a first stab at automaster(5), this is what I've come up with,
> although it's not complete:
> 
>     module Automaster =
>         autoload xfm
> 
>         let eol     = Util.eol
>         let comment = Util.comment
>         let empty   = Util.empty
>         let comma   = Sep.comma
>         let colon   = Sep.colon
>         let sep_spc = Sep.space
> 
>         let word       = /[^,:#\n\t ]+/
> 
>         let record = [ seq "automap" .
>     			[ label "key" . store word ] . sep_spc .
>     			( [ label "map-type" . store word ] . comma )? .
>     			( [ label "format" . store word ] . colon )? .
>     		 ] (* removed eol as I think sep_spc will consume \n *
> 
>         let lns = ( empty | comment | record ) *
> 
>         let filter = incl "/etc/auto.master"
> 
>         let xfm = transform lns filter
> 
> There is an error in this grammar in the whitespace handling but it's
> not jump out at me.
> The error message:
> 
>     $ augtool --version
>     augtool 0.9.0 <http://augeas.net/>
>     Copyright (C) 2009-2010 David Lutterkort
>     License LGPLv2+: GNU LGPL version 2.1 or later
>                      <http://www.gnu.org/licenses/lgpl-2.1.html>
>     This is free software: you are free to change and redistribute it.
>     There is NO WARRANTY, to the extent permitted by law.
> 
>     Written by David Lutterkort
>     $ augparse automaster.aug
>     Syntax error in lens definition
>     automaster.aug:16.4-22.4:Failed to compile record
>     automaster.aug:16.19-21.71:exception: ambiguous concatenation
>           First regexp: /(([^,:#=\n\t ]+))([ \t]+)(((([^,:#=\n\t
> ]+))(,))?)(((([^,:#=\n\t ]+))(:))?)(((([^,:#=\n\t ]+))([ \t]+))?)/
>           Second regexp: /((([^,:#=\n\t ]+))([ \t]+))?/
>           'A A ' can be split into
>           'A |=|A '
> 
>          and
>           'A A |=|'
> 
>         First lens: automaster.aug:16.19-20.67:
>         Second lens: automaster.aug:21.24-.71:
> 
> 
> So it appears that /[ ]/ can consume a newline in this regex dialect?
> What is the proper way to structure this grammar so that whitespace
> handling isn't ambiguous?
> 
> Thanks,
> 
> -Josh
> 
> --
> 
> _______________________________________________
> augeas-devel mailing list
> augeas-devel at redhat.com
> https://www.redhat.com/mailman/listinfo/augeas-devel




More information about the augeas-devel mailing list