Revision: 61268
          http://sourceforge.net/p/brlcad/code/61268
Author:   tbrowder2
Date:     2014-06-12 13:34:32 +0000 (Thu, 12 Jun 2014)
Log Message:
-----------
start refactoring conversion code back into its own subroutine; put regexes in 
their own module

Modified Paths:
--------------
    brlcad/branches/d-binding/misc/d-bindings/HObj.pm

Added Paths:
-----------
    brlcad/branches/d-binding/misc/d-bindings/R.pm

Modified: brlcad/branches/d-binding/misc/d-bindings/HObj.pm
===================================================================
--- brlcad/branches/d-binding/misc/d-bindings/HObj.pm   2014-06-12 13:27:49 UTC 
(rev 61267)
+++ brlcad/branches/d-binding/misc/d-bindings/HObj.pm   2014-06-12 13:34:32 UTC 
(rev 61268)
@@ -138,7 +138,9 @@
 sub c_to_d {
   my $self = shift @_;
 
-  # process pretty_d lines as a group, insert back into pretty_d lines
+  # process input pretty_d lines as a group, insert back into pretty_d
+  # lines
+
   my $daref = $self->pretty_d();
 
   # use a tmp array copy
@@ -350,48 +352,13 @@
   # now tidy up a bit, and convert to D where necessary
   my @arr2 = ();
 
-  # some regexes
-  my $r_first_line
-    = qr{\A \s*
-        (typedef)?            # capture $1
-        \s*
-        (struct|enum|union)?  # capture $2
-
-        ([\s\S]*)             # capture $3
-
-        (\{)                  # capture $4
-
-        \s* \z
-      }ox;
-
-  my $r_only_line
-    = qr{\A \s*
-        (typedef)            # capture $1
-
-        ([\s\S]*)            # capture $2
-
-        (;)                  # capture $3
-
-        \s* \z
-      }ox;
-
-  my $r_last_line
-    = qr{\A \s*
-        (\})                     # capture $1
-
-        ([\S\s]*)                # capture $2
-
-        (\;)                     # capture $3
-
-        \s* \z
-      }ox;
-
   # for D only use: hold parts from first (or only) and last lines
   my %fline = ();
   my %oline = ();
   my %lline = ();
 
   my $nl = @arr;
+
  LINE:
   for (my $i = 0; $i < $nl; ++$i) {
     my $line = $arr[$i];
@@ -420,7 +387,7 @@
       # (if it is '{')
 
       # possibilities for the ENTIRE line:
-      if ($line =~ m{$r_first_line}) {
+      if ($line =~ m{$R::r_first_line}) {
        if ($G::debug) {
          F::debug_regex("first line match: '$line'",
                         ($1, $2, $3, $4));
@@ -441,7 +408,7 @@
        # we don't save the line
        next LINE;
       }
-      elsif ($line =~ m{$r_only_line}) {
+      elsif ($line =~ m{$R::r_only_line}) {
        if ($G::debug) {
          F::debug_regex("only line match: '$line'",
                         ($1, $2, $3));
@@ -485,7 +452,7 @@
     elsif ($i == $nl - 1 && $ptyp eq 'd') {
       # last line
       # possibilities for the ENTIRE line:
-      if ($line =~ m{$r_last_line}) {
+      if ($line =~ m{$R::r_last_line}) {
        if ($G::debug) {
          F::debug_regex("last line match: '$line'",
                         ($1, $2, $3));
@@ -517,56 +484,40 @@
       if ($line =~ /\S/);
   }
 
+  # and save the mess
+  if ($ptyp eq 'c') {
+    # this is C code
+    $self->pretty_c(\@arr2);
+  }
+  elsif ($ptyp eq 'd') {
+    # this is D code
+    $self->pretty_d(\@arr2);
+    # a little inefficient, but cleaner to do seprately
+    $self->c_to_d();
+  }
+
   # have we any D conversions?
   my $nF = (keys %fline);
   my $nO = (keys %oline);
   my $nL = (keys %lline);
   if ($nO) {
 
-    # update objetc status
+    # update object status
     $self->converted(1);
   }
   elsif ($nF && $nL) {
 
-    # update objetc status
+    # update object status
     $self->converted(1);
   }
   elsif ($nF || $nL) {
     die "FATAL:  Unexpected first or last line without the other."
   }
 
-=pod
+  if ($ptyp eq 'd') {
 
-  # extract the "name" of any typedef
-  if ($self->type() eq 'typedef') {
-    my $nl = @arr2;
-    my $line = $arr2[$nl-1];
-    $line =~ s{;}{ ; }g;
-    my @d = split ' ', $line;
-    my $end = pop @d;
-    if ($end ne ';') {
-      say "FATAL:  last typedef line: '$line'";
-      die "   Line not ended with semicolon."
-    }
-    # the name, if any, should be the next to last token
-    my $name = pop @d;
-    if ($name ne '}') {
-      $self->name2($name);
-    }
   }
 
-=cut
-
-  # and save the mess
-  if ($ptyp eq 'c') {
-    # this is C code
-    $self->pretty_c(\@arr2);
-  }
-  elsif ($ptyp eq 'd') {
-    # this is D code
-    $self->pretty_d(\@arr2);
-  }
-
 =pod
 
   say "DEBUG: dumping \@arr array AFTER cleanup:";

Added: brlcad/branches/d-binding/misc/d-bindings/R.pm
===================================================================
--- brlcad/branches/d-binding/misc/d-bindings/R.pm                              
(rev 0)
+++ brlcad/branches/d-binding/misc/d-bindings/R.pm      2014-06-12 13:34:32 UTC 
(rev 61268)
@@ -0,0 +1,44 @@
+pachage R;
+
+use v5.14;
+
+# holds varous regexes
+
+# regexes for HObj use:
+our $r_first_line
+  = qr{\A \s*
+       (typedef)?            # capture $1
+       \s*
+       (struct|enum|union)?  # capture $2
+
+       ([\s\S]*)             # capture $3
+
+       (\{)                  # capture $4
+
+       \s* \z
+    }ox;
+
+our $r_only_line
+  = qr{\A \s*
+       (typedef)            # capture $1
+
+       ([\s\S]*)            # capture $2
+
+       (;)                  # capture $3
+
+       \s* \z
+    }ox;
+
+our $r_last_line
+  = qr{\A \s*
+       (\})                     # capture $1
+
+       ([\S\s]*)                # capture $2
+
+       (\;)                     # capture $3
+
+       \s* \z
+    }ox;
+
+# mandatory true return for a Perl module
+1;


Property changes on: brlcad/branches/d-binding/misc/d-bindings/R.pm
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
Find What Matters Most in Your Big Data with HPCC Systems
Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
Leverages Graph Analysis for Fast Processing & Easy Data Exploration
http://p.sf.net/sfu/hpccsystems
_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to