Commits

Anonymous committed ac1318c

Refactoring: extracted _generate_tag_event.

Comments (0)

Files changed (1)

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

     }
 }
 
+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;
 
     my $space = $self->_consume(qr{\s});
 
-    my $l = $self->_curr_line_ref();
-    my $orig_pos = pos($$l);
-
-    if ($$l =~ m{\G<}cg)
+    if (! $self->_generate_tag_event())
     {
-        # If it's a tag.
-
-        # TODO : implement the comment handling.
-        # We have a tag.
-
-        my $is_closing_tag = ($$l =~ m{\G/}cg);
-        pos($$l) = $orig_pos;
-
-        # If it's a closing tag - then backtrack.
-        if ($is_closing_tag)
-        {
-            $self->_enqueue_event({'type' => "close"});
-            return;
-        }
-        else
-        {
-            $self->_enqueue_event({'type' => "open"});
-            return;
-        }
-    }
-    else
-    {
+        my $l = $self->_curr_line_ref();
+        my $orig_pos = pos($$l);
+        
         my $is_para = (pos($$l) == 0);
 
         my $status = $self->_parse_non_tag_text_unit();
             $self->_enqueue_event({ type => "close", tag => "para" });
             $in_para = 0;
         }
-        return;
     }
+    return;
 }
 
 sub _curr_line_matches
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.