[Lxr-commits] CVS: lxr/lib/LXR/Lang Generic.pm, 1.39, 1.40 Java.pm, 1.9, 1.10 Perl.pm, 1.11, 1.12 P
Brought to you by:
ajlittoz
From: Andre-Littoz <ajl...@us...> - 2013-03-11 16:11:46
|
Update of /cvsroot/lxr/lxr/lib/LXR/Lang In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv19685/lib/LXR/Lang Modified Files: Generic.pm Java.pm Perl.pm Python.pm Ruby.pm Log Message: Generic.pm, Java.pm, Perl.pm, Python.pm, Ruby.pm: fix include file processing Fix for bug #231 (Java parser enters infinite loop when scanning "import static ..."): add optional static keyword in regexp for splitting include fragment. While fixing this bug, a patch was needed on the "multi-directory path" handling because the trigger test was incorrect (testing for definedness on $link instead of an existing <a> HTML tag). This fix is intended for 1.1.0->1.1.1 release, but the include feature will be rearchitectured for 1.2.0 because readability is poor. Index: Generic.pm =================================================================== RCS file: /cvsroot/lxr/lxr/lib/LXR/Lang/Generic.pm,v retrieving revision 1.39 retrieving revision 1.40 diff -u -d -r1.39 -r1.40 --- Generic.pm 21 Sep 2012 17:07:17 -0000 1.39 +++ Generic.pm 11 Mar 2013 16:11:42 -0000 1.40 @@ -372,6 +372,7 @@ my $m; # matching pattern my $s; # substitution string my $link; # link to include file + my $tail; # lower-lever links after current $link my $identdef = $self->langinfo('identdef'); my $incspec = $self->langinfo('include'); @@ -461,18 +462,31 @@ $path = $file; $rsep = $6 . $9; } - $link = &LXR::Common::incref($file, "include" ,$path ,$dir); - if (defined($link)) { - while ($file =~ m!/!) { - $link =~ s!^([^>]+>)([^/]*/)+?([^/<]+<)!$1$3!; - $file =~ s!/[^/]*$!!; + $link = &LXR::Common::incref($file, "include", $path, $dir); + if (!defined($link)) { + $tail = $file if $path !~ m!/!; + } + # incref above did not return a link to the file. + # Explore however the path to see if directories are + # known along the way. + while ( $path =~ m!/! + && substr($link, 0, 1) ne '<' + ) { + $file =~ s!(/[^/]*)$!!; # BUG: incorrect if sparator not / + $tail = $1 . $tail; + $path =~ s!/[^/]+$!!; + $link = &LXR::Common::incdirref($file, "include", $path, $dir); + } + # A known directory (at least) has been found. + # Build links to higher path elements + if (substr($link, 0, 1) eq '<') { + while ($path =~ m!/!) { + $link =~ s!^([^>]+>)([^/]*/)+?([^/<]+<)!$1$3!; # BUG: incorrect if sparator not / + $tail = '/' . $link . $tail; + $file =~ s!/[^/]*$!!; # BUG: incorrect if sparator not / $path =~ s!/[^/]+$!!; - $link = &LXR::Common::incdirref($file, "include", $path, $dir) - . "/" - . $link ; + $link = &LXR::Common::incdirref($file, "include", $path, $dir); } - } else { - $link = $file; } # Rescan the tail for more "code" constructs @@ -485,6 +499,7 @@ ) . $spacer . $lsep . $link + . $tail . $rsep } Index: Java.pm =================================================================== RCS file: /cvsroot/lxr/lxr/lib/LXR/Lang/Java.pm,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- Java.pm 21 Nov 2012 15:08:48 -0000 1.9 +++ Java.pm 11 Mar 2013 16:11:42 -0000 1.10 @@ -66,7 +66,7 @@ # "import java.awt.classname" by providing links to the # package and the class elsif ($source =~ s/^ - (import\s+) + (import\s+(?:static\s+)?) ([\w.]+) # package 'path' \.(\*|\w+) # class or * //sx) { @@ -88,10 +88,7 @@ # Assemble the highlighted bits $$frag = "<span class='reserved'>$dirname</span>" - . ( defined($link) - ? $link - : $file - ); + . $link; } sub _packagelinks { @@ -99,18 +96,34 @@ my $link = &LXR::Common::incdirref ($file, "include", $path, $dir); - if (defined($link)) { + # Now iteratively pop the last part of the path to + # build direct links to the corresponding sub-directory. + my $tail; + + # Part 1: there is not yet a link in the path, + # try to find a known directory. + while ( $file =~ m!\.! + && substr($link, 0, 1) ne '<' + ) { + $file =~ s!(\.[^.]*)$!!; + $tail = $1 . $tail; + $path =~ s!/[^/]+$!!; + $link = &LXR::Common::incdirref($file, "include", $path, $dir); + } + + # Part 2: the path leads to a known file/directory, + # build now links to higher path elements. + if (substr($link, 0, 1) eq '<') { while ($file=~m!\.!) { $link =~ s!^([^>]+>)([^.]*\.)+?([^.<]+<)!$1$3!; + $tail = '.' . $link . $tail; $file =~ s!\.[^.]*$!!; $path =~ s!/[^/]+$!!; $link = &LXR::Common::incdirref($file, "include", $path, $dir) - . "." - . $link ; } - } else { - $link = $file; } + + $link .= $tail; return $link; } Index: Perl.pm =================================================================== RCS file: /cvsroot/lxr/lxr/lib/LXR/Lang/Perl.pm,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- Perl.pm 21 Nov 2012 15:08:48 -0000 1.11 +++ Perl.pm 11 Mar 2013 16:11:43 -0000 1.12 @@ -73,6 +73,7 @@ my $file; # language include file my $path; # OS include file my $link; # link to include file + my $tail; # lower-lever links after current $link # Faster surrogate for 'directive' if ($source =~ s/^ # reminder: no initial space in the grammar @@ -92,18 +93,30 @@ # Create the hyperlinks $link = &LXR::Common::incref($file, "include", $path, $dir); - if (defined($link)) { + if (!defined($link)) { + $tail = $file if $path !~ m!/!; + } + # incref above did not return a link to the file. + # Explore however the path to see if directories are + # known along the way. + while ( $file =~ m!::! + && substr($link, 0, 1) ne '<' + ) { + $file =~ s!(::[^:]*)$!!; + $tail = $1 . $tail; + $path =~ s!/[^/]+$!!; + $link = &LXR::Common::incdirref($file, "include", $path, $dir); + } + if (substr($link, 0, 1) eq '<') { while ($file =~ m!::!) { $link =~ s!^([^>]+>)([^:]*::)+!$1!; + $tail = '::' . $link . $tail; $file =~ s!::[^:]*$!!; $path =~ s!/[^/]+$!!; - $link = &LXR::Common::incdirref($file, "include" ,$path ,$dir) - . "::" - . $link ; + $link = &LXR::Common::incdirref($file, "include" ,$path ,$dir); } - } else { - $link = $file; } + $link .= $tail; } elsif ($source =~ s/^ # reminder: no initial space in the grammar ([\w]+ # reserved keyword for include construct \s+) # and space in same capture @@ -121,19 +134,27 @@ # Create the hyperlinks $link = &LXR::Common::incref($file, "include", $path, $dir); - if (defined($link)) { + if (!defined($link)) { + $tail = $file if $path !~ m!/!; + } + while ( $file =~ m!/! + && substr($link, 0, 1) ne '<' + ) { + $file =~ s!(/[^/]*)$!!; + $tail = $1 . $tail; + $path =~ s!/[^/]+$!!; + $link = &LXR::Common::incdirref($file, "include", $path, $dir); + } + if (substr($link, 0, 1) eq '<') { while ($file =~ m!/!) { $link =~ s!^([^>]+>)([^/]*/)+!$1!; + $tail = '/' . $link . $tail; $file =~ s!/[^/]*$!!; $path =~ s!/[^/]+$!!; - $link = &LXR::Common::incdirref($file, "include" ,$path ,$dir) - . "/" - . $link ; + $link = &LXR::Common::incdirref($file, "include" ,$path ,$dir); } - } else { - $link = $file; } - $link = $delim . $link . $delim; + $link = $delim . $link . $tail . $delim; } else { # Guard against syntax error or variant # Advance past keyword, so that parsing may continue without loop. Index: Python.pm =================================================================== RCS file: /cvsroot/lxr/lxr/lib/LXR/Lang/Python.pm,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Python.pm 21 Nov 2012 15:08:48 -0000 1.7 +++ Python.pm 11 Mar 2013 16:11:43 -0000 1.8 @@ -24,7 +24,7 @@ =head1 Perl language module -This module is the Perl language highlighting engine. +This module is the Python language highlighting engine. It shares most of its methods with I<Generic.pm>. It only overrides C<processinclude> for efficiency. @@ -73,6 +73,7 @@ my $file; # language include file my $path; # OS include file my $link; # link to include file + my $tail; # lower-lever links after current $link # Faster surrogate for 'directive' if ($source !~ s/^ # reminder: no initial space in the grammar @@ -114,23 +115,32 @@ # Erase last path separator from <a> link to enable # following partial path processing. # NOTE: this creates a dependency of link structure from incref! - if (substr($link, 0, 3) eq '<a ') { + if (substr($link, 0, 1) eq '<') { $link =~ s!/">!">!; - } else { - $link = undef; } } - if (defined($link)) { + while ( $file =~ m!\.! + && substr($link, 0, 1) ne '<' + ) { + $file =~ s!(\.[^.]*)$!!; + $tail = $1 . $tail; + $path =~ s!/[^/]+$!!; + $link = &LXR::Common::incdirref($file, "include", $path, $dir); + } + if (substr($link, 0, 1) eq '<') { while ($file =~ m!\.!) { $link =~ s!^([^>]+>)([^.]*\.)+?([^.<]+<)!$1$3!; + $tail = '.' . $link . $tail; $file =~ s!\.[^.]*$!!; $path =~ s!/[^/]+$!!; - $link = &LXR::Common::incdirref($file, "include", $path, $dir) - . "." - . $link ; + $link = &LXR::Common::incdirref ( $file, "include", $path, $dir) } } else { - $link = join('.', map {$self->processcode(\$_)} split(/\./, $file)); + $link = join ( '.' + , map {$self->processcode(\$_)} + split(/\./, $link.$tail) + ); + $tail = ''; } # As a goodie, rescan the tail of import/from for Python code @@ -138,10 +148,8 @@ # Assemble the highlighted bits $$frag = "<span class='reserved'>$dirname</span>" - . ( defined($link) - ? $link - : $file - ); + . $link + . $tail; } 1; Index: Ruby.pm =================================================================== RCS file: /cvsroot/lxr/lxr/lib/LXR/Lang/Ruby.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- Ruby.pm 17 Sep 2012 12:15:43 -0000 1.2 +++ Ruby.pm 11 Mar 2013 16:11:43 -0000 1.3 @@ -43,6 +43,7 @@ my $lsep; # left separator my $rsep; # right separator my $link; # link to include file + my $tail; # lower-lever links after current $link my $identdef = $self->langinfo('identdef'); if ($source =~ s/^ # Parse instruction @@ -69,24 +70,47 @@ $path =~ s@(?<!\.rb)$@.rb@; $link = &LXR::Common::incref($file, "include" ,$path ,$dir); - if (defined($link)) { - while ($file =~ m!/!) { - $link =~ s!^([^>]+>)([^/]*/)+!$1!g; + if (!defined($link)) { + $tail = $file if $path !~ m!/!; + } + while ( $file =~ m!/! + && substr($link, 0, 1) ne '<' + ) { + $file =~ s!(/[^/]*)$!!; + $tail = $1 . $tail; + $path =~ s!/[^/]+$!!; + $link = &LXR::Common::incdirref($file, "include", $path, $dir); + } + if (substr($link, 0, 1) eq '<') { + while ($path =~ m!/!) { + $link =~ s!^([^>]+>)([^/]*/)+?!$1!; + $tail = '/' . $link . $tail; $file =~ s!/[^/]*$!!; $path =~ s!/[^/]+$!!; - $link = &LXR::Common::incdirref($file, "include", $path, $dir) - . "/" - . $link ; + $link = &LXR::Common::incdirref($file, "include", $path, $dir); } - } else { - $link = $file; } +# if (defined($link)) { +# while ($file =~ m!/!) { +# $link =~ s!^([^>]+>)([^/]*/)+!$1!g; +# $file =~ s!/[^/]*$!!; +# $path =~ s!/[^/]+$!!; +# $link = &LXR::Common::incdirref($file, "include", $path, $dir) +# . "/" +# . $link ; +# } +# } else { +# $link = $file; +# } + # Rescan the unused part of the source line + &LXR::SimpleParse::requeuefrag($source); + $$frag = "<span class='reserved'>$dirname</span>" . $spacer . $lsep . $link - . $rsep - . $source; + . $tail + . $rsep; } 1; |