提交 4ff90d99 编写于 作者: M Michael Meskes

Added new version of ecpg's parser test script which was written by Andy...

Added new version of ecpg's parser test script which was written by Andy Colson <andy@squeakycode.net>.
上级 4cd3fb6e
...@@ -6,130 +6,176 @@ ...@@ -6,130 +6,176 @@
# Copyright (c) 2009-2011, PostgreSQL Global Development Group # Copyright (c) 2009-2011, PostgreSQL Global Development Group
# #
# Written by Michael Meskes <meskes@postgresql.org> # Written by Michael Meskes <meskes@postgresql.org>
# Andy Colson <andy@squeakycode.net>
# #
# Placed under the same license as PostgreSQL. # Placed under the same license as PostgreSQL.
# #
# Command line: [-v] [path only to ecpg.addons] [full filename of gram.y]
# -v enables verbose mode... show's some stats... thought it might be interesting
#
# This script loads rule names from gram.y and sets $found{rule} = 1 for each.
# Then it checks to make sure each rule in ecpg.addons was found in gram.y
if (@ARGV) { use strict;
$path = $ARGV[0]; use warnings;
$parser = $ARGV[1]; no warnings 'uninitialized';
}
$[ = 1; # set array base to 1 my $verbose = 0;
if ($ARGV[0] eq '-v')
{
$verbose = shift;
}
my $path = shift || '.';
my $parser = shift || '../../../backend/parser/gram.y';
my $filename = $path . "/ecpg.addons";
if ($verbose)
{
print "parser: $parser\n";
print "addons: $filename\n";
}
if ($path eq '') { $path = "."; } my %replace_line = (
$filename = $path . "/ecpg.addons"; 'ExecuteStmtEXECUTEnameexecute_param_clause' =>
'EXECUTE prepared_name execute_param_clause execute_rest',
if ($parser eq '') { $parser = "../../../backend/parser/gram.y"; } 'ExecuteStmtCREATEOptTempTABLEcreate_as_targetASEXECUTEnameexecute_param_clause' =>
'CREATE OptTemp TABLE create_as_target AS EXECUTE prepared_name execute_param_clause',
$replace_line{'ExecuteStmtEXECUTEnameexecute_param_clause'} = 'EXECUTE prepared_name execute_param_clause execute_rest'; 'PrepareStmtPREPAREnameprep_type_clauseASPreparableStmt' =>
$replace_line{'ExecuteStmtCREATEOptTempTABLEcreate_as_targetASEXECUTEnameexecute_param_clause'} = 'CREATE OptTemp TABLE create_as_target AS EXECUTE prepared_name execute_param_clause'; 'PREPARE prepared_name prep_type_clause AS PreparableStmt'
$replace_line{'PrepareStmtPREPAREnameprep_type_clauseASPreparableStmt'} = 'PREPARE prepared_name prep_type_clause AS PreparableStmt'; );
$block = ''; my $block = '';
$ret = 0; my $yaccmode = 0;
$yaccmod = 0; my $brace_indent = 0;
$brace_indent = 0; my (@arr, %found);
my $comment = 0;
my $non_term_id = '';
my $cc = 0;
open GRAM, $parser or die $!; open GRAM, $parser or die $!;
while (<GRAM>) { while (<GRAM>)
chomp; # strip record separator {
if (/^%%/)
{
$yaccmode++;
}
if (/^%%/) { if ( $yaccmode != 1 )
$yaccmode++; {
next;
} }
if ($yaccmode != 1) { chomp; # strip record separator
next;
}
$S = $_; next if ($_ eq '');
$prec = 0;
# Make sure any braces are split # Make sure any braces are split
$S =~ s/{/ { /g; s/{/ { /g;
$S =~ s/}/ } /g; s/}/ } /g;
# Any comments are split # Any comments are split
$S =~ s#[/][*]# /* #g; s|\/\*| /* |g;
$S =~ s#[*][/]# */ #g; s|\*\/| */ |g;
# Now split the line into individual fields # Now split the line into individual fields
$n = (@arr = split(' ', $S)); my $n = ( @arr = split( ' ' ) );
# Go through each field in turn # Go through each field in turn
for ($fieldIndexer = 1; $fieldIndexer <= $n; $fieldIndexer++) { for ( my $fieldIndexer = 0 ; $fieldIndexer < $n ; $fieldIndexer++ )
if ($arr[$fieldIndexer] eq '*/' && $comment) { {
$comment = 0; if ( $arr[$fieldIndexer] eq '*/' && $comment )
next; {
$comment = 0;
next;
} }
elsif ($comment) { elsif ($comment)
next; {
next;
} }
elsif ($arr[$fieldIndexer] eq '/*') { elsif ( $arr[$fieldIndexer] eq '/*' )
# start of a multiline comment {
$comment = 1; # start of a multiline comment
next; $comment = 1;
next;
} }
elsif ($arr[$fieldIndexer] eq '//') { elsif ( $arr[$fieldIndexer] eq '//' )
next; {
next;
} }
elsif ($arr[$fieldIndexer] eq '}') { elsif ( $arr[$fieldIndexer] eq '}' )
$brace_indent--; {
next; $brace_indent--;
next;
} }
elsif ($arr[$fieldIndexer] eq '{') { elsif ( $arr[$fieldIndexer] eq '{' )
$brace_indent++; {
next; $brace_indent++;
next;
} }
if ($brace_indent > 0) { if ( $brace_indent > 0 )
next; {
next;
} }
if ($arr[$fieldIndexer] eq ';' || $arr[$fieldIndexer] eq '|') { if ( $arr[$fieldIndexer] eq ';' || $arr[$fieldIndexer] eq '|' )
{
$block = $non_term_id . $block; $block = $non_term_id . $block;
if ($replace_line{$block}) { if ( $replace_line{$block} )
$block = &generate_block($replace_line{$block}); {
$block = $non_term_id . $replace_line{$block};
$block =~ tr/ |//d;
} }
$found{$block} = 'found'; $found{$block} = 1;
$cc++;
$block = ''; $block = '';
} }
elsif (($arr[$fieldIndexer] =~ '[A-Za-z0-9]+:') || $arr[$fieldIndexer + 1] eq ':') { elsif ( ( $arr[$fieldIndexer] =~ '[A-Za-z0-9]+:' )
|| $arr[ $fieldIndexer + 1 ] eq ':' )
{
$non_term_id = $arr[$fieldIndexer]; $non_term_id = $arr[$fieldIndexer];
$non_term_id =~ s/://g; $non_term_id =~ tr/://d;
} }
else { else
{
$block = $block . $arr[$fieldIndexer]; $block = $block . $arr[$fieldIndexer];
} }
} }
} }
close GRAM; close GRAM;
if ($verbose)
{
print "$cc rules loaded\n";
}
open ECPG, $filename or die $!; my $ret = 0;
$cc = 0;
line: while (<ECPG>) {
chomp; # strip record separator
@Fld = split(' ', $_, -1);
if (!/^ECPG:/) { open ECPG, $filename or die $!;
next line; while (<ECPG>)
} {
if ( !/^ECPG:/ )
{
next;
}
if ($found{$Fld[2]} ne 'found') { my @Fld = split( ' ', $_, 3 );
printf $Fld[2] . " is not used for building parser!\n"; $cc++;
$ret = 1; if ( not exists $found{ $Fld[1] } )
} {
print $Fld[1], " is not used for building parser!\n";
$ret = 1;
}
} }
close ECPG; close ECPG;
if ($verbose)
{
print "$cc rules checked\n";
}
exit $ret; exit $ret;
sub generate_block {
local($line) = @_;
$block = $non_term_id . $line;
$block =~ s/ //g;
$s = "\\|", $block =~ s/$s//g;
return $block;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册