Skip to content

Commit 7bdbe0e

Browse files
committed
Add another Perl heuristic for // when separated from preceding punc. by LF
1 parent 460b7d7 commit 7bdbe0e

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

src/org/opensolaris/opengrok/analysis/perl/PerlXref.lex

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ import org.opensolaris.opengrok.web.Util;
111111
char opc = ltpostop.charAt(0);
112112
setEndQuoteChar(opc);
113113
setState(ltpostop, nointerp);
114-
//return htmlize(boundary + opname) + Ss + htmlize(postop);
115114

116115
if (doWrite) {
117116
out.write(htmlize(boundary));
@@ -260,6 +259,22 @@ import org.opensolaris.opengrok.web.Util;
260259
return trimmed.equals(hereTerminator);
261260
}
262261

262+
// Splits `capture' on {EOL} and sets value1 to the left-side and value2 to
263+
// the right-side, dropping the {EOL}.
264+
void splitEol(String capture)
265+
{
266+
int i;
267+
if ((i = capture.indexOf("\n")) == -1) {
268+
value1 = capture;
269+
value2 = "";
270+
return;
271+
}
272+
value1 = capture.substring(0, i);
273+
if (value1.endsWith("\r"))
274+
value1 = value1.substring(0, value1.length() - 1);
275+
value2 = capture.substring(i + 1);
276+
}
277+
263278
final static String Sc = "<span class=\"c\">";
264279
final static String Sn = "<span class=\"n\">";
265280
final static String Ss = "<span class=\"s\">";
@@ -358,6 +373,9 @@ Mwords_2 = ("if" | "unless" | "or" | "and" | "not")
358373
Mwords_3 = ("split")
359374
Mwords = ({Mwords_1} | {Mwords_2} | {Mwords_3})
360375

376+
Mpunc1YYIN = [\(\!]
377+
Mpunc2IN = ([!=]"~" | [\:\?\=\+\-\<\>] | "=="|"!="|"<="|">="|"<=>"|"&&" | "||")
378+
361379
//
362380
// There are two dimensions to quoting: "link"-or-not and "interpolate"-or-not.
363381
// Unfortunately, we cannot control the %state values, so we have to declare
@@ -508,16 +526,26 @@ Mwords = ({Mwords_1} | {Mwords_2} | {Mwords_3})
508526
// first slash cannot always be distinguished from division (/) without
509527
// true parsing.
510528

511-
[\(\!] {MaybeWhsp} "/" { hqop(yytext()); }
529+
{Mpunc1YYIN} {MaybeWhsp} "/" { hqop(yytext()); }
530+
531+
{Mpunc1YYIN} {MaybeWhsp}{EOL}{MaybeWhsp} "/" {
532+
splitEol(yytext());
533+
out.write(htmlize(value1));
534+
startNewLine();
535+
hqop(value2);
536+
}
512537
}
513538

514539
<INTRA> {
515540
// Continue with more punctuation heuristics
516541

517-
[!=]"~" {MaybeWhsp} "/" |
518-
[\:\?\=\+\-\<\>] {MaybeWhsp} "/" |
519-
("==" | "!=" | "<=" | ">=" | "<=>" | "&&" | "||") {MaybeWhsp} "/" {
520-
hqop(yytext());
542+
{Mpunc2IN} {MaybeWhsp} "/" { hqop(yytext()); }
543+
544+
{Mpunc2IN} {MaybeWhsp}{EOL}{MaybeWhsp} "/" {
545+
splitEol(yytext());
546+
out.write(htmlize(value1));
547+
startNewLine();
548+
hqop(value2);
521549
}
522550
}
523551

testdata/sources/perl/main.pl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ ($)
152152
if (0 || /pP \"\'\(\)\<\>\{\}\[\]\/\# et $var./) { print; }
153153
print if /pP \"\'\(\)\<\>\{\}\[\]\/\# et $var./;
154154
155+
my @o = $contents =~
156+
/^(?>\S+) \s* := \s* LINKSRC \s* = \s* \S+/mxg;
157+
foreach my $v (@o) { # This loop shouldn't mistakenly be inside the previous m//
158+
print $v;
159+
}
160+
155161
#
156162
# The following table is from
157163
# https://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators .

0 commit comments

Comments
 (0)