PerlPoint-Package
view release on metacpan or search on metacpan
ppParser.yp view on Meta::CPAN
{
push(@{$resultStreamRef->[STREAM_TOKENS]}, [{}, DIRECTIVE_NEW_LINE, DIRECTIVE_START, {file=>$sourceFile, line=>$lineNrs{$inHandle}}]);
# update tag finish memory by the way
_updateTagFinishMem(scalar(@{$resultStreamRef->[STREAM_TOKENS]}));
}
# remove TRAILING whitespaces, but keep newlines (if any)
{
my $newline=($parser->{USER}->{INPUT}=~/\n$/m);
$parser->{USER}->{INPUT}=~s/\s*$//;
$parser->{USER}->{INPUT}=join('', $parser->{USER}->{INPUT}, "\n") if $newline;
}
}
# scan for empty lines as necessary
if ($parser->{USER}->{INPUT}=~/^$/)
{
# update the checksum flags
$flags{checksum}=1 if $flags{cache} & CACHE_ON;
# trace, if necessary
warn "[Trace] Lexer: Empty_line in line $lineNrs{$inHandle}", $lexerFlags{el}==LEXER_IGNORE ? ' is ignored' : '', ".\n" if $flags{trace} & TRACE_LEXER;
# update input line
$parser->{USER}->{INPUT}='';
# sometimes empty lines have no special meaning
shift(@inLine), redo if $lexerFlags{el}==LEXER_IGNORE;
# but sometimes they are very special
return('Empty_line', ["\n", $lineNrs{$inHandle}]);
}
else
{
# disable caching for embedded code containing empty lines
$flags{checksummed}=0 if $specials{embedded};
# this may be the first line of a new paragraph to be checksummed
if (
($flags{cache} & CACHE_ON)
and $flags{checksum}
and not $lineFromStack
and (not $specials{heredoc} or $specials{heredoc} eq '1')
and not @tableSeparatorStack
and not $specials{embedded}
)
{
# handle $/ locally
local($/);
# update statistics
$statistics{cache}[0]++;
# well, switch to paragraph mode (depending on the paragraph type)!
if ($parser->{USER}->{INPUT}=~/^<<(\w+)/)
{$/="\n$1";}
elsif ($parser->{USER}->{INPUT}=~/^(?<!\\)\\TABLE/i)
{$/="\n\\END_TABLE";}
else
{$/='';}
# store current position
my $lexerPosition=tell($inHandle);
# read *current* paragraph completely (take care - we may have read it completely yet!)
seek($inHandle, $lexerPosition-length($parser->{USER}->{INPUT}), 0) unless $parser->{USER}->{INPUT}=~/^<<(\w+)/ or $parser->{USER}->{INPUT}=~/^(?<!\\)\\TABLE/i;
my $paragraph=<$inHandle>;
$paragraph=join('', $parser->{USER}->{INPUT}, $paragraph) if $parser->{USER}->{INPUT}=~/^<<(\w+)/ or $parser->{USER}->{INPUT}=~/^(?<!\\)\\TABLE/i;
# count the lines in the paragraph read
my $plines=0;
$plines++ while $paragraph=~/(\n)/g;
$plines-- unless $parser->{USER}->{INPUT}=~/^<<(\w+)/ or $parser->{USER}->{INPUT}=~/^(?<!\\)\\TABLE/i;
# remove trailing whitespaces (to avoid checksumming them)
$paragraph=~s/\n+$//;
# anything interesting found?
if (defined $paragraph)
{
# build checksum (of paragraph *and* headline level offset)
my $checksum=sha1_base64(join('+', exists $flags{headlineLevelOffset} ? $flags{headlineLevelOffset} : 0, $paragraph));
# warn "---> Searching checksum for this paragraph:\n-----\n$paragraph\n- by $checksum --\n";
# check paragraph to be known
if (
exists $checksums->{$sourceFile}
and exists $checksums->{$sourceFile}{$checksum}
and (
not defined $checksums->{$sourceFile}{$checksum}[3]
or $checksums->{$sourceFile}{$checksum}[3] eq $macroChecksum
)
and (
not defined $checksums->{$sourceFile}{$checksum}[4]
or $checksums->{$sourceFile}{$checksum}[4] eq $varChecksum
)
)
{
# Do *not* reset the checksum flag for new checksums - we already read the
# empty lines, and a new paragraph may follow! *But* deactivate the current
# checksum to avoid multiple storage - we already stored it, right?
$flags{checksummed}=0;
# reset input buffer - it is all handled (take care to remove a final newline
# if the paragraph was closed by a string - this would normally be read in a
# per line processing, but it remained in the file in paragraph mode)
$/="\n";
scalar(<$inHandle>) if $parser->{USER}->{INPUT}=~/^<<(\w+)/ or $parser->{USER}->{INPUT}=~/^(?<!\\)\\TABLE/i;
$parser->{USER}->{INPUT}='';
# warn "===========> PARAGRAPH CACHE HIT!! ($lineNrs{$inHandle}/$sourceFile/$checksum) <=================\n$paragraph-----\n";
# use Data::Dumper; warn Dumper($checksums->{$sourceFile}{$checksum});
# update statistics
$statistics{cache}[1]++;
# update line counter
# warn "----> Old line: $lineNrs{$inHandle}\n";
$lineNrs{$inHandle}+=$plines;
# warn "----> New line: $lineNrs{$inHandle}\n";
( run in 1.533 second using v1.01-cache-2.11-cpan-364913b4093 )