Skip to content

Commit 4c023d2

Browse files
author
Chris White
committed
Perl comments now permitted in code blocks.
Added a newline to the generated script after every Perl code block so that comments (which run to end of line) will always be terminated at the end of the code block.
1 parent cd3f215 commit 4c023d2

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

perlpp.pl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,31 +292,33 @@ sub OnOpening {
292292
sub OnClosing {
293293
my $inside;
294294
my $insetMode;
295-
my $plainMode = OBMODE_PLAIN;
295+
my $nextMode = OBMODE_PLAIN;
296296

297297
$insetMode = GetModeOfOB();
298298
$inside = EndOB(); # contents of the inset
299299
if ( $inside =~ /"$/ ) {
300300
StartOB( $insetMode ); # restore contents of the inset
301301
print substr( $inside, 0, -1 );
302-
$plainMode = OBMODE_CAPTURE;
302+
$nextMode = OBMODE_CAPTURE;
303303
} else {
304304
if ( $insetMode == OBMODE_ECHO ) {
305305
print "print ${inside};\n"; # don't wrap in (), trailing semicolon
306306
} elsif ( $insetMode == OBMODE_COMMAND ) {
307307
ExecuteCommand( $inside );
308308
} elsif ( $insetMode == OBMODE_COMMENT ) {
309309
# Ignore the contents - no operation
310+
} elsif ( $insetMode == OBMODE_CODE ) {
311+
print "$inside\n"; # \n so you can put comments in your perl code
310312
} else {
311313
print $inside;
312314
}
313315

314316
if ( GetModeOfOB() == OBMODE_CAPTURE ) { # if the inset is wrapped
315317
print EndOB() . " PerlPP::EndOB(); } . "; # end of do { .... } statement
316-
$plainMode = OBMODE_CAPTURE; # back to capturing
318+
$nextMode = OBMODE_CAPTURE; # back to capturing
317319
}
318320
}
319-
StartOB( $plainMode ); # plain text
321+
StartOB( $nextMode ); # plain text
320322
} #OnClosing()
321323

322324
sub RunPerlPP {

t/basic.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ my @testcases=(
1616
['Foo <?= 2+2 ?> <? print "?>Howdy, "world!" I\'m cool.<?"; ?> bar'."\n",
1717
'Foo 4 Howdy, "world!" I\'m cool. bar'."\n"],
1818
['<?# This output file is tremendously boring. ?>',''],
19+
['<? my $x=42; #this is a comment?><?=$x?>','42'],
1920
['<?#ditto?>',''],
2021
['<? my $foo=80; ?>#define QUUX (<?= $foo/40 ?>)', '#define QUUX (2)'],
2122
['<? print (map { $_ . $_ . "\n" } qw(a b c d)); ?>',"aa\nbb\ncc\ndd\n"],

0 commit comments

Comments
 (0)