RSS 2.0 Feed

» Welcome Guest Log In :: Register

Pages: (38) < [1] 2 3 4 5 6 ... >   
  Topic: Board Mechanics< Next Oldest | Next Newest >  
steve_h



Posts: 532
Joined: Jan. 2006

(Permalink) Posted: May 12 2006,11:02   

Not sure that a full parser is necessary. If you add a (.*) to the front of your pattern (To slurp up the longest text that doesn't contain {quote}, you can find the last complete inner quote. Then iterate until you find no more or you hit a limit (to avoid infinite loops if there is a mistake). I also combined the handling of {quote=} and {quote} forms, otherwise it still gets hopelessly muddled.


Code Sample
#! perl

$_ = <<END;

{quote=wes, 08:00:10}
  {quote}
     {quote}
        Three quotes
          {quote=steve, 01:15}  yes but  {/quote}
          {quote}  no but {/quote}
          {quote=xxx, 01:17}  yes {/quote}
          get a life, steve
      {/quote}
  {/quote}

  {quote=blah, blah} blah blah {/quote}
  {quote} yawn {/quote}
{/quote}
END

$MAXQUOTES=20;
$n=0;
for( $i = 0; $i < $MAXQUOTES &&  $_ ne $old; $i++)
{

  $old=$_;
  s{(.*)\{quote(=(.+?),\s*(.+?))?\}(.+?)\{/quote\}} {
       $n++;
       if ($2 ne "")
       {
        $x = "$1 {QT$n of=$3 at=$4} $5 {/QT$n}";
       }
       else
       {
         $x = "$1 {QT$n} $5 {/QT$n}";
       }
    }eisx;

 #   print "Iteration $i:\n $_";
}

die "unmatched quotes" if (/{\/?quote}/);
print;



produces
Code Sample

{QT8 of=wes at=08:00:10}
   {QT7}
      {QT6}  
        Three quotes
           {QT5 of=steve at=01:15}   yes but   {/QT5}
           {QT4}   no but  {/QT4}
           {QT3 of=xxx at=01:17}   yes  {/QT3}
          get a life, steve
       {/QT6}
   {/QT7}

   {QT2 of=blah at=blah}  blah blah  {/QT2}
   {QT1}  yawn  {/QT1}
{/QT8}  


edit: purged spurious last if.

My deepest sympathy to anyone that can make any sense of the above "edit" comment.

Do you have the code that handles hyperlinks handy? They've caused me considerable annoyance of late.

  
  1132 replies since Oct. 19 2005,12:45 < Next Oldest | Next Newest >  

Pages: (38) < [1] 2 3 4 5 6 ... >   


Track this topic Email this topic Print this topic

[ Read the Board Rules ] | [Useful Links] | [Evolving Designs]