Skip to content

Commit

Permalink
XML start block comment on line w/code #811
Browse files Browse the repository at this point in the history
  • Loading branch information
AlDanial committed Feb 17, 2024
1 parent 4ddc10a commit b2a3851
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 8 deletions.
20 changes: 16 additions & 4 deletions Unix/cloc
Original file line number Diff line number Diff line change
Expand Up @@ -7160,6 +7160,7 @@ sub remove_matches { # {{{1
$pattern , # in Perl regular expression (case insensitive)
) = @_;
print "-> remove_matches(pattern=$pattern)\n" if $opt_v > 2;
print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4;

my @save_lines = ();
foreach (@{$ra_lines}) {
Expand All @@ -7171,6 +7172,7 @@ sub remove_matches { # {{{1
push @save_lines, $_;
}

print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4;
print "<- remove_matches\n" if $opt_v > 2;
#print "remove_matches returning\n ", join("\n ", @save_lines), "\n";
return @save_lines;
Expand All @@ -7181,6 +7183,7 @@ sub remove_matches_2re { # {{{1
$pattern2, # in Perl regex 2 (case insensitive) to not match prev line
) = @_;
print "-> remove_matches_2re(pattern=$pattern1,$pattern2)\n" if $opt_v > 2;
print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4;

my @save_lines = ();
for (my $i = 0; $i < scalar @{$ra_lines}; $i++) {
Expand All @@ -7197,6 +7200,7 @@ sub remove_matches_2re { # {{{1
push @save_lines, $ra_lines->[$i];
}

print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4;
print "<- remove_matches_2re\n" if $opt_v > 2;
#print "remove_matches_2re returning\n ", join("\n ", @save_lines), "\n";
return @save_lines;
Expand Down Expand Up @@ -7308,6 +7312,7 @@ sub remove_between { # {{{1
# '{}' '()' '[]' or '<>'

print "-> remove_between(marker=$marker)\n" if $opt_v > 2;
print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4;
my %acceptable = ('{}'=>1, '()'=>1, '[]'=>1, '<>'=>1, );
die "remove_between: invalid delimiter '$marker'\n",
"the delimiter must be one of these four pairs:\n",
Expand All @@ -7326,6 +7331,7 @@ sub remove_between { # {{{1
$all_lines =~ s/$1//g;
}

print "[", join("]\n[", split(/\n/, $all_lines)), "]\n" if $opt_v > 4;
print "<- remove_between\n" if $opt_v > 2;
return split("\n", $all_lines);
} # 1}}}
Expand All @@ -7337,6 +7343,7 @@ sub rm_comments_in_strings { # {{{1
print "-> rm_comments_in_strings(string_marker=$string_marker, " .
"start_comment=$start_comment, end_comment=$end_comment)\n"
if $opt_v > 2;
print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4;

my @save_lines = ();
my $in_ml_string = 0;
Expand Down Expand Up @@ -7407,6 +7414,7 @@ sub rm_comments_in_strings { # {{{1
push @save_lines, $new_line;
}

print "[", join("]\n[", @save_lines), "]\n" if $opt_v > 4;
print "<- rm_comments_in_strings\n" if $opt_v > 2;
return @save_lines;
} # 1}}}
Expand Down Expand Up @@ -7539,7 +7547,7 @@ sub replace_between_regex { # {{{1
push @save_lines, $_;
}

print "[", join("][", @{$ra_lines}), "]\n" if $opt_v > 4;
print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4;
print "<- replace_between_regex\n" if $opt_v > 2;
return @save_lines;
} # 1}}}
Expand Down Expand Up @@ -7656,7 +7664,11 @@ sub remove_html_comments { # {{{1
}
next if /^\s*$/;
$in_comment = 1 if /^(.*?)<!\-\-/;
next if defined $1 and $1 =~ /^\s*$/;
if (defined $1 and $1 !~ /^\s*$/) {
# has both code and comment
push @save_lines, "$1\n";
next;
}
next if ($in_comment);
push @save_lines, $_;
}
Expand Down Expand Up @@ -7937,7 +7949,7 @@ sub docstring_rm_comments { # {{{1
}
}

print "[", join("][", @{$ra_lines}), "]\n" if $opt_v > 4;
print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4;
print "<- docstring_rm_comments\n" if $opt_v > 2;
return @{$ra_lines};
} # 1}}}
Expand Down Expand Up @@ -11514,7 +11526,7 @@ sub call_regexp_common { # {{{1
# a bogus use of %RE to avoid:
# Name "main::RE" used only once: possible typo at cloc line xx.
print scalar keys %RE if $opt_v < -20;
print "[", join("][", @{$ra_lines}), "]\n" if $opt_v > 4;
print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4;
print "<- call_regexp_common\n" if $opt_v > 2;
return split("\n", $all_lines);
} # 1}}}
Expand Down
7 changes: 7 additions & 0 deletions Unix/t/01_opts.t
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,13 @@ my @Tests = (
'ref' => '../tests/outputs/issues/806/results.yaml',
},

{
'name' => 'XML start block comment on line w/code #811',
'cd' => '../tests/inputs/issues/811',
'args' => 'inline_comment.xml',
'ref' => '../tests/outputs/issues/811/inline_comment.xml.yaml',
},

);

# Special cases:
Expand Down
21 changes: 17 additions & 4 deletions cloc
Original file line number Diff line number Diff line change
Expand Up @@ -7175,6 +7175,7 @@ sub remove_matches { # {{{1
$pattern , # in Perl regular expression (case insensitive)
) = @_;
print "-> remove_matches(pattern=$pattern)\n" if $opt_v > 2;
print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4;

my @save_lines = ();
foreach (@{$ra_lines}) {
Expand All @@ -7186,6 +7187,7 @@ sub remove_matches { # {{{1
push @save_lines, $_;
}

print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4;
print "<- remove_matches\n" if $opt_v > 2;
#print "remove_matches returning\n ", join("\n ", @save_lines), "\n";
return @save_lines;
Expand All @@ -7196,6 +7198,7 @@ sub remove_matches_2re { # {{{1
$pattern2, # in Perl regex 2 (case insensitive) to not match prev line
) = @_;
print "-> remove_matches_2re(pattern=$pattern1,$pattern2)\n" if $opt_v > 2;
print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4;

my @save_lines = ();
for (my $i = 0; $i < scalar @{$ra_lines}; $i++) {
Expand All @@ -7212,6 +7215,7 @@ sub remove_matches_2re { # {{{1
push @save_lines, $ra_lines->[$i];
}

print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4;
print "<- remove_matches_2re\n" if $opt_v > 2;
#print "remove_matches_2re returning\n ", join("\n ", @save_lines), "\n";
return @save_lines;
Expand Down Expand Up @@ -7323,6 +7327,7 @@ sub remove_between { # {{{1
# '{}' '()' '[]' or '<>'

print "-> remove_between(marker=$marker)\n" if $opt_v > 2;
print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4;
my %acceptable = ('{}'=>1, '()'=>1, '[]'=>1, '<>'=>1, );
die "remove_between: invalid delimiter '$marker'\n",
"the delimiter must be one of these four pairs:\n",
Expand All @@ -7341,6 +7346,7 @@ sub remove_between { # {{{1
$all_lines =~ s/$1//g;
}

print "[", join("]\n[", split(/\n/, $all_lines)), "]\n" if $opt_v > 4;
print "<- remove_between\n" if $opt_v > 2;
return split("\n", $all_lines);
} # 1}}}
Expand All @@ -7352,6 +7358,7 @@ sub rm_comments_in_strings { # {{{1
print "-> rm_comments_in_strings(string_marker=$string_marker, " .
"start_comment=$start_comment, end_comment=$end_comment)\n"
if $opt_v > 2;
print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4;

my @save_lines = ();
my $in_ml_string = 0;
Expand Down Expand Up @@ -7422,6 +7429,7 @@ sub rm_comments_in_strings { # {{{1
push @save_lines, $new_line;
}

print "[", join("]\n[", @save_lines), "]\n" if $opt_v > 4;
print "<- rm_comments_in_strings\n" if $opt_v > 2;
return @save_lines;
} # 1}}}
Expand Down Expand Up @@ -7554,7 +7562,7 @@ sub replace_between_regex { # {{{1
push @save_lines, $_;
}

print "[", join("][", @{$ra_lines}), "]\n" if $opt_v > 4;
print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4;
print "<- replace_between_regex\n" if $opt_v > 2;
return @save_lines;
} # 1}}}
Expand Down Expand Up @@ -7671,7 +7679,11 @@ sub remove_html_comments { # {{{1
}
next if /^\s*$/;
$in_comment = 1 if /^(.*?)<!\-\-/;
next if defined $1 and $1 =~ /^\s*$/;
if (defined $1 and $1 !~ /^\s*$/) {
# has both code and comment
push @save_lines, "$1\n";
next;
}
next if ($in_comment);
push @save_lines, $_;
}
Expand Down Expand Up @@ -7952,7 +7964,7 @@ sub docstring_rm_comments { # {{{1
}
}

print "[", join("][", @{$ra_lines}), "]\n" if $opt_v > 4;
print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4;
print "<- docstring_rm_comments\n" if $opt_v > 2;
return @{$ra_lines};
} # 1}}}
Expand Down Expand Up @@ -8543,6 +8555,7 @@ sub set_constants { # {{{1
'jsf' => 'JavaServer Faces' ,
'jsx' => 'JSX' ,
'xhtml' => 'XHTML' ,
'j2' => 'Jinja Template' ,
'jinja' => 'Jinja Template' ,
'jinja2' => 'Jinja Template' ,
'yyp' => 'JSON' ,
Expand Down Expand Up @@ -11528,7 +11541,7 @@ sub call_regexp_common { # {{{1
# a bogus use of %RE to avoid:
# Name "main::RE" used only once: possible typo at cloc line xx.
print scalar keys %RE if $opt_v < -20;
print "[", join("][", @{$ra_lines}), "]\n" if $opt_v > 4;
print "[", join("]\n[", @{$ra_lines}), "]\n" if $opt_v > 4;
print "<- call_regexp_common\n" if $opt_v > 2;
return split("\n", $all_lines);
} # 1}}}
Expand Down
6 changes: 6 additions & 0 deletions tests/inputs/issues/811/inline_comment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<foo>
<bar/><!-- bar
is not
foo -->
</foo>
21 changes: 21 additions & 0 deletions tests/outputs/issues/811/inline_comment.xml.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
# github.com/AlDanial/cloc
header :
cloc_url : github.com/AlDanial/cloc
cloc_version : 1.99
elapsed_seconds : 0.00256609916687012
n_files : 1
n_lines : 6
files_per_second : 389.696553005668
lines_per_second : 2338.17931803401
report_file : ../../../outputs/issues/811/inline_comment.xml.yaml
'XML' :
nFiles: 1
blank: 0
comment: 2
code: 4
SUM:
blank: 0
comment: 2
code: 4
nFiles: 1

0 comments on commit b2a3851

Please sign in to comment.