chiark / gitweb /
fixed bug about long spans of character data
authorThomas Thurman <tthurman@gnome.org>
Mon, 15 Mar 2010 00:11:54 +0000 (20:11 -0400)
committerThomas Thurman <tthurman@gnome.org>
Mon, 15 Mar 2010 00:11:54 +0000 (20:11 -0400)
lib/Fury/Parse.pm
source.xml

index c731840..91d44ee 100644 (file)
@@ -21,7 +21,7 @@ sub new {
        leas => Lingua::EN::Alphabet::Shaw->new(),
        quotedepth => 0,
        magicword => undef,
-       magiccontent => undef,
+       textcontent => undef,
        unknownWords => {},
     };
 
@@ -95,6 +95,49 @@ sub checkQuoteDepth {
     }
 }
 
+sub addTextContentToPara {
+
+    my ($self, $lineNumber) = @_;
+
+    return unless defined $self->{'textcontent'};
+
+    my @lines = split(/\n/, $self->{'textcontent'});
+    for my $line (@lines) {
+       my @words = split(/\s+/, $line);
+
+       my @result;
+           
+       for my $word (@words) {
+           next unless $word;
+           my $shaw = $word;
+           
+           $shaw = $self->shavianise_phrase($shaw, $lineNumber) unless $self->{'literal'};
+                   
+           $word =~ s/_[a-z]*//g;
+
+           my $args = 0;
+           if ($self->{'poetry'}) {
+               $args = 1;
+           } else {
+               $args += 1 if $self->{'italics'};
+               $args += 2 if $self->{'literal'};
+           }
+           
+           push @result, [$word, $shaw,
+                          $args];
+       }
+
+       push @{$self->{'para'}}, @result;
+
+       if ($self->{'poetry'}) {
+           push @{$self->{'para'}}, ['LINE', 'LINE', 4];
+       }
+
+    }
+
+    $self->{'textcontent'} = undef;
+}
+
 sub parse {
     my ($self, $filename, $callback) = @_;
 
@@ -106,15 +149,21 @@ sub parse {
            my ($parser, $tag, %attrs) = @_;
 
            if ($tag eq 'i') {
+               $self->addTextContentToPara($parser->current_line());
                $self->{'italics'} = 1;
+               $self->{'textcontent'} = '';
            } elsif ($tag eq 'literal') {
+               $self->addTextContentToPara($parser->current_line());
                $self->{'literal'} = 1;
+               $self->{'textcontent'} = '';
            } elsif ($tag eq 'p') {
                $self->{'para'} = [];
                $self->{'poetry'} = 0;
+               $self->{'textcontent'} = '';
            } elsif ($tag eq 'poetry') {
                $self->{'para'} = [];
                $self->{'poetry'} = 1;
+               $self->{'textcontent'} = '';
            } elsif ($tag eq 'pagebreak') {
                $callback->('PGBK');
            } elsif ($tag eq 'dab') {
@@ -157,7 +206,7 @@ sub parse {
                                         $attrs{'short'});              
            } elsif ($tag eq 'magic') {
                $self->{'magicword'} = $attrs{'word'};
-               $self->{'magiccontent'} = '';
+               $self->{'textcontent'} = '';
            } elsif ($tag eq 'quote') {
                $self->{'quotedepth'} = $attrs{'depth'};
            }
@@ -167,10 +216,15 @@ sub parse {
            my ($parser, $tag) = @_;
 
            if ($tag eq 'i') {
+               $self->addTextContentToPara($parser->current_line());
                $self->{'italics'} = 0;
+               $self->{'textcontent'} = '';
            } elsif ($tag eq 'literal') {
+               $self->addTextContentToPara($parser->current_line());
                $self->{'literal'} = 0;
+               $self->{'textcontent'} = '';
            } elsif ($tag eq 'p') {
+               $self->addTextContentToPara($parser->current_line());
                $skipping = !$callback->('PARA',
                                         $self->{'para'});
                $self->checkQuoteDepth($parser->current_line());
@@ -178,6 +232,7 @@ sub parse {
            } elsif ($tag eq 'poetry') {
                my @temp;
                $self->checkQuoteDepth($parser->current_line());
+               $self->addTextContentToPara($parser->current_line());
                for my $word (@{$self->{'para'}}) {
                    if ($word->[2] == 8) {
                        # Stanza break
@@ -196,14 +251,14 @@ sub parse {
                push @{$self->{'para'}}, ['STANZA', 'STANZA', 8];
                $self->{'quotedepth'} = 0;
            } elsif ($tag eq 'magic') {
-               my $shavian_content = $self->{'magiccontent'};
+               my $shavian_content = $self->{'textcontent'};
                $shavian_content = $self->shavianise_phrase($shavian_content, $parser->current_line);
                $callback->('MAGI',
                            $self->{'magicword'},
-                           $self->{'magiccontent'},
+                           $self->{'textcontent'},
                            $shavian_content);
                $self->{'magicword'} = undef;
-               $self->{'magiccontent'} = undef;
+               $self->{'textcontent'} = undef;
            }
        },
        Char => sub {
@@ -217,45 +272,10 @@ sub parse {
                    $parser->current_line()."\n";
            }
 
-           if (defined $self->{'magiccontent'}) {
-               # <magic/> captures all text
-               $self->{'magiccontent'} .= $text;
+           if (defined $self->{'textcontent'}) {
+               $self->{'textcontent'} .= $text;
                return;
            }
-
-           my @lines = split(/\n/, $text);
-           for my $line (@lines) {
-               my @words = split(/\s+/, $line);
-
-               my @result;
-           
-               for my $word (@words) {
-                   next unless $word;
-                   my $shaw = $word;
-                   
-                   $shaw = $self->shavianise_phrase($shaw, $parser->current_line) unless $self->{'literal'};
-                   
-                   $word =~ s/_[a-z]*//g;
-
-                   my $args = 0;
-                   if ($self->{'poetry'}) {
-                       $args = 1;
-                   } else {
-                       $args += 1 if $self->{'italics'};
-                       $args += 2 if $self->{'literal'};
-                   }
-                   
-                   push @result, [$word, $shaw,
-                                  $args];
-               }
-
-               push @{$self->{'para'}}, @result;
-
-               if ($self->{'poetry'}) {
-                   push @{$self->{'para'}}, ['LINE', 'LINE', 4];
-               }
-
-           }
        },
                            });
 
index 75eb237..338350d 100644 (file)
@@ -195,7 +195,7 @@ With gently smiling jaws!]</stanza></poetry>
 
 <p>[Not like cats!] cried the Mouse, in a shrill, passionate voice. [Would <i>you</i> like cats if you were me?]</p>
 
-<p>[Well, perhaps not,] said Alice in a soothing tone: [don't be angry about it. And yet I wish I could show you our cat Dinah: I think you'd take a fancy to cats if you could only see her. She is such a dear quiet thing,] Alice went on, half to herself, as she swam lazily about in the pool, [and she sits purring so nicely by the fire, licking her paws and washing her face—and she is such a nice soft thing to nurse—and she's such a capital one for catching mice—oh, I beg your pardon!] cried Alice again, for this time the Mouse was bristling all over, and she felt certain it must be <fixme/>really offended. [We won't talk about her any more if you'd rather not.]</p>
+<p>[Well, perhaps not,] said Alice in a soothing tone: [don't be angry about it. And yet I wish I could show you our cat Dinah: I think you'd take a fancy to cats if you could only see her. She is such a dear quiet thing,] Alice went on, half to herself, as she swam lazily about in the pool, [and she sits purring so nicely by the fire, licking her paws and washing her face—and she is such a nice soft thing to nurse—and she's such a capital one for catching mice—oh, I beg your pardon!] cried Alice again, for this time the Mouse was bristling all over, and she felt certain it must be really offended. [We won't talk about her any more if you'd rather not.]</p>
 
 <p>[We indeed!] cried the Mouse, who was trembling down to the end of his tail. [As if I would talk on such a subject_n! Our family always <i>hated</i> cats: nasty, low, vulgar things! Don't let me hear the name again!]</p>
 
@@ -326,11 +326,11 @@ death.]++</magic><img src="thimble.jpg" align="top"/><pagebreak/>
 
 <p>[I had <i>not!]</i> cried the Mouse, sharply and very angrily.</p>
 
-<p>[A knot!] said Alice, <fixme/>always ready to make herself useful, and looking anxiously about her. [Oh, do let me help to undo it!]</p>
+<p>[A knot!] said Alice, always ready to make herself useful, and looking anxiously about her. [Oh, do let me help to undo it!]</p>
 
 <p>[I shall do nothing of the sort,] said the Mouse, getting up and walking away. [You insult me by talking such nonsense!]</p>
 
-<p>[I didn't mean it!] pleaded poor Alice. <fixme/>[But you're so easily offended, you know!]</p>
+<p>[I didn't mean it!] pleaded poor Alice. [But you're so easily offended, you know!]</p>
 
 <p>The Mouse only growled in reply.</p>