This might be oversimplifying the situation, but it's the only reasonable approach I can think of:

Do two operations: split on /\s*\([a-zA-Z1-90]*\)/ in @texts, and then do a /\s*\(([a-zA-Z1-90]*)\)/g into @sections. Shift off the first element of @texts (should be whatever comes before the first section indicator, which you suggest is null), and then for array element $i, $texts[$i] corresponds to $section[$i].

Now, you simply need to work out the tree structure for this. Create an array of subroutines that parse the appropriate section number at the given level. Eg:

sub major_section { $sec = shift; if ( $sec =~ /^([A-Z])$/ ) { return ( ord $1 - ord 'A' + 1 ); } else { return 0; } }
For each @section in turn, start at one level below the current one in this coderef array and see if it matches; if so, it's at that level, otherwise move backwards in the coderef array until you hit a match. If you don't hit a match, then you want to try for your list starter (which must begin with 1) and if it's a list, run the list until the next section changes.

The only problem is a case like the following:

A. 1. 2. a. 1. list data 2. list data 3. 4.
without more formal guidelines from the original format, you will not be able to determin where A.2.a's list stops and section A.3 begins. Also, this assumes that any other text within parenthesis has whitespace and thus does not look like section headers.


Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

In reply to Re: Parsing the Law by Masem
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.