File Coverage

blib/lib/Lingua/LinkParser/MatchPath.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package Lingua::LinkParser::MatchPath;
2              
3 1     1   36793 use strict;
  1         2  
  1         38  
4 1     1   702 use Lingua::LinkParser::MatchPath::SM;
  1         3  
  1         32  
5 1     1   558 use Lingua::LinkParser::MatchPath::Lex;
  0            
  0            
6             use Lingua::LinkParser::MatchPath::Parser;
7              
8             our $VERSION = '0.03';
9              
10             my $DEBUG;
11              
12             use fields qw(parser matcher);
13              
14             sub new {
15             my $class = shift;
16             my %arg = @_;
17             if( ! ref $arg{parser} ){
18             require Lingua::LinkParser;
19             $arg{parser} = Lingua::LinkParser->new;
20             }
21             bless { parser => $arg{parser} } => $class;
22             }
23              
24             sub create_matcher($$) {
25             push @{$_[0]->{matcher}}, path_matcher($_[1], $_[0]->{parser});
26             }
27              
28             sub matcher($) { $_[0]->{matcher} }
29              
30             # parenthesize rules and append a semicolon
31             sub _preprocess($) {
32             my $path = shift;
33             $path =~ s/[\s\n]*$//o;
34             $path .= ';' unless $path =~ /;$/;
35             if($path !~ /^\(.+\);$/o){
36             $path =~ s/;$/\);/o;
37             $path = '('.$path;
38             }
39             # print "$path$/";
40             $path
41             }
42              
43             sub path_matcher($$) {
44             my $template = _preprocess shift;
45             my $parser = shift;
46              
47             my $p = new Lingua::LinkParser::MatchPath::Parser;
48             $p->{_sm} = Lingua::LinkParser::MatchPath::SM->new($template);
49              
50             my $l = Lingua::LinkParser::MatchPath::Lex->new( debug => $DEBUG );
51             $l->load($template);
52            
53             $p->YYParse(
54             yylex => sub { $l->lex },
55             yyerror => sub { die "Syntax error in [ $template ]\n" },
56             # yydebug => 0x1F,
57             );
58             $p->{_sm}->{parser} = $parser;
59             $p->{_sm};
60             }
61              
62              
63             1;
64             __END__