[augeas-devel] help with nrpe.cfg lens

Francis Giraldeau Francis.Giraldeau at USherbrooke.ca
Fri Aug 6 02:32:50 UTC 2010


Le jeudi 05 août 2010 à 16:57 +0200, Marc Fournier a écrit :
> My (stripped-down) code is currently unable to match more than
> one sub-item:
>
> test_test.aug:5.7-.31:exception: Get did not match entire input
>     Lens: ./test.aug:8.16-.95:
>     Error encountered at 2:0 (17 characters into string)
>              <command[foo]=bar\n|=|command[bar]=baz\n>
>
>     Tree generated so far:
>     /command
> /command/foo = "bar"

There was 2 problems. First: look at the test. The lens that is tested
is "command", but the iteration is defined only in "lns", that's why it
matches only once. Your lens works when using "lns" for the test. The
second problem I see is the subtree of the command lens. This subtree
shouldn't be iterated. It doesn't prevent the lens from working, but it
doesn't seems make sens to allow iteration there.

If you need debugging, then you can use this trick:

   let _ = print_regexp(lens_ctype(some_fucked_lens))
   let _ = print_endline ""

The "ctype" is the actual regexp that will be used to match the input
file.

As for the tree, I would do at first a simple lens, try it, and see if
it fits the need with a use case.

Have a nice day,

Francis
-------------- next part --------------

module Test2 =

  let nl = del /\n/ "\n"
  let eq = del /=/ "="
  let obrkt = del /\[/ "["
  let cbrkt = del /\]/ "]"

  let command = [ key "command" .
    [ obrkt . key /[a-z]+/ . cbrkt . eq . store /[^=]+/ . nl ]*
  ]

  let lns = ( command ) *

  let cmd = "command[foo]=bar\ncommand[bar]=baz\n"

  test lns get cmd =
  { "command"
    { "foo" = "bar" }
  }
  { "command"
    { "bar" = "baz" }
  }



More information about the augeas-devel mailing list