~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to lib/GenTest/Generator/FromGrammar.pm

protection against broken grammar rules that always produce broken queries

Show diffs side-by-side

added added

removed removed

Lines of Context:
210
210
                if (ref($sentence[$pos]) eq 'GenTest::Grammar::Rule') {
211
211
                        splice (@sentence, $pos, 1 , map {
212
212
 
 
213
                                $rule_counters{$_}++ if $_ ne uc($_);
 
214
 
 
215
                                if ($rule_counters{$_} > GENERATOR_MAX_OCCURRENCES) {
 
216
                                        say("Rule $_ occured more than ".GENERATOR_MAX_OCCURRENCES()." times. Possible endless loop in grammar. Aborting.");
 
217
                                        return undef;
 
218
                                }
 
219
 
213
220
                                # Check if we just picked a grammar rule. If yes, then return its Rule object.  
214
221
                                # If not, use the original literal, stored in $_
215
222
 
216
223
                                if (exists $grammar_rules->{$_}) {
217
 
                                        $rule_counters{$_}++;
218
 
                                        if ($rule_counters{$_} > GENERATOR_MAX_OCCURRENCES) {
219
 
                                                say("Rule $_ occured more than ".GENERATOR_MAX_OCCURRENCES()." times. Possible endless loop in grammar. Aborting.");
220
 
                                                return undef;
221
 
                                        } else {
222
 
                                                $grammar_rules->{$_};
223
 
                                        }
 
224
                                        $grammar_rules->{$_};
224
225
                                } else {
225
226
                                        $_;
226
227
                                }
387
388
                ($sentence =~ m{CREATE}sio) && 
388
389
                ($sentence =~ m{BEGIN|END}sio)
389
390
        ) {
390
 
                return [ $sentence ];
 
391
                return [ $sentence ], rqg_debug() ? [ keys %rule_counters ] : [];
391
392
        } elsif ($sentence =~ m{;}) {
392
393
                my @sentences = split (';', $sentence);
393
 
                return \@sentences;
 
394
                return \@sentences, rqg_debug() ? [ keys %rule_counters ] : [];
394
395
        } else {
395
 
                return [ $sentence ];
 
396
                return [ $sentence ], rqg_debug() ? [ keys %rule_counters ] : [];
396
397
        }
397
398
}
398
399