@@ -289,71 +289,72 @@ sub ParseData
289289
290290 if ($preserve_formatting )
291291 {
292- # Scan the input file.
293- while (<$ifd >)
294- {
295- my $hash_ref ;
296-
297- if (/ {/ )
292+ # Scan the input file.
293+ while (<$ifd >)
298294 {
299- # Capture the hash ref
300- # NB: Assumes that the next hash ref can't start on the
301- # same line where the present one ended.
302- # Not foolproof, but we shouldn't need a full parser,
303- # since we expect relatively well-behaved input.
304-
305- # Quick hack to detect when we have a full hash ref to
306- # parse. We can't just use a regex because of values in
307- # pg_aggregate and pg_proc like '{0,0}'. This will need
308- # work if we ever need to allow unbalanced braces within
309- # a field value.
310- my $lcnt = tr / {// ;
311- my $rcnt = tr / }// ;
312-
313- if ($lcnt == $rcnt )
295+ my $hash_ref ;
296+
297+ if (/ {/ )
314298 {
315- # We're treating the input line as a piece of Perl, so we
316- # need to use string eval here. Tell perlcritic we know what
317- # we're doing.
318- eval ' $hash_ref = ' . $_ ; # # no critic (ProhibitStringyEval)
319- if (!ref $hash_ref )
299+ # Capture the hash ref
300+ # NB: Assumes that the next hash ref can't start on the
301+ # same line where the present one ended.
302+ # Not foolproof, but we shouldn't need a full parser,
303+ # since we expect relatively well-behaved input.
304+
305+ # Quick hack to detect when we have a full hash ref to
306+ # parse. We can't just use a regex because of values in
307+ # pg_aggregate and pg_proc like '{0,0}'. This will need
308+ # work if we ever need to allow unbalanced braces within
309+ # a field value.
310+ my $lcnt = tr / {// ;
311+ my $rcnt = tr / }// ;
312+
313+ if ($lcnt == $rcnt )
320314 {
321- die " $input_file : error parsing line $. :\n $_ \n " ;
322- }
315+ # We're treating the input line as a piece of Perl, so we
316+ # need to use string eval here. Tell perlcritic we know what
317+ # we're doing.
318+ eval ' $hash_ref = '
319+ . $_ ; # # no critic (ProhibitStringyEval)
320+ if (!ref $hash_ref )
321+ {
322+ die " $input_file : error parsing line $. :\n $_ \n " ;
323+ }
324+
325+ # Annotate each hash with the source line number.
326+ $hash_ref -> {line_number } = $. ;
323327
324- # Annotate each hash with the source line number.
325- $hash_ref -> {line_number } = $. ;
328+ # Expand tuples to their full representation.
329+ AddDefaultValues($hash_ref , $schema , $catname );
330+ }
331+ else
332+ {
333+ my $next_line = <$ifd >;
334+ die " $input_file : file ends within Perl hash\n "
335+ if !defined $next_line ;
336+ $_ .= $next_line ;
337+ redo ;
338+ }
339+ }
326340
327- # Expand tuples to their full representation.
328- AddDefaultValues($hash_ref , $schema , $catname );
341+ # If we found a hash reference, keep it, unless it is marked as
342+ # autogenerated; in that case it'd duplicate an entry we'll
343+ # autogenerate below. (This makes it safe for reformat_dat_file.pl
344+ # with --full-tuples to print autogenerated entries, which seems like
345+ # useful behavior for debugging.)
346+ #
347+ # Otherwise, we have a non-data string, which we need to keep in
348+ # order to preserve formatting.
349+ if (defined $hash_ref )
350+ {
351+ push @$data , $hash_ref if !$hash_ref -> {autogenerated };
329352 }
330353 else
331354 {
332- my $next_line = <$ifd >;
333- die " $input_file : file ends within Perl hash\n "
334- if !defined $next_line ;
335- $_ .= $next_line ;
336- redo ;
355+ push @$data , $_ ;
337356 }
338357 }
339-
340- # If we found a hash reference, keep it, unless it is marked as
341- # autogenerated; in that case it'd duplicate an entry we'll
342- # autogenerate below. (This makes it safe for reformat_dat_file.pl
343- # with --full-tuples to print autogenerated entries, which seems like
344- # useful behavior for debugging.)
345- #
346- # Otherwise, we have a non-data string, which we need to keep in
347- # order to preserve formatting.
348- if (defined $hash_ref )
349- {
350- push @$data , $hash_ref if !$hash_ref -> {autogenerated };
351- }
352- else
353- {
354- push @$data , $_ ;
355- }
356- }
357358 }
358359 else
359360 {
0 commit comments