If you're doing it moduleless, why not:

ie

# use this in your rule tests for position my %structure = ( 1 => {qw(a b c d e f g h i etc...)}, 2 => {qw(1 2 3 4 5 6 7 8 9 10 11 12 13 etc...)}, 3 => {qw(A B C D E F G H I etc...)}, 4 => {qw(i ii iii iv v vi vii viii ix x xi etc...)} ); my %legalese; # hash to store text/markers my $key = 2; # key marker to keep order ('1' is tree root) # read into hash while (s/\((\w+)\)(.*?)(\(\w+\))/$3/s) { $legalese{$key}{'list_id'} = $1; $legalese{$key}{'content'} = $2; $key++; } my %node = ( 1 => ''); # node structure tree # initialise with single node # to denote top of page # now work on rules for tree depth my $last_node; # go through markers in order parsed in for (sort {$a <=> $b;} keys %legalese) { # too tired to try to create rule set :) # but set nodes as follows $node{$_}{'parent'} = 'whatever parent node is' # either '1', $last_node, or somewhere in between # using %structure as your guide $last_node = $_; }
The above is in no way final code, but that's the sort of approach I'd take.

Hope that's enough pointers. By knowing what type the previous node was, you can create a valid rule for the next node by asking:

etc, etc...

cLive ;-)


In reply to Re: Parsing the Law by cLive ;-)
in thread Parsing the Law by swiftone

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.