Commits

shl...@52c325ad-5fd0-0310-8a0f-c43feede02cc  committed af713b7

Moved _generate_tag_event to the base class and extracted it from Screenplay.

  • Participants
  • Parent commits 8a08d5f

Comments (0)

Files changed (3)

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

     return qr{(?:\<|^\n?$)}ms;
 }
 
-sub _generate_tag_event
-{
-    my $self = shift;
-
-    my $l = $self->curr_line_ref();
-    my $orig_pos = pos($$l);
-
-    if (my ($tag_opener) = $$l =~ m{\G(<(?:/)?)}cg)
-    {
-        # If it's a tag.
-
-        # TODO : implement the comment handling.
-        # We have a tag.
-
-        my $is_closing_tag = $tag_opener =~ m{/};
-
-        pos($$l) = $orig_pos;
-
-        $self->_enqueue_event(
-            {'type' => ($is_closing_tag ? "close" : "open")}
-        );
-
-        return 1;
-    }
-    else
-    {
-        return;
-    }
-}
-
 sub _generate_text_unit_events
 {
     my $self = shift;

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

     return \@ret;
 }
 
+sub _look_for_tag_opener
+{
+    my $self = shift;
+
+    my $l = $self->curr_line_ref();
+
+    if ($$l =~ m{\G(\&|<(?:/)?)}cg)
+    {
+        return $1;
+    }
+    else
+    {
+        return;
+    }
+}
+
+sub _is_closing_tag { 
+    my $self = shift;
+    my $tag_start = shift;
+
+    return $tag_start =~ m{/};
+}
+
+sub _generate_tag_event
+{
+    my $self = shift;
+
+    my $l = $self->curr_line_ref();
+    my $orig_pos = pos($$l);
+
+    if (defined(my $tag_start = $self->_look_for_tag_opener()))
+    {
+        # If it's a tag.
+
+        # TODO : implement the comment handling.
+        # We have a tag.
+
+        pos($$l) = $orig_pos;
+
+        if ($$l =~ m{\G\&})
+        {
+            if ($$l !~ m{\G(\&\w+;)}g)
+            {
+                Carp::confess("Cannot match entity (e.g: \"&quot;\") at line " .
+                    $self->line_num()
+                );
+            }
+
+            my $entity = $1;
+
+            $self->_enqueue_event(
+                {
+                    type => "elem",
+                    elem => $self->_new_text(
+                        [HTML::Entities::decode_entities($entity)]
+                    ),
+                },
+            );
+
+            return;
+        }
+
+        $self->_enqueue_event(
+            {'type' => ($self->_is_closing_tag($tag_start) ? "close" : "open")}
+        );
+
+        return 1;
+    }
+    else
+    {
+        return;
+    }
+}
+
 sub _flush_ret_tag
 {
     my $self = shift;

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

     }
 };
 
+sub _look_for_tag_opener
+{
+    my $self = shift;
+
+    my $l = $self->curr_line_ref();
+
+    if ($$l =~ m{\G([<\[\]\&])})
+    {
+        return $1;
+    }
+    else
+    {
+        return;
+    }
+}
+
+
+sub _is_closing_tag { 
+    my $self = shift;
+    my $tag_start = shift;
+
+    return (${$self->curr_line_ref()} =~ m{\G(</|\])});
+}
+
+
 sub _generate_text_unit_events
 {
     my $self = shift;
     
     # $self->skip_multiline_space();
 
-    my $l = $self->curr_line_ref();
-    if ($$l =~ m{\G[<\[\]\&]})
+    if (! $self->_generate_tag_event())
     {
-        # If it's a tag.
-
-        # TODO : implement the comment handling.
-        # We have a tag.
-
-        # If it's an entity, then parse it.
-        if ($$l =~ m{\G\&})
-        {
-            if ($$l !~ m{\G(\&\w+;)}g)
-            {
-                Carp::confess("Cannot match entity (e.g: \"&quot;\") at line " .
-                    $self->line_num()
-                );
-            }
-
-            my $entity = $1;
-
-            $self->_enqueue_event(
-                {
-                    type => "elem",
-                    elem => $self->_new_text(
-                        [HTML::Entities::decode_entities($entity)]
-                    ),
-                },
-            );
-
-            return;
-        }
-        # If it's a closing tag - then backtrack.
-        if ($$l =~ m{\G(</|\])})
-        {
-            $self->_enqueue_event({'type' => "close"});
-            return;
-        }
-        else
-        {
-            $self->_enqueue_event({'type' => "open"});
-            return;
-        }
-    }
-    else
-    {
-
         my $status = $self->_parse_non_tag_text_unit();
 
         if (!defined($status))