On 06/01/2011 01:42 PM, Doug Warner wrote:
> I'm trying to get a lens that will work for gentoo's new /etc/conf.d/net file
> (http://www.gentoo.org/doc/en/openrc-migration.xml) that uses variables that
> /look/ like shellvars, but separates things by newlines.
> 
> It look like the Shellvars_list lens might be close, but it separates on any
> whitespace and not just newlines.  I'm not sure exactly how to modify it since
> it makes use of a recursive function.
> 
> Any tips on how to proceed?
> 
> -Doug

Here's what I've been working on so far; I'm getting stuck on this parse error
currently:


$ augparse -I . gentooconf_net.aug
Syntax error in lens definition
gentooconf_net.aug:27.2-.79:Failed to compile squote_arr
gentooconf_net.aug:23.6-.43:exception: ambiguous iteration
      Iterated regexp: /([ \t]*\n)([^'\n]+)/
      '\nA \nA' can be split into
      '\nA|=| \nA'

     and
      '\nA |=|\nA'

    Iterated lens: gentooconf_net.aug:23.6-.42:


I believe I want to completely absorb that space in there, but the problem I'm
running into is I don't know where the best place to do that is.  If I change
the "eol" in my iterated lens to "nl" (newline only, no whitespace) this error
goes away, but I get a parse error on the bigger picture:


$ augparse -I . gentooconf_net.aug
Syntax error in lens definition
gentooconf_net.aug:37.2-.80:Failed to compile kv
gentooconf_net.aug:37.13-.78:exception: ambiguous concatenation
      First regexp:
/([A-Za-z0-9_]+)(=)(((('))(((([^'\n]+))(((\n)([^'\n]+))*))?)('))|(((\"))(((([^\"\n]+))(((\n)([^\"\n]+))*))?)(\"))|((((([^\"'\n]+)+))?)))/
      Second regexp: /[ \t]*\n/
      'A= \n' can be split into
      'A=|=| \n'

     and
      'A= |=|\n'

    First lens: gentooconf_net.aug:37.13-.71:
    Second lens: /usr/share/augeas/lenses/dist/util.aug:54.12-.31:


This is obviously not what I want; I don't want a trailing space to be
considered a value at all.

-Doug
(* Lens to match the crazy newline-split variables that Gentoo    *)
(* uses in it's openrc-based /etc/conf.d/net file                 *)
module GentooConf_net=
  autoload xfm

  let nl  = Util.del_str "\n"
  let eol = Util.eol

  let key_re = /[A-Za-z0-9_]+/
  let eq      = Util.del_str "="
  let comment = Util.comment
  let empty   = Util.empty
  let indent  = Util.indent

  let sqword = /[^'\n]+/
  let dqword = /[^"\n]+/
  let uqword = /[^"'\n]+/

  (* lists values of the form ...  val1 val2 val3  ... *)
  let list(word:regexp) =
    let list_value = store word in
      [ label "value" . list_value ] .
      [ eol . label "value" . list_value ]*


  (* handle single quoted lists *)
  let squote_arr = [ label "quote" . store /'/ ] . (list sqword)? . del /'/ "'"

  (* similarly handle double qouted lists *)
  let dquote_arr = [ label "quote" . store /"/ ] . (list dqword)? . del /"/ "\""

  (* handle unquoted single value *)
  let unquot_val = [ label "quote" . store "" ] . [label "value"  . store 
uqword+]?


  (* lens for key value pairs *)
  let kv = [ key key_re . eq . ( squote_arr | dquote_arr | unquot_val ) . eol ]

  let lns = ( comment | empty | kv )*

  let filter = incl "/etc/conf.d/net/"
             . Util.stdexcl

  let xfm = transform lns filter

(* Local Variables: *)
(* mode: caml       *)
(* End:             *)
module Test_GentooConf_Net=
  test GentooConf_Net.lns get "config_eth0=\"null\"\n" =
    { "config_eth0"
      { "quote" = "\"" }
      { "value" = "null" }
    }

  test GentooConf_Net.lns get "vlans_eth1=\"10 11\"\n" =
    { "config_eth0"
      { "quote" = "\"" }
      { "value" = "10 11" }
    }

  test GentooConf_Net.lns get 
"config_eth0=\"192.168.0.1/24\n192.168.1.1/24\"\n" =
    { "config_eth0"
      { "quote" = "\"" }
      { "value" = "192.168.0.1" }
      { "value" = "192.168.0.2" }
    }


(*
config_eth0="null"
config_eth1="null"
vlans_eth1="10 11"
vlan10_name="vlan10"
config_vlan10="192.168.0.1/24"
routes_vlan10="10.0.0.0/8 via 192.168.0.2"
vlan11_name="vlan11"
config_vlan11="172.16.0.1/25"
routes_vlan11="default via 172.16.0.2"
#vlan_start_eth1="no"
#rc_need_vlan10="net.eth1"
#rc_need_vlan11="net.eth1"
*)

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
augeas-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/augeas-devel

Reply via email to