FLAT/Regex/Parser.pm

filter: Statementstmt 100% 28 / 28 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 97.0% 33 / 34 SCAR 6.9
CC
2
Cov
100%
new
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.0
« FLAT/DFA/Minimal.pm ↑ Summary FLAT/Transition.pm »
1 package FLAT::Regex::Parser;
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 #### Is this one level of abstraction too far? Parser generator generators..
5  
6 #### TODO: try YAPP, since recursive descent is SLOOOW
7 6 ▶use Parse::RecDescent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use FLAT::Regex::Op;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 ▶use vars '$CHAR';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 $CHAR = qr{ [A-Za-z0-9_\$\#] | \[[^\]]*\] }x;
12  
13 sub new {
14 12 ▶ my $pkg = shift;
Subroutine new: called CC=2 SCAR=6.9
Pod undocumented
15 60 my @ops = sort {$a->{prec} <=> $b->{prec}}
16 map {
17 12 {
18 48 pkg => "FLAT::Regex::Op::$_",
19 prec => "FLAT::Regex::Op::$_"->precedence,
20 spec => "FLAT::Regex::Op::$_"->parse_spec,
21 short => $_
22 }
23 } @_;
24  
25 12 my $lowest = shift @ops;
26 12 my $grammar = qq!
27 parse:
28 $lowest->{short} /^\\Z/ { \$item[1] }
29 !;
30  
31 12 my $prev = $lowest;
32 12 for (@ops) {
33 36 my $spec = sprintf $prev->{spec}, $_->{short};
34  
35 36 $grammar .= qq!
36 $prev->{short}:
37 $spec { $prev->{pkg}\->from_parse(\@item) }
38 | $_->{short} { \$item[1] }
39 !;
40  
41 36 $prev = $_;
42 }
43  
44 12 my $spec = sprintf $prev->{spec}, "atomic";
45 12 $grammar .= qq!
46 $prev->{short}:
47 $spec { $prev->{pkg}\->from_parse(\@item) }
48 | atomic { \$item[1] }
49  
50 atomic:
51 "(" $lowest->{short} ")" { \$item[2] }
52 | /\$FLAT::Regex::Parser::CHAR/
53 { FLAT::Regex::Op::atomic->from_parse(\@item) }
54 !;
55  
56 12 Parse::RecDescent->new($grammar);
57 }
58  
59 6 1;
60  
61 __END__
« FLAT/DFA/Minimal.pm ↑ Summary FLAT/Transition.pm »