Commits

Anonymous committed c8456a5

Refactoring: extract LineIterator::at_line_start from many places.

  • Participants
  • Parent commits 6ea675b

Comments (0)

Files changed (4)

perl/modules/XML-Grammar-Fiction/lib/XML/Grammar/Fiction/FromProto/Parser/QnD.pm

 {
     my $self = shift;
 
-    my $is_para = ($self->curr_pos() == 0);
+    my $is_para = $self->at_line_start;
 
     my $status = $self->_parse_non_tag_text_unit();
 

perl/modules/XML-Grammar-Fiction/lib/XML/Grammar/FictionBase/FromProto/Parser/LineIterator.pm

     return pos(${$self->curr_line_ref()});
 }
 
+=head2 $self->at_line_start()
+
+Returns if at start of line (curr_pos == 0).
+
+=cut
+
+sub at_line_start
+{
+    my $self = shift;
+
+    return ($self->curr_pos == 0);
+}
+
 =head2 my ($line_ref, $pos) = $self->curr_line_and_pos();
 
 Convenience method to return the line reference and the position.

perl/modules/XML-Grammar-Fiction/lib/XML/Grammar/FictionBase/FromProto/Parser/XmlIterator.pm

 
     # Demote the cursor to before the < of the tag.
     #
-    if (pos($$l) > 0)
+    if ($self->at_line_start)
+    {
+        $is_para_end = 1;
+    }
+    else
     {
         pos($$l)--;
         if (substr($$l, pos($$l), 1) eq "\n")
             $is_para_end = 1;
         }
     }
-    else
-    {
-        $is_para_end = 1;
-    }
-    
+
     if ($text !~ /\S/)
     {
         return;

perl/modules/XML-Grammar-Fiction/lib/XML/Grammar/Screenplay/FromProto/Parser/QnD.pm

 
     my $l = $self->curr_line_ref();
 
-    my $is_start = ($self->curr_pos() == 0);
+    my $is_start = $self->at_line_start;
 
     if ($$l =~ m{\G\[}cg)
     {
 
     return
     (
-           (pos($$l) == 0) 
+        $self->at_line_start()
         && (! $self->_top_is_desc())
         && ($$l =~ m{\A[^\[<][^:]*:})
     );
     my $elem = $status->{'elem'};
     my $is_para_end = $status->{'para_end'};
     my $is_saying = $elem->isa("XML::Grammar::Fiction::FromProto::Node::Saying");
-    #my $is_para =
-    #    (($self->curr_pos() == 0) && 
-    #     (${$self->curr_line_ref()} =~ m{\G\n?\z})
-    #    );
-    # Trying out this one:
     my $is_para = $elem->isa("XML::Grammar::Fiction::FromProto::Node::Paragraph");
 
     my $in_para = $self->_in_para();