orrence has asked for the wisdom of the Perl Monks concerning the following question:
I have ascii files describing network topology like this:
Now I am trying to use Parse::RecDescent to extract relevant information and visualize it in a nice way. My problem is, that I can't seem to get the host and host-range alternatives to work at the same time.network:north = { ip = 10.1.1.0; mask = 255.255.255.0; host:asterix = {ip = 10.1.1.10;} host:obelix = {ip = 10.1.1.11;} host:idefix = {ip = 10.1.1.12;} host:ix_13_20 = {range = 10.1.1.13 - 10.1.1.20;} }
Here is part of my grammar:host:ix_13_20 = {ip = 10.1.1.13; ip = 10.1.1.14; ..... ; ip = 10.1.1.2 +0 }
The host rule matches for the host-range as well with 0 matches for subrule ip and host_range isn't considered anymore. I thought I could change this behaviour with the <score: ...> directive, but I can't get it to try the host_range part of the grammar if a range is specified and I therefor get 0 matches for subrule ip for the "host"-part of the grammar.startrule: network_object(s) ip: 'ip' '=' /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/ ip_nosemi: 'ip' '=' /\d{1,3}\.\d{1,3}\.\d{1,3}\.d{1,3}/ mask: /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3};/ host: /host:\w+/ '=' '{' ip(s) '}' host_range: /host:\w+/ '=' '{' 'range' '=' ip_nosemi '-' ip '}' hosts_or_range: host(s?) | host_range #hosts_or_range: host(s?) <score: 2> | host_range <score: 1> network_object: /network:(\w+)/ '=' '{' ip 'mask' '=' mask hosts_or_range '}' { print "Found network object named $item[1] " . "with IP $item{ip} and MASK $item{mask}\n"; }
I hope I explained precisely enough what I am trying to achieve here ... anyone any hint?
Thanks, Daniel.
update (broquaint): fixed formatting
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parse::RecDescent and <score: ...> directive
by tachyon (Chancellor) on Sep 22, 2003 at 13:03 UTC | |
|
Re: Parse::RecDescent and <score: ...> directive
by kabel (Chaplain) on Sep 22, 2003 at 16:15 UTC | |
|
Re: Parse::RecDescent and <score: ...> directive
by jryan (Vicar) on Sep 22, 2003 at 17:37 UTC |