| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
=head1 NAME |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
App::Greple::xp - extended pattern module |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 VERSION |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Version 1.01 |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
greple -Mxp |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
This module provides functions those can be used by B pattern |
|
16
|
|
|
|
|
|
|
and region options. |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 OPTIONS |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=over 7 |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=item B<--le-pattern> I |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=item B<--inside-pattern> I |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=item B<--outside-pattern> I |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=item B<--include-pattern> I |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=item B<--exclude-pattern> I |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Read file contents and use each lines as a pattern for options. |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=item B<--le-string> I |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=item B<--inside-string> I |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=item B<--outside-string> I |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=item B<--include-string> I |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=item B<--exclude-string> I |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Almost same as B<*-pattern> option but each line is concidered as a |
|
45
|
|
|
|
|
|
|
fixed string rather than regular expression. |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=back |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 COMMENT |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
You can insert comment lines in pattern file. As for fixed string |
|
52
|
|
|
|
|
|
|
file, there is no way to write comment. |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Lines start with hash mark (C<#>) is ignored as a comment line. |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
String after double slash (C/>) is also ignored with preceding |
|
57
|
|
|
|
|
|
|
spaces. |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 MULTILINE REGEX |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Complex pattern can be written on multiple lines as follows. |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
(?xxn) \ |
|
64
|
|
|
|
|
|
|
( (?\[) | \@ ) # start with "[" or @ \ |
|
65
|
|
|
|
|
|
|
(? [ \d : , ]+) # sequence of digit, ":", or "," \ |
|
66
|
|
|
|
|
|
|
(?() \] | ) # closing "]" if start with "[" \ |
|
67
|
|
|
|
|
|
|
$ # EOL |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 WILD CARD |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Because I parameter is globbed, you can use wild card to give |
|
72
|
|
|
|
|
|
|
multiple files. If nothing matched to the wild card, this option is |
|
73
|
|
|
|
|
|
|
simply ignored with no message. |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
$ greple -Mxp --exclude-pattern '*.exclude' ... |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
L |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
L |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 AUTHOR |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Kazumasa Utashiro |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 LICENSE |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Copyright 2019-2025 Kazumasa Utashiro. |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
92
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
package App::Greple::xp; |
|
98
|
|
|
|
|
|
|
|
|
99
|
7
|
|
|
7
|
|
306404
|
use v5.14; |
|
|
7
|
|
|
|
|
25
|
|
|
100
|
7
|
|
|
7
|
|
36
|
use strict; |
|
|
7
|
|
|
|
|
14
|
|
|
|
7
|
|
|
|
|
222
|
|
|
101
|
7
|
|
|
7
|
|
28
|
use warnings; |
|
|
7
|
|
|
|
|
85
|
|
|
|
7
|
|
|
|
|
747
|
|
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
our $VERSION = "1.01"; |
|
104
|
|
|
|
|
|
|
|
|
105
|
7
|
|
|
7
|
|
86
|
use Exporter 'import'; |
|
|
7
|
|
|
|
|
13
|
|
|
|
7
|
|
|
|
|
424
|
|
|
106
|
|
|
|
|
|
|
our @EXPORT = qw(&xp_pattern_file); |
|
107
|
|
|
|
|
|
|
|
|
108
|
7
|
|
|
7
|
|
599
|
use open IO => ':utf8'; |
|
|
7
|
|
|
|
|
1477
|
|
|
|
7
|
|
|
|
|
67
|
|
|
109
|
7
|
|
|
7
|
|
1704
|
use App::Greple::Common; |
|
|
7
|
|
|
|
|
560
|
|
|
|
7
|
|
|
|
|
638
|
|
|
110
|
7
|
|
|
7
|
|
542
|
use App::Greple::Regions qw(match_regions merge_regions); |
|
|
7
|
|
|
|
|
8948
|
|
|
|
7
|
|
|
|
|
619
|
|
|
111
|
7
|
|
|
7
|
|
45
|
use Data::Dumper; |
|
|
7
|
|
|
|
|
12
|
|
|
|
7
|
|
|
|
|
4784
|
|
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
my @default_opt = ( |
|
114
|
|
|
|
|
|
|
hash_comment => 1, |
|
115
|
|
|
|
|
|
|
slash_comment => 1, |
|
116
|
|
|
|
|
|
|
glob => 1, |
|
117
|
|
|
|
|
|
|
fixed => 0, |
|
118
|
|
|
|
|
|
|
); |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub xp_pattern_file { |
|
121
|
5
|
|
|
5
|
0
|
21316
|
my %opt = (@default_opt, @_); |
|
122
|
5
|
50
|
|
|
|
90
|
my $target = delete $opt{&FILELABEL} or die; |
|
123
|
5
|
|
|
|
|
17
|
my $file = $opt{file}; |
|
124
|
5
|
50
|
|
|
|
354
|
my @files = $opt{glob} ? glob $file : ($file); |
|
125
|
5
|
|
|
|
|
16
|
my @r; |
|
126
|
5
|
|
|
|
|
25
|
for my $file (@files) { |
|
127
|
6
|
50
|
|
|
|
852
|
open my $fh, $file or die "$file: $!"; |
|
128
|
6
|
|
|
|
|
15
|
my @p = map s/\\(?=\R)//gr, split /(? }; |
|
|
6
|
|
|
|
|
38
|
|
|
|
6
|
|
|
|
|
467
|
|
|
129
|
6
|
|
|
|
|
25
|
for my $p (@p) { |
|
130
|
30
|
100
|
66
|
|
|
13627
|
if ($opt{hash_comment} and !$opt{fixed}) { |
|
131
|
20
|
100
|
|
|
|
108
|
next if $p =~ /^\s*#/; |
|
132
|
|
|
|
|
|
|
} |
|
133
|
27
|
100
|
66
|
|
|
105
|
if ($opt{slash_comment} and !$opt{fixed}) { |
|
134
|
17
|
|
|
|
|
114
|
$p =~ s{\s*//.*}{}; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
27
|
50
|
|
|
|
179
|
next unless $p =~ /\S/; |
|
137
|
27
|
100
|
|
|
|
1176
|
my $re = $opt{fixed} ? qr/\Q$p/ : qr/$p/m; |
|
138
|
27
|
|
|
|
|
131
|
push @r, match_regions pattern => $re; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
} |
|
141
|
5
|
|
|
|
|
3120
|
merge_regions @r; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub block_match { |
|
145
|
0
|
|
|
0
|
0
|
|
my $grep = shift; |
|
146
|
|
|
|
|
|
|
$grep->{RESULT} = [ |
|
147
|
|
|
|
|
|
|
[ [ 0, length ], |
|
148
|
|
|
|
|
|
|
map { |
|
149
|
0
|
|
|
|
|
|
[ $_->[0][0], $_->[0][1], 0, $grep->{callback}->[0] ] |
|
|
0
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
} $grep->result |
|
151
|
|
|
|
|
|
|
] ]; |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
1; |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
__DATA__ |