Professional Web Applications Themes

Extracting strings delimited by other strings - PERL Modules

Hi, I need to write some code that will allowed embedded, specially formatted comments to doent test cases within a program (SAS code). The code will process the programs, pulling out the test case information. AFAIK this is similar to how Javadoc works, embedding doentation alongside code. The syntax will look like: /* <testcase> TESTID: TEST1 OBJECTIVE: The objective of the test PROCEDURE: The procedure that the test uses Continuation line from the above RESULTS: The expected results of the test Continuation line Another "continuation" line </testcase> */ The syntax can also be embedded in titles statements: /* <testcase> */ ...

  1. #1

    Default Extracting strings delimited by other strings

    Hi,

    I need to write some code that will allowed embedded, specially formatted
    comments to doent test cases within a program (SAS code). The code will
    process the programs, pulling out the test case information. AFAIK this is
    similar to how Javadoc works, embedding doentation alongside code.

    The syntax will look like:

    /*
    <testcase>
    TESTID: TEST1
    OBJECTIVE: The objective of the test
    PROCEDURE: The procedure that the test uses
    Continuation line from the above
    RESULTS: The expected results of the test
    Continuation line
    Another "continuation" line
    </testcase>
    */

    The syntax can also be embedded in titles statements:

    /* <testcase> */
    title3 "TESTID: TEST1";
    title4 "OBJECTIVE: The objective of the test";
    title5 "PROCEDURE: The procedure that the test uses";
    title6 " Continuation line from the above";
    title6 "RESULTS: The expected results of the test";
    title7 " Continuation line";
    title8 ' Another "continuation" line';
    /* </testcase> */

    After processing the program, the desired output is a tab-delimited string
    containing filename, testid, objective, procedure, and results. For those
    lines that were continued, I would like an embedded CR/LF. Leading spaces
    should be
    removed, as well as any title statements, "outer" quotation marks
    (preserving inner quotation marks), and trailing semi-colons.

    Are there any modules that I could use as a starting point for this? If you
    have any code does something similar, could you either post it or email it
    to me? It will be easier to modify an existing example than to start from
    scratch.

    Kind Regards,
    Scott




    Scott Bass Guest

  2. #2

    Default Re: Extracting strings delimited by other strings

    "Scott Bass" <usenet739_yahoo_com_au> wrote in
    news:427c11c6$0$32016$5a62ac22per-qv1-newsreader-01.iinet.net.au:
    > I need to write some code
    ....
    > After processing the program, the desired output is a tab-delimited
    > string containing filename, testid, objective, procedure, and results.
    > For those lines that were continued, I would like an embedded CR/LF.
    Surely, you do not expect people here to write a program to your specs.
    > Are there any modules that I could use as a starting point for this?
    Did you find anything on CPAN? Did you try Google?

    The surest way to get quality help here is to post what you have
    attempted so far, and specific questions regarding specific issues you
    are have encountered.

    Sinan


    --
    A. Sinan Unur <1usallenroc.ude.invalid>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    [url]http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html[/url]
    A. Sinan Unur Guest

  3. #3

    Default Re: Extracting strings delimited by other strings

    Scott Bass <> wrote:
    > /*
    ><testcase>
    > TESTID: TEST1
    > OBJECTIVE: The objective of the test
    > PROCEDURE: The procedure that the test uses
    > Continuation line from the above
    > RESULTS: The expected results of the test
    > Continuation line
    > Another "continuation" line
    ></testcase>
    > */
    >
    > The syntax can also be embedded in titles statements:
    >
    > /* <testcase> */
    > title3 "TESTID: TEST1";
    > title4 "OBJECTIVE: The objective of the test";
    > title5 "PROCEDURE: The procedure that the test uses";
    > title6 " Continuation line from the above";
    > title6 "RESULTS: The expected results of the test";
    > title7 " Continuation line";
    > title8 ' Another "continuation" line';
    > /* </testcase> */
    >
    > After processing the program, the desired output is a tab-delimited string

    I'm going to use commas because they are easier to see.

    > containing filename, testid, objective, procedure, and results. For those
    > lines that were continued, I would like an embedded CR/LF. Leading spaces
    > should be
    > removed, as well as any title statements, "outer" quotation marks
    > (preserving inner quotation marks), and trailing semi-colons.
    >
    > Are there any modules that I could use as a starting point for this?

    I dunno.

    Hardly seems worth modularization when it only takes about
    20 lines of regular ol' Perl.

    Assuming the whole file is slurped into $_ :

    ------------------------------
    while ( m#<testcase>(.*?)</testcase>#gs ) {
    my $record = normalize($1);
    my(undef,parts) = split /(?:TESTID|OBJECTIVE|PROCEDURE|RESULTS):\s+/,
    $record;
    chomp parts;
    print join( ',', parts), "\n";
    }

    sub normalize {
    my($r) = _;

    $r =~ s#^\s*\*/##; # snip bits of comment delimiters
    $r =~ s#/\*\s*##;

    $r =~ s#^title\d+ ##gm; # remove title statement cruft
    $r =~ s#^(['"])(.*?)\1;#$2#gm;

    $r =~ s#\n\s\s+#\n#; # join continuation lines

    $r =~ s#^\s*##; # trim spaces
    $r =~ s#\s*$##;
    return $r;
    }
    ------------------------------


    --
    Tad McClellan SGML consulting
    [email]tadmcaugustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

Similar Threads

  1. Extracting a comma or tab delimited file from a converted .pdf
    By Yasmine_Carson@adobeforums.com in forum Adobe Acrobat Windows
    Replies: 1
    Last Post: May 3rd, 12:45 PM
  2. strings
    By James Brown in forum Microsoft Access
    Replies: 5
    Last Post: February 14th, 07:05 PM
  3. strings into variables....
    By dipsy18 webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 2
    Last Post: October 1st, 03:00 PM
  4. Parsing Comma Delimited Strings
    By Word of Mouth Productions in forum Macromedia Director Lingo
    Replies: 5
    Last Post: September 17th, 08:38 PM
  5. [PHP] strings
    By Curt Zirzow in forum PHP Development
    Replies: 1
    Last Post: August 2nd, 04:47 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139