Perform/AttributeGrammar.pm untested

filter: Statementstmt 0.0% 0 / 23 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 29 CC 1 SCAR 6.9
CC
1
Cov
0%
get_grammar
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package DBIx::Perform::AttributeGrammar;
2  
3 use strict;
4 use Parse::RecDescent;
5 use base 'Exporter';
6 use Data::Dumper;
7  
8 our $VERSION = '0.695';
9  
10 # exported methods
11 our @EXPORT_OK = qw( &get_grammar );
12  
13 # Enable warnings within the Parse::RecDescent module.
14  
15 $::RD_ERRORS = 1; # Make sure the parser dies when it encounters an error
16 $::RD_WARN = 1; # Enable warnings. This will warn on unused rules &c.
17 $::RD_HINT = 1; # Give out hints to help fix problems.
18  
19 $::Lindex = 0;
20 $::Jindex = 0;
21 $::Index = 0;
22 #$::Verify_Join = undef;
23 $::Verify_Lookup_Join = undef;
24  
25 our $grammar = <<'_EOGRAMMAR_';
26  
27 OP : m([-+*/%]) # Mathematical operators
28 QUOTE : /"/ | /'/ # Quoted string
29 INTEGER : /[-+]?\d+/ # Signed integers
30 DOUBLE : /[-+]?\d+\.\d+/ # Signed doubles
31 ALPHANUM : /\w-?\w*/ # Unquoted alphanumberic characters
32 NAME_STRING : /\w+/i # Limited complexity strings for names
33 GENERIC_STRING : /[\.a-zA-Z0-9\*\-\_\(\)\$\/\[\]\#\@\&\!\+\=\%\>\<\,\;\:\ \'\\]*/i
34 QSTRING : /"((^|[^\\])(\\\\)*\\"|[^"])*"/
35 BSTRING : /[^"),\s][^),\s]*/
36 FORMAT_STRING : /[\#\.\/\-\$\&mdyMDY]*/i
37  
38 empty_tag : ''
39 {
40 $::Lindex = 0;
41 $::Jindex = 0;
42 $::res = undef;
43 $::res->{field_tag} = "EMPTY_FIELD_TAG";
44 }
45  
46 field_tag : NAME_STRING
47 {
48 $::Lindex = 0;
49 $::Jindex = 0;
50 $::res = undef;
51 $::res->{field_tag} = lc $item{NAME_STRING};
52 }
53  
54 table_name : NAME_STRING
55 {
56 $::res->{table_name} = lc $item{NAME_STRING};
57 }
58 |
59 {
60 $::res->{table_name} = "EMPTY_TABLE_NAME";
61 }
62  
63 column_name : NAME_STRING
64 {
65 $::res->{column_name} = lc $item{NAME_STRING};
66 }
67  
68 lookup_tag : NAME_STRING
69  
70 lookup_table : NAME_STRING
71  
72 lookup_column : NAME_STRING
73  
74 join_table : NAME_STRING
75  
76 join_column : NAME_STRING
77  
78 field_join_table : NAME_STRING
79  
80 field_join_column : NAME_STRING
81  
82 verify_lookup_join : "*"
83 {
84 $::Verify_Lookup_Join = 1;
85 }
86 |
87  
88 verify_field : "*"
89 {
90 $::res->{VERIFY} = 1;
91 }
92 |
93  
94 numeric_value: DOUBLE
95 | INTEGER
96  
97 data_type : /CHARACTER/i
98 | /CHAR/i
99 | /SMALLINT/i
100 | /INTEGER/i
101 | /INT/i
102 | /SERIAL/i
103 | /DECIMAL/i
104 | /DEC/i
105 | /NUMERIC/i
106 | /MONEY/i
107 | /SMALLFLOAT/i
108 | /REAL/i
109 | /FLOAT/i
110 | /DATETIME/i
111 | /DATE/i
112 | /INTERVAL/i
113  
114 include_string : QSTRING
115 {
116 $item{QSTRING} =~ /^"(.*)"$/;
117 $::res->{INCLUDE_VALUES}->{$1} = 1;
118 }
119  
120 range_floor : QSTRING
121 | BSTRING
122  
123 range_ceiling : QSTRING
124 | BSTRING
125  
126 subscript_floor : numeric_value
127  
128 subscript_ceiling : numeric_value
129  
130 null_rule : /(,\s*)?NULL(\s*,)?/i { $::res->{INCLUDE_NULL_OK} = 1; }
131 |
132  
133 range_statement : null_rule range_floor /TO/i range_ceiling null_rule
134 {
135 $::res->{RANGE}->{$item{range_floor}}
136 = $item{range_ceiling};
137 }
138  
139 comment_spec : "," /COMMENTS/i "=" QSTRING
140 {
141 ($::res->{COMMENTS}) = $item{QSTRING} =~ /^"(.*)"$/;
142 }
143
144 default_spec : "," /DEFAULT/i "=" QSTRING
145 {
146 ($::res->{DEFAULT}) = $item{QSTRING} =~ /^"(.*)"$/;
147 }
148 | "," /DEFAULT/i "=" numeric_value
149 {
150 $::res->{DEFAULT} = $item{numeric_value};
151 }
152 | "," /DEFAULT/i "=" ALPHANUM
153 {
154 $::res->{DEFAULT} = uc $item{ALPHANUM};
155 }
156  
157 format_spec : "," /FORMAT/i "=" QUOTE FORMAT_STRING QUOTE
158 {
159 $::res->{FORMAT} = uc $item{FORMAT_STRING};
160 }
161  
162 include_item : range_statement
163 | include_string
164  
165 include_list : include_item "," include_list
166 | include_item
167  
168 include_spec : "," /INCLUDE/i "=" "(" include_list ")"
169  
170 joining_spec : /JOINING/i join_table "." join_column
171 {
172 $::res->{LOOKUP_HASH}->{$::Lindex}->{$::Tag}->{join_table} = lc $item{join_table};
173 $::res->{LOOKUP_HASH}->{$::Lindex}->{$::Tag}->{join_column} = lc $item{join_column};
174 }
175 | /JOINING/i verify_lookup_join join_table "." join_column
176 {
177 $::res->{LOOKUP_HASH}->{$::Lindex}->{$::Tag}->{join_table} = lc $item{join_table};
178 $::res->{LOOKUP_HASH}->{$::Lindex}->{$::Tag}->{join_column} = lc $item{join_column};
179 $::res->{LOOKUP_HASH}->{$::Lindex}->{$::Tag}->{verify} = $::Verify_Lookup_Join;
180 }
181  
182 lookup_assignment : lookup_tag "=" lookup_table "." lookup_column
183 {
184 $::Tag = lc $item{lookup_tag};
185 $::Jindex++ if ! defined $::res->{LOOKUP_HASH}->{$::Lindex}->{$::Tag};
186 $::res->{LOOKUP_HASH}->{$::Lindex}->{$::Tag}->{table_name} = lc $item{lookup_table};
187 $::res->{LOOKUP_HASH}->{$::Lindex}->{$::Tag}->{column_name} = lc $item{lookup_column};
188 $::res->{LOOKUP_HASH}->{$::Lindex}->{$::Tag}->{join_index} = $::Jindex;
189 }
190 | lookup_tag "=" lookup_column
191 {
192 $::Tag = lc $item{lookup_tag};
193 $::Jindex++ if ! defined $::res->{LOOKUP_HASH}->{$::Lindex}->{$::Tag};
194 $::res->{LOOKUP_HASH}->{$::Lindex}->{$::Tag}->{table_name} = "EMPTY_TABLE_NAME";
195 $::res->{LOOKUP_HASH}->{$::Lindex}->{$::Tag}->{column_name} = lc $item{lookup_column};
196 $::res->{LOOKUP_HASH}->{$::Lindex}->{$::Tag}->{join_index} = $::Jindex;
197 }
198  
199 repeat_lookup_assignment : lookup_assignment "," repeat_lookup_assignment
200 | lookup_assignment
201  
202 lookup_spec : "," /LOOKUP/i repeat_lookup_assignment joining_spec
203 {
204 $::Lindex++;
205 }
206  
207 picture_spec : "," /PICTURE/i "=" QUOTE GENERIC_STRING QUOTE
208 {
209 $::res->{PICTURE} = $item{GENERIC_STRING};
210 }
211  
212 wordwrap_spec : "," /WORDWRAP/i
213 {
214 $::res->{WORDWRAP} = 1;
215 }
216 | "," /WORDWRAP/i /COMPRESS/i
217 {
218 $::res->{WORDWRAP} = 1;
219 $::res->{COMPRESS} = 1;
220 }
221  
222 attr_spec : "," /AUTONEXT/i { $::res->{uc $item[2]} = 1; }
223 | "," /DOWNSHIFT/i { $::res->{uc $item[2]} = 1; }
224 | "," /INVISIBLE/i { $::res->{uc $item[2]} = 1; }
225 | "," /NOENTRY/i { $::res->{uc $item[2]} = 1; }
226 | "," /NOUPDATE/i { $::res->{uc $item[2]} = 1; }
227 | "," /QUERYCLEAR/i { $::res->{uc $item[2]} = 1; }
228 | "," /REVERSE/i { $::res->{uc $item[2]} = 1; }
229 | "," /RIGHT/i { $::res->{uc $item[2]} = 1; }
230 | "," /REQUIRED/i { $::res->{uc $item[2]} = 1; }
231 | "," /UPSHIFT/i { $::res->{uc $item[2]} = 1; }
232 | "," /ZEROFILL/i { $::res->{uc $item[2]} = 1; }
233 | comment_spec
234 | default_spec
235 | format_spec
236 | include_spec
237 | picture_spec
238 | wordwrap_spec
239 | lookup_spec
240
241 repeat_attr_spec : attr_spec repeat_attr_spec
242  
243 subscript_field_description : "[" subscript_floor "," subscript_ceiling "]"
244 {
245 $::res->{SUBSCRIPT_FLOOR} = $item{subscript_floor};
246 $::res->{SUBSCRIPT_CEILING} = $item{subscript_ceiling};
247 }
248  
249 displayonly_type : /TYPE/i data_type
250 {
251 $::res->{data_type} = uc $item{data_type};
252 }
253  
254 displayonly_options : /ALLOWING/i /INPUT/i displayonly_type /NOT/i /NULL/i
255 {
256 $::res->{ALLOWING_INPUT} = 1;
257 $::res->{NOTNULL} = 1;
258 }
259 | displayonly_type /NOT/i /NULL/i
260 {
261 $::res->{NOTNULL} = 1;
262 }
263 | /ALLOWING/i /INPUT/i displayonly_type
264 {
265 $::res->{ALLOWING_INPUT} = 1;
266 }
267 | displayonly_type
268  
269 displayonly_field : /DISPLAYONLY/i displayonly_options repeat_attr_spec
270 {
271 $::res->{DISPLAYONLY} = 1;
272 }
273 | /DISPLAYONLY/i displayonly_options
274 {
275 $::res->{DISPLAYONLY} = 1;
276 }
277 | /DISPLAYONLY/i
278 {
279 $::res->{DISPLAYONLY} = 1;
280 }
281  
282 field_desc : "=" verify_field field_join_table "." field_join_column
283 {
284 $::res->{FIELD_TAG_JOIN_HASH}->{$::Index}->{join_table} = lc $item{field_join_table};
285 $::res->{FIELD_TAG_JOIN_HASH}->{$::Index}->{join_column} = lc $item{field_join_column};
286  
287 $::Index++;
288 }
289  
290 repeat_field_desc : field_desc repeat_field_desc
291 | field_desc
292 |
293  
294 field_description_list : repeat_field_desc repeat_attr_spec
295 {
296 $::Index = 0;
297 }
298 |
299 {
300 $::Index = 0;
301 }
302  
303 attrs : field_tag "=" verify_field displayonly_field
304 {
305 return $::res;
306 }
307 | field_tag "=" verify_field table_name "." column_name subscript_field_description field_description_list
308 {
309 return $::res;
310 }
311 | field_tag "=" verify_field table_name "." column_name field_description_list
312 {
313 return $::res;
314 }
315 | empty_tag "=" verify_field table_name "." column_name field_description_list
316 {
317 return $::res;
318 }
319 | field_tag "=" verify_field column_name subscript_field_description field_description_list
320 {
321 return $::res;
322 }
323 | field_tag "=" verify_field column_name field_description_list
324 {
325 return $::res;
326 }
327  
328 startrule : attrs(s /;/)
329  
330 _EOGRAMMAR_
331  
332 # methods
333  
334 sub get_grammar {
335 return $grammar;
336 }
337  
338 1;