Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4ff90d9

Browse files
author
Michael Meskes
committed
Added new version of ecpg's parser test script which was written by Andy Colson <andy@squeakycode.net>.
1 parent4cd3fb6 commit4ff90d9

File tree

1 file changed

+122
-76
lines changed

1 file changed

+122
-76
lines changed

‎src/interfaces/ecpg/preproc/check_rules.pl

100755100644
Lines changed: 122 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -6,130 +6,176 @@
66
# Copyright (c) 2009-2011, PostgreSQL Global Development Group
77
#
88
# Written by Michael Meskes <meskes@postgresql.org>
9+
# Andy Colson <andy@squeakycode.net>
910
#
1011
# Placed under the same license as PostgreSQL.
1112
#
13+
# Command line: [-v] [path only to ecpg.addons] [full filename of gram.y]
14+
# -v enables verbose mode... show's some stats... thought it might be interesting
15+
#
16+
# This script loads rule names from gram.y and sets $found{rule} = 1 for each.
17+
# Then it checks to make sure each rule in ecpg.addons was found in gram.y
1218

13-
if (@ARGV) {
14-
$path =$ARGV[0];
15-
$parser =$ARGV[1];
16-
}
19+
use strict;
20+
use warnings;
21+
no warnings'uninitialized';
1722

18-
$[ = 1;# set array base to 1
23+
my$verbose = 0;
24+
if ($ARGV[0]eq'-v')
25+
{
26+
$verbose =shift;
27+
}
28+
my$path =shift ||'.';
29+
my$parser =shift ||'../../../backend/parser/gram.y';
30+
31+
my$filename =$path ."/ecpg.addons";
32+
if ($verbose)
33+
{
34+
print"parser:$parser\n";
35+
print"addons:$filename\n";
36+
}
1937

20-
if ($patheq'') {$path ="."; }
21-
$filename =$path ."/ecpg.addons";
38+
my%replace_line = (
39+
'ExecuteStmtEXECUTEnameexecute_param_clause'=>
40+
'EXECUTE prepared_name execute_param_clause execute_rest',
2241

23-
if ($parsereq'') {$parser ="../../../backend/parser/gram.y"; }
42+
'ExecuteStmtCREATEOptTempTABLEcreate_as_targetASEXECUTEnameexecute_param_clause'=>
43+
'CREATE OptTemp TABLE create_as_target AS EXECUTE prepared_name execute_param_clause',
2444

25-
$replace_line{'ExecuteStmtEXECUTEnameexecute_param_clause'} ='EXECUTE prepared_name execute_param_clause execute_rest';
26-
$replace_line{'ExecuteStmtCREATEOptTempTABLEcreate_as_targetASEXECUTEnameexecute_param_clause'} ='CREATE OptTemp TABLE create_as_targetASEXECUTE prepared_name execute_param_clause';
27-
$replace_line{'PrepareStmtPREPAREnameprep_type_clauseASPreparableStmt'} ='PREPARE prepared_name prep_type_clause AS PreparableStmt';
45+
'PrepareStmtPREPAREnameprep_type_clauseASPreparableStmt'=>
46+
'PREPARE prepared_name prep_type_clauseASPreparableStmt'
47+
);
2848

29-
$block ='';
30-
$ret = 0;
31-
$yaccmod = 0;
32-
$brace_indent = 0;
49+
my$block ='';
50+
my$yaccmode = 0;
51+
my$brace_indent = 0;
52+
my (@arr,%found);
53+
my$comment = 0;
54+
my$non_term_id ='';
55+
my$cc = 0;
3356

3457
open GRAM,$parserordie$!;
35-
while (<GRAM>) {
36-
chomp;# strip record separator
58+
while (<GRAM>)
59+
{
60+
if (/^%%/)
61+
{
62+
$yaccmode++;
63+
}
3764

38-
if (/^%%/) {
39-
$yaccmode++;
65+
if ($yaccmode != 1 )
66+
{
67+
next;
4068
}
4169

42-
if ($yaccmode != 1) {
43-
next;
44-
}
70+
chomp;# strip record separator
4571

46-
$S =$_;
47-
$prec = 0;
72+
nextif ($_eq'');
4873

4974
# Make sure any braces are split
50-
$S =~s/{/ {/g;
51-
$S =~s/}/ }/g;
75+
s/{/ {/g;
76+
s/}/ }/g;
77+
5278
# Any comments are split
53-
$S =~s#[/][*]# /*#g;
54-
$S =~s#[*][/]# */#g;
79+
s|\/\*| /*|g;
80+
s|\*\/| */|g;
5581

5682
# Now split the line into individual fields
57-
$n = (@arr =split('',$S));
83+
my$n = (@arr =split('' ));
5884

5985
# Go through each field in turn
60-
for ($fieldIndexer = 1;$fieldIndexer <=$n;$fieldIndexer++) {
61-
if ($arr[$fieldIndexer]eq'*/' &&$comment) {
62-
$comment = 0;
63-
next;
86+
for (my$fieldIndexer = 0 ;$fieldIndexer <$n ;$fieldIndexer++ )
87+
{
88+
if ($arr[$fieldIndexer]eq'*/' &&$comment )
89+
{
90+
$comment = 0;
91+
next;
6492
}
65-
elsif ($comment) {
66-
next;
93+
elsif ($comment)
94+
{
95+
next;
6796
}
68-
elsif ($arr[$fieldIndexer]eq'/*') {
69-
# start of a multiline comment
70-
$comment = 1;
71-
next;
97+
elsif ($arr[$fieldIndexer]eq'/*' )
98+
{
99+
# start of a multiline comment
100+
$comment = 1;
101+
next;
72102
}
73-
elsif ($arr[$fieldIndexer]eq'//') {
74-
next;
103+
elsif ($arr[$fieldIndexer]eq'//' )
104+
{
105+
next;
75106
}
76-
elsif ($arr[$fieldIndexer]eq'}') {
77-
$brace_indent--;
78-
next;
107+
elsif ($arr[$fieldIndexer]eq'}' )
108+
{
109+
$brace_indent--;
110+
next;
79111
}
80-
elsif ($arr[$fieldIndexer]eq'{') {
81-
$brace_indent++;
82-
next;
112+
elsif ($arr[$fieldIndexer]eq'{' )
113+
{
114+
$brace_indent++;
115+
next;
83116
}
84117

85-
if ($brace_indent > 0) {
86-
next;
118+
if ($brace_indent > 0 )
119+
{
120+
next;
87121
}
88122

89-
if ($arr[$fieldIndexer]eq';' ||$arr[$fieldIndexer]eq'|') {
123+
if ($arr[$fieldIndexer]eq';' ||$arr[$fieldIndexer]eq'|' )
124+
{
90125
$block =$non_term_id .$block;
91-
if ($replace_line{$block}) {
92-
$block = &generate_block($replace_line{$block});
126+
if ($replace_line{$block} )
127+
{
128+
$block =$non_term_id .$replace_line{$block};
129+
$block =~tr/ |//d;
93130
}
94-
$found{$block} ='found';
131+
$found{$block} = 1;
132+
$cc++;
95133
$block ='';
96134
}
97-
elsif (($arr[$fieldIndexer] =~'[A-Za-z0-9]+:') ||$arr[$fieldIndexer + 1]eq':') {
135+
elsif ( ($arr[$fieldIndexer] =~'[A-Za-z0-9]+:' )
136+
||$arr[$fieldIndexer + 1 ]eq':' )
137+
{
98138
$non_term_id =$arr[$fieldIndexer];
99-
$non_term_id =~s/://g;
139+
$non_term_id =~tr/://d;
100140
}
101-
else {
141+
else
142+
{
102143
$block =$block .$arr[$fieldIndexer];
103144
}
104145
}
105146
}
106147

107148
close GRAM;
149+
if ($verbose)
150+
{
151+
print"$cc rules loaded\n";
152+
}
108153

109-
open ECPG,$filenameordie$!;
110-
111-
line:while (<ECPG>) {
112-
chomp;# strip record separator
113-
@Fld =split('',$_, -1);
154+
my$ret = 0;
155+
$cc = 0;
114156

115-
if (!/^ECPG:/) {
116-
next line;
117-
}
157+
open ECPG,$filenameordie$!;
158+
while (<ECPG>)
159+
{
160+
if ( !/^ECPG:/ )
161+
{
162+
next;
163+
}
118164

119-
if ($found{$Fld[2]}ne'found') {
120-
printf$Fld[2] ." is not used for building parser!\n";
121-
$ret = 1;
122-
}
165+
my@Fld =split('',$_, 3 );
166+
$cc++;
167+
if (notexists$found{$Fld[1] } )
168+
{
169+
print$Fld[1]," is not used for building parser!\n";
170+
$ret = 1;
171+
}
123172
}
124-
125173
close ECPG;
126174

175+
if ($verbose)
176+
{
177+
print"$cc rules checked\n";
178+
}
179+
127180
exit$ret;
128181

129-
subgenerate_block {
130-
local($line) =@_;
131-
$block =$non_term_id .$line;
132-
$block =~s///g;
133-
$s ="\\|",$block =~s/$s//g;
134-
return$block;
135-
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp