Hi!

I have ascii files describing network topology like this:

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;} }
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.
The range-alternative is for hosts with several ip-adresses in order to avoid having to type all ip-adresses in the host-specification-line like so:
host:ix_13_20 = {ip = 10.1.1.13; ip = 10.1.1.14; ..... ; ip = 10.1.1.2 +0 }
Here is part of my 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"; }
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.

I hope I explained precisely enough what I am trying to achieve here ... anyone any hint?

Thanks, Daniel.

update (broquaint): fixed formatting


In reply to Parse::RecDescent and <score: ...> directive by orrence

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.