~drizzle-trunk/drizzle/development

0.67.392 by Philip Stoev
allow grammar simplification to work with mask and mask-level
1
# Copyright (C) 2008-2009 Sun Microsystems, Inc. All rights reserved.
2
# Use is subject to license terms.
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 2 of the License.
7
#
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
# General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
16
# USA
17
18
use strict;
19
use lib 'lib';
20
use lib '../lib';
21
use Carp;
22
use Getopt::Long;
23
24
use GenTest;
25
use GenTest::Properties;
26
use GenTest::Grammar;
27
28
my $options = {};
29
GetOptions(
30
	$options,
31
	'grammar=s',
32
	'mask=i',
33
	'mask-level=i'
34
);
35
36
my $config = GenTest::Properties->new(
37
	options => $options,
38
	defaults => {
39
		'mask-level'	=> 1,
40
		'mask'		=> 0
41
	},
42
	required => ['grammar']
43
);
44
45
my ($grammar_file, $mask, $mask_level) = (
46
	$config->property('grammar'),
47
	$config->property('mask'),
48
	$config->property('mask-level')
49
);
50
51
say("Grammar: $grammar_file");
52
say("Mask: $mask");
53
say("Mask-level: $mask_level");
54
55
my $initial_grammar = GenTest::Grammar->new(
56
	'grammar_file'	=> $grammar_file
57
);
58
59
my $final_grammar;
60
61
if ($mask > 0) {
62
	my $top_grammar = $initial_grammar->topGrammar($mask_level, "query", "query_init");
63
	my $masked_top = $top_grammar->mask($mask);
64
	$final_grammar = $initial_grammar->patch($masked_top);
65
} else {
66
	$final_grammar = $initial_grammar;
67
}
68
69
print $final_grammar->toString();
70
print "\n";