some bugfixes
This commit is contained in:
+11
-16
@@ -1,18 +1,13 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
#$Author: zimoch $
|
||||
#$Date: 2008/09/19 11:13:04 $
|
||||
#$Revision: 1.1 $
|
||||
#$Id: dbLoadTemplate,v 1.1 2008/09/19 11:13:04 zimoch Exp $
|
||||
|
||||
use strict;
|
||||
|
||||
my $QUOTECHAR = '"';
|
||||
my $NOWORDCHAR = ",(){}=";
|
||||
|
||||
my $NOWORD=qr/[${NOWORDCHAR}${QUOTECHAR}]/;
|
||||
my $WORD=qr/[^\s${NOWORDCHAR}${QUOTECHAR}]+/;
|
||||
my $STRING=qr/(?:$QUOTECHAR([^$QUOTECHAR]*)$QUOTECHAR)/;
|
||||
my $NOWORD=qr/[${NOWORDCHAR}${QUOTECHAR}]/; # single non-word character
|
||||
my $WORD=qr/[^\s${NOWORDCHAR}${QUOTECHAR}]+/; # unquoted word
|
||||
my $STRING=qr/(?:$QUOTECHAR((?:\\.|\\\n|.)*?)$QUOTECHAR)/; # quoted string
|
||||
my $SUBST=qr/(\$\(.*?\)|[^\s${NOWORDCHAR}${QUOTECHAR}])+/; # unquoted word with $(macro) allowed
|
||||
|
||||
# nextToken returns the next input word, string, or char
|
||||
# It skips comments and whitespace
|
||||
@@ -28,9 +23,9 @@ sub nextToken {
|
||||
die "unexpected end of file in $ARGV\n";
|
||||
}
|
||||
}
|
||||
$input =~ s/^\s*($WORD|$STRING|$NOWORD)\s*(#.*\n?)?//;
|
||||
$input =~ s/^\s*($WORD|$STRING|$NOWORD|$SUBST)\s*(#.*\n?)?//;
|
||||
$1 ne $QUOTECHAR or die "unterminated string in $ARGV line $.\n";
|
||||
# print STDERR "nextToken from $ARGV line $. is $1\n";
|
||||
#print STDERR "nextToken from $ARGV line $. is $1\n";
|
||||
$1;
|
||||
}
|
||||
|
||||
@@ -62,9 +57,9 @@ sub expect {
|
||||
}
|
||||
$success or die "parse error in $ARGV line $.: found '$_' instead of $desc\n";
|
||||
}
|
||||
if (s/^"(.*)"$/$1/) {
|
||||
%subst and s/\$\(([^\)]*)\)/replace($1)/ge;
|
||||
}
|
||||
s/^$QUOTECHAR(.*)$QUOTECHAR$/$1/; # remove quotes around strings
|
||||
m/\$\(([^)]*)$/ and die "unterminated macro \$($1 in $ARGV line $.\n";
|
||||
%subst and s/\$\((.*?)\)/replace($1)/ge; # replace macros
|
||||
$_;
|
||||
}
|
||||
|
||||
@@ -122,7 +117,7 @@ sub parseSubst {
|
||||
$macro = expect "$WORD|,|} macro name";
|
||||
} while $_ eq ","; # ignore commas
|
||||
last if $_ eq '}';
|
||||
expect "=", "$WORD|$STRING value for $macro";
|
||||
expect "=", "$STRING|$SUBST value for $macro";
|
||||
$subst{$macro} = $_;
|
||||
}
|
||||
parseTemplate $filename;
|
||||
@@ -145,7 +140,7 @@ sub parseSubst {
|
||||
last if $_ eq "}";
|
||||
foreach my $macro (@macros) {
|
||||
do {
|
||||
expect "$WORD|$STRING|, value for $macro";
|
||||
expect "$STRING|$SUBST|, value for $macro";
|
||||
} while $_ eq ","; # ignore commas
|
||||
$subst{$macro} = $_;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user