File Coverage

lib/Lingua/YaTeA/ParsingPatternParser.yp
Criterion Covered Total %
statement 78 94 82.9
branch 26 30 86.6
condition 3 3 100.0
subroutine 16 28 57.1
pod 0 1 0.0
total 123 156 78.8


line stmt bran cond sub pod time code
1             #
2             # ParsingPatternParser.yp
3             #
4             # used to generate Lingua::YaTeA::ParsingPatternParser.pm
5             #
6             # Use: yapp -m 'Lingua::YaTeA::ParsingPatternParser' -o lib/Lingua/YaTeA/ParsingPatternParser.pm lib/Lingua/YaTeA/ParsingPatternParser.yp
7             #
8             # Parse::Yapp input grammar for parsing the yatea PArsint patterns
9             #
10             #
11             #
12             %{
13 5     5   1185 use Lingua::YaTeA;
  5         9  
  5         42  
14             # use Data::Dumper;
15 5     5   126 use warnings;
  5         73  
  5         7984  
16              
17             my $node_set;
18             my $level = 0;
19             my $node;
20             my @uncomplete;
21             my @parse;
22             my $edge;
23             my $num_content_words;
24             my @pos_sequence;
25             my $priority;
26             my $direction;
27             my $pos_sequence;
28             my $pattern;
29             my $parse;
30             my $num_line = 1;
31             %}
32             %%
33             input: #empty
34 4     672 0 13 | input line { # print STDERR "INPUT $_[1] \n";
        4      
35 4 50       14 }
36             ;
37              
38 392     392   11307 line: '\n' { $_[1] }
39             | parsingpattern '\n' {
40             # print STDERR "=>$_[1]\n";
41              
42 280     280   8640 $pos_sequence = join(" ",@pos_sequence);
43 280         520 $parse = join(" ",@parse);
44             # print STDERR "parse = $parse\n";
45 280         639 $node_set->setRoot;
46 280         756 $pattern = Lingua::YaTeA::ParsingPattern->new($parse,$pos_sequence,$node_set,$priority,$direction,$num_content_words,$num_line);
47            
48 280         501 $_[0]->YYData->{PPRS}->addPattern($pattern);
49 280         440 @pos_sequence = ();
50 280         309 @uncomplete = ();
51 280         366 @parse = ();
52 280         300 $level = 0;
53 280         455 $_[0]->YYData->{PPRS}->checkContentWords($num_content_words,$num_line);
54              
55 280 100       430 if ($num_content_words > $Lingua::YaTeA::ParsingPatternRecordSet::max_content_words)
56             {
57 8         13 $Lingua::YaTeA::ParsingPatternRecordSet::max_content_words = $num_content_words;
58             }
59 280         279 $num_content_words = 0;
60 280         399 $num_line++;
61             }
62 0     0   0 | error '\n' { $_[0]->YYErrok }
63             ;
64              
65             parsingpattern: { # print STDERR "START\n";
66              
67 280     280   5822 $node_set = Lingua::YaTeA::NodeSet->new;
68              
69             } OPEN pattern END priority direction
70 0     0   0 | error 'parsingpattern' { $_[0]->YYErrok }
71             ;
72              
73              
74             pattern: CANDIDATE PREP DET CANDIDATE
75             | CANDIDATE PREP CANDIDATE
76             | CANDIDATE PREP PREP CANDIDATE
77             | CANDIDATE DET CANDIDATE
78             | CANDIDATE CANDIDATE
79 0     0   0 | error '\nnew_pattern: ' { $_[0]->YYErrok }
80             ;
81              
82             OPEN: OPEN_TAG {# print STDERR "OPEN $_[1]\n";
83              
84 300 100   300   12285 if ($level == 0)
85             {
86 280         625 $node = Lingua::YaTeA::RootNode->new($level);
87             }
88             else
89             {
90 20         105 $node = Lingua::YaTeA::InternalNode->new($level);
91             }
92 300         646 $node_set->addNode($node);
93 300         435 push @uncomplete, $node;
94 300         344 $level++;
95 300         616 push @parse, $_[1];
96             }
97 0     0   0 | error '\nOPEN: ' { $_[0]->YYErrok }
98             ;
99              
100             CANDIDATE: CANDIDATE_TAG POSITION_TAG {
101             # print STDERR "CANDIDATE $_[1] $_[2]\n";
102              
103 580     580   19228 $edge = Lingua::YaTeA::PatternLeaf->new($_[1],$node);
104 580         1325 $node->addEdge($edge,$_[2]);
105 580         582 $num_content_words++;
106 580         781 push @pos_sequence,$_[1];
107 580         1217 push @parse, "$_[1]<=$_[2]>";
108              
109             }
110             | OPEN pattern CLOSE
111 0     0   0 | error '\nCANDIDATE: ' { $_[0]->YYErrok }
112             ;
113              
114             PREP: PREP_TAG {# print STDERR "PREP $_[1]\n";
115 108     108   3194 $node->{"PREP"} = $_[1];
116 108         175 push @pos_sequence, $_[1];
117 108         163 push @parse, $_[1];
118             }
119 0     0   0 | error '\nPREP: ' { $_[0]->YYErrok }
120             ;
121              
122              
123             DET: DET_TAG {# print STDERR "DET $_[1]\n";
124 52     52   1510 $node->{"DET"} = $_[1];
125 52         66 push @pos_sequence, $_[1];
126 52         83 push @parse, $_[1];
127             }
128 0     0   0 | error '\nDET: ' { $_[0]->YYErrok }
129             ;
130              
131             CLOSE: CLOSE_TAG {# print STDERR "CLOSE_TAG $_[1]\n";
132 20     20   616 pop @uncomplete;
133 20         81 $node->linkToFather(\@uncomplete,$_[1]);
134 20         29 $node = $uncomplete[$#uncomplete];
135 20         26 $level--;
136 20         38 push @parse, ')';
137             }
138 0     0   0 | error '\nCLOSE: ' { $_[0]->YYErrok }
139             ;
140              
141             END: END_TAG {# print STDERR "END $_[1]\n";
142 280     280   8146 push @parse, $_[1];
143 280         405 $_[1];
144             }
145 0     0   0 | error '\nEND: ' { $_[0]->YYErrok };
146              
147             priority: PRIORITY_TAG {# print STDERR "PRIORITY\n";
148 280     280   8320 $priority = $_[1];
149             }
150 0     0   0 | error '\npriority: ' { $_[0]->YYErrok }
151             ;
152              
153             direction: DIRECTION_TAG {# print STDERR "DIRECTION $_[1]\n";
154 280     280   8118 $direction = $_[1];
155             }
156 0     0   0 | error '\ndirection: ' { $_[0]->YYErrok }
157 4         570 ;
158              
159             %%
160 4         286  
161              
162              
163             sub _Error {
164             exists $_[0]->YYData->{ERRMSG}
165 0 0   0   0 and do {
166 0         0 print $_[0]->YYData->{ERRMSG};
167 0         0 delete $_[0]->YYData->{ERRMSG};
168 0         0 return;
169             };
170 0         0 print "Syntax error.\n";
171             }
172              
173             sub _Lexer {
174 3156     3156   67503 my($parser)=shift;
175              
176 3156         4724 my $fh = $parser->YYData->{FH};
177              
178 3156         13394 my $open = '(\()';
179 3156         3892 my $det = $parser->YYData->{DETERMINERS};
180 3156         13687 my $prep = $parser->YYData->{PREPOSITIONS};
181 3156         13269 my $candidates = $parser->YYData->{CANDIDATES};
182 3156         12205 my $positions = '<=(([MH])||(C[12]))>';
183 3156         2910 my $close = '\)<=(([MH])||(C[12]))>';
184 3156         2801 my $end = '(\))\t+';
185 3156         2837 my $priority = '([0-9]+)\t+';
186 3156         2754 my $direction = '((LEFT)|(RIGHT))';
187              
188              
189             $parser->YYData->{INPUT}
190             or $parser->YYData->{INPUT} = <$fh>
191 3156 100 100     3803 or return('',undef);
192              
193 3152         20128 $parser->YYData->{INPUT}=~s/^[ \t]*#.*//;
194 3152         15452 $parser->YYData->{INPUT}=~s/^[ \t]*//;
195              
196              
197              
198 3152         19872 for ($parser->YYData->{INPUT}) {
199 3152 100       19441 s/^$open\s*// and return ('OPEN_TAG', $1);
200 2852 100       9464 s/^$candidates\s*// and return('CANDIDATE_TAG', $1);
201 2272 100       4829 s/^$prep// and return('PREP_TAG', $1);
202 2164 100       3970 s/^$det// and return('DET_TAG', $1);
203 2112 100       6301 s/^$positions\s*// and return('POSITION_TAG', $1);
204 1532 100       2835 s/^$close// and return('CLOSE_TAG', $1);
205 1512 100       3757 s/^$end// and return('END_TAG', $1);
206 1232 100       3488 s/^$priority// and return('PRIORITY_TAG', $1);
207 952 100       2748 s/^$direction// and return('DIRECTION_TAG', $1);
208 672 50       3361 s/^(.)//s and return($1,$1);
209            
210             }
211             }
212              
213             # sub Run {
214             # my($self)=shift;
215             # $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error );
216             # }
217              
218             # my($parsingpattern)=new ParsingPatternParser;
219             # $parsingpattern->Run;
220              
221              
222             __END__