line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pugs::Grammar::Base; |
2
|
13
|
|
|
13
|
|
70650
|
use Pugs::Runtime::Match; |
|
13
|
|
|
|
|
38
|
|
|
13
|
|
|
|
|
468
|
|
3
|
13
|
|
|
13
|
|
4474
|
use Pugs::Compiler::RegexPerl5; |
|
13
|
|
|
|
|
31
|
|
|
13
|
|
|
|
|
342
|
|
4
|
13
|
|
|
13
|
|
4359
|
use Pugs::Compiler::Regex; |
|
13
|
|
|
|
|
41
|
|
|
13
|
|
|
|
|
477
|
|
5
|
13
|
|
|
13
|
|
81
|
use Data::Dumper; |
|
13
|
|
|
|
|
26
|
|
|
13
|
|
|
|
|
828
|
|
6
|
13
|
|
|
13
|
|
111
|
use Carp; |
|
13
|
|
|
|
|
30
|
|
|
13
|
|
|
|
|
954
|
|
7
|
|
|
|
|
|
|
|
8
|
13
|
|
|
13
|
|
82
|
use charnames ":full"; # support \c[DIGIT SIX] |
|
13
|
|
|
|
|
27
|
|
|
13
|
|
|
|
|
128
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# This class defines , unicode character classes, etc |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# internal methods - not in spec |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub no_match { |
15
|
0
|
|
|
0
|
0
|
|
my $grammar = shift; |
16
|
0
|
|
0
|
|
|
|
my $pos = $_[1]{p} || 0; |
17
|
0
|
|
|
|
|
|
return Pugs::Runtime::Match->new( { |
18
|
|
|
|
|
|
|
bool => \0, |
19
|
|
|
|
|
|
|
str => \$_[0], |
20
|
|
|
|
|
|
|
match => [], |
21
|
|
|
|
|
|
|
from => \$pos, |
22
|
|
|
|
|
|
|
to => \$pos, |
23
|
|
|
|
|
|
|
capture => undef, |
24
|
|
|
|
|
|
|
} ); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
*fail = \&no_match; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
*any = Pugs::Compiler::RegexPerl5->compile( |
30
|
|
|
|
|
|
|
'\X' |
31
|
|
|
|
|
|
|
)->code; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# <
|
34
|
|
|
|
|
|
|
*_wb_left = Pugs::Compiler::RegexPerl5->compile( |
35
|
|
|
|
|
|
|
'\b(?=\w)' |
36
|
|
|
|
|
|
|
)->code; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# word>> |
39
|
|
|
|
|
|
|
*_wb_right = Pugs::Compiler::RegexPerl5->compile( |
40
|
|
|
|
|
|
|
'(?<=\w)\b' |
41
|
|
|
|
|
|
|
)->code; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=for later - unused |
44
|
|
|
|
|
|
|
# \h |
45
|
|
|
|
|
|
|
*_horizontal_ws = Pugs::Compiler::RegexPerl5->compile( |
46
|
|
|
|
|
|
|
#'XXX - Infinite loop in pugs stdrules.t' . |
47
|
|
|
|
|
|
|
'\x20|\t' |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#'\x0a|\x0b|\x0c|\x0d|\x85' |
50
|
|
|
|
|
|
|
# from regex_tests, plus \t and ' ' |
51
|
|
|
|
|
|
|
)->code; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# \v |
54
|
|
|
|
|
|
|
*_vertical_ws = Pugs::Compiler::RegexPerl5->compile( |
55
|
|
|
|
|
|
|
#'XXX - Infinite loop in pugs stdrules.t' . |
56
|
|
|
|
|
|
|
'[\n\r]' |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#'\x{1680}|\x{180e}|\x{2000}|\x{2001}|\x{2002}|\x{2003}|\x{2004}|\x{2005}|\x{2006}|\x{2007}|\x{2008}|\x{2008}|\x{2009}|\x{200a}|\x{202f}|\x{205f}|\x{3000}' |
59
|
|
|
|
|
|
|
# from regex_tests |
60
|
|
|
|
|
|
|
)->code; |
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# specced methods |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub before { |
66
|
|
|
|
|
|
|
#print "Base->before: ", Dumper(\@_); |
67
|
0
|
|
|
0
|
0
|
|
my $grammar = shift; |
68
|
0
|
|
0
|
|
|
|
my $pos = $_[1]{p} || 0; |
69
|
0
|
|
|
|
|
|
my $arg = $_[1]{positionals}[0]; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# XXX - token or regex? |
72
|
0
|
|
|
|
|
|
my $rule = Pugs::Compiler::Regex->compile( $arg ); |
73
|
0
|
|
|
|
|
|
my $match = $rule->match( $_[0], { pos => $pos } ); |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
return Pugs::Runtime::Match->new( { |
76
|
|
|
|
|
|
|
bool => \( $match ? 1 : 0 ), |
77
|
|
|
|
|
|
|
str => \$_[0], |
78
|
|
|
|
|
|
|
match => [], |
79
|
|
|
|
|
|
|
from => \$pos, |
80
|
|
|
|
|
|
|
to => \$pos, |
81
|
|
|
|
|
|
|
capture => undef, |
82
|
|
|
|
|
|
|
} ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub at { |
86
|
|
|
|
|
|
|
#print "Base->at: ", Dumper(\@_); |
87
|
0
|
|
|
0
|
0
|
|
my $grammar = shift; |
88
|
0
|
|
0
|
|
|
|
my $pos = $_[1]{p} || 0; |
89
|
0
|
|
|
|
|
|
my $arg = $_[1]{positionals}[0]; |
90
|
|
|
|
|
|
|
# print "at: ",Dumper( @_ ); |
91
|
0
|
|
|
|
|
|
return Pugs::Runtime::Match->new( { |
92
|
|
|
|
|
|
|
bool => \( $pos == $arg ), |
93
|
|
|
|
|
|
|
str => \$_[0], |
94
|
|
|
|
|
|
|
match => [], |
95
|
|
|
|
|
|
|
from => \$pos, |
96
|
|
|
|
|
|
|
to => \$pos, |
97
|
|
|
|
|
|
|
capture => undef, |
98
|
|
|
|
|
|
|
} ); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub prior { |
102
|
0
|
0
|
|
0
|
0
|
|
die "Error: is undefined" |
103
|
|
|
|
|
|
|
unless defined $main::_V6_PRIOR_; |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $prior = $main::_V6_PRIOR_; |
106
|
|
|
|
|
|
|
## local $main::_V6_PRIOR_; |
107
|
0
|
|
|
|
|
|
$prior->(@_[0, 1, 2, 2]); # XXX fix parameter list |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
*null = Pugs::Compiler::RegexPerl5->compile( |
111
|
|
|
|
|
|
|
'' |
112
|
|
|
|
|
|
|
)->code; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
*ws = Pugs::Compiler::RegexPerl5->compile( |
115
|
|
|
|
|
|
|
'(?:(?
|
116
|
|
|
|
|
|
|
)->code; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# = word boundary - from regex_tests |
119
|
|
|
|
|
|
|
*wb = Pugs::Compiler::RegexPerl5->compile( |
120
|
|
|
|
|
|
|
'\b' |
121
|
|
|
|
|
|
|
)->code; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
*ident = Pugs::Compiler::RegexPerl5->compile( |
124
|
|
|
|
|
|
|
'[[:alpha:]_][[:alnum:]_]*' |
125
|
|
|
|
|
|
|
)->code; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
*name = Pugs::Compiler::RegexPerl5->compile( |
128
|
|
|
|
|
|
|
# from pugs tests |
129
|
|
|
|
|
|
|
'(?:[[:alpha:]_][[:alnum:]_]*::)*[[:alpha:]_][[:alnum:]_]*' |
130
|
|
|
|
|
|
|
)->code; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
*sp = Pugs::Compiler::RegexPerl5->compile( |
133
|
|
|
|
|
|
|
'\x20' |
134
|
|
|
|
|
|
|
)->code; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
*dot = Pugs::Compiler::RegexPerl5->compile( |
137
|
|
|
|
|
|
|
'\.' |
138
|
|
|
|
|
|
|
)->code; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
*gt = Pugs::Compiler::RegexPerl5->compile( |
141
|
|
|
|
|
|
|
'>' |
142
|
|
|
|
|
|
|
)->code; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
*lt = Pugs::Compiler::RegexPerl5->compile( |
145
|
|
|
|
|
|
|
'<' |
146
|
|
|
|
|
|
|
)->code; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
#BEGIN { |
149
|
|
|
|
|
|
|
# # this list was extracted from 'perlre' |
150
|
|
|
|
|
|
|
# for ( qw( |
151
|
|
|
|
|
|
|
# alpha alnum ascii blank |
152
|
|
|
|
|
|
|
# cntrl digit graph lower |
153
|
|
|
|
|
|
|
# print punct space upper |
154
|
|
|
|
|
|
|
# word xdigit |
155
|
|
|
|
|
|
|
# ) ) { |
156
|
|
|
|
|
|
|
# *{$_} = Pugs::Compiler::RegexPerl5->compile( |
157
|
|
|
|
|
|
|
# "[[:$_:]]" |
158
|
|
|
|
|
|
|
# )->code; |
159
|
|
|
|
|
|
|
# } |
160
|
|
|
|
|
|
|
#} |
161
|
|
|
|
|
|
|
|
162
|
0
|
|
|
0
|
|
|
sub DESTROY { } # avoid autoloading this |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub AUTOLOAD { |
165
|
|
|
|
|
|
|
#my $self = shift; |
166
|
0
|
|
|
0
|
|
|
my $meth = $AUTOLOAD; |
167
|
0
|
|
|
|
|
|
$meth =~ s/.*:://; # strip fully-qualified portion |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
# is it a Unicode property? "isL" |
170
|
|
|
|
|
|
|
{ |
171
|
0
|
|
|
|
|
|
local $@; |
|
0
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
my $p5; |
173
|
0
|
0
|
|
|
|
|
if ( exists $Pugs::Emitter::Rule::Perl5::CharClass::extra_unicode{$meth} ) { |
174
|
0
|
|
|
|
|
|
$p5 = $Pugs::Emitter::Rule::Perl5::CharClass::extra_unicode{$meth}; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
else { |
177
|
0
|
|
|
|
|
|
$p5 = '\p{' . $meth . '}'; |
178
|
0
|
|
|
|
|
|
eval ' my $s="a"; $s =~ /' . $p5 . '/ '; |
179
|
|
|
|
|
|
|
} |
180
|
0
|
0
|
|
|
|
|
unless ( $@ ) { |
181
|
0
|
|
|
|
|
|
*{$meth} = Pugs::Compiler::RegexPerl5->compile($p5)->code; |
|
0
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
return $meth->( @_ ); |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# is it a char class? "digit" |
187
|
|
|
|
|
|
|
{ |
188
|
0
|
|
|
|
|
|
local $@; |
|
0
|
|
|
|
|
|
|
189
|
0
|
|
|
|
|
|
eval ' my $s="a"; $s =~ /[[:' . $meth . ':]]/ '; |
190
|
0
|
0
|
|
|
|
|
unless ( $@ ) { |
191
|
0
|
|
|
|
|
|
*{$meth} = Pugs::Compiler::RegexPerl5->compile( |
|
0
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
'[[:' . $meth . ':]]' |
193
|
|
|
|
|
|
|
)->code; |
194
|
0
|
|
|
|
|
|
return $meth->( @_ ); |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
carp "unknown rule: <$meth>"; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
1; |