FLAT/Regex/Parser.pm

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