From 522b9770dd335d3a98a2f976a243f7e6d620f726 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Tue, 27 Aug 2013 00:42:17 +0000 Subject: [PATCH] compiler_vm: Fix comment stripping logic regarding C89 comments versus C99 comments in code like `int i = 10 //**/ 2\n;` Code history now includes argument flags Improved regex parsing of diff tags --- PBot/VERSION.pm | 4 ++-- modules/compiler_vm/compiler_vm_client.pl | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index 4137d8d5..21dd9de8 100644 --- a/PBot/VERSION.pm +++ b/PBot/VERSION.pm @@ -13,8 +13,8 @@ use warnings; # These are set automatically by the build/commit script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 425, - BUILD_DATE => "2013-08-24", + BUILD_REVISION => 426, + BUILD_DATE => "2013-08-26", }; 1; diff --git a/modules/compiler_vm/compiler_vm_client.pl b/modules/compiler_vm/compiler_vm_client.pl index 57db7799..fec38db5 100755 --- a/modules/compiler_vm/compiler_vm_client.pl +++ b/modules/compiler_vm/compiler_vm_client.pl @@ -189,8 +189,8 @@ if($code =~ m/^\s*diff\s*$/i) { if($diff !~ /(?:|)/) { $diff = "No difference."; } else { - $diff =~ s/([^\s]+)(\s+)<\/del>/$1<\/del>$2/g; - $diff =~ s/([^\s]+)(\s+)<\/ins>/$1<\/ins>$2/g; + $diff =~ s/(.*?)(\s+)<\/del>/$1<\/del>$2/g; + $diff =~ s/(.*?)(\s+)<\/ins>/$1<\/ins>$2/g; $diff =~ s/((?:(?!).)*)<\/del>\s*((?:(?!).)*)<\/ins>/<[replaced `$1` with `$2`]>/g; $diff =~ s/(.*?)<\/del>/<[removed `$1`]>/g; $diff =~ s/(.*?)<\/ins>/<[inserted `$1`]>/g; @@ -468,7 +468,9 @@ if($code =~ m/^\s*(run|paste)\s*$/i) { }; if($@) { - print "$nick: $@\n"; + my $foo = $@; + $foo =~ s/ at \.\/compiler_vm_client.pl line \d+\.\s*//; + print "$nick: $foo\n"; exit 0; } @@ -551,7 +553,9 @@ if($code =~ m/^\s*(run|paste)\s*$/i) { }; if($@) { - print "$nick: $@\n"; + my $foo = $@; + $foo =~ s/ at \.\/compiler_vm_client.pl line \d+\.\s*//; + print "$nick: $foo\n"; exit 0; } @@ -574,7 +578,7 @@ if($code =~ m/^\s*(run|paste)\s*$/i) { open FILE, "> last_code.txt"; unless ($got_undo and not $got_changes) { - unshift @last_code, $code; + unshift @last_code, length $args ? $args . ' ' . $code : $code; } my $i = 0; @@ -771,7 +775,13 @@ if($lang eq 'C89' or $lang eq 'C99' or $lang eq 'C11' or $lang eq 'C++') { print "*** prelude: [$prelude]\n precode: [$precode]\n" if $debug; # strip C and C++ style comments - $precode =~ s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//([^\\]|[^\n][\n]?)*?\n|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $3 ? $3 : " "#gse; + if($lang eq 'C89' or $args =~ m/-std=(gnu89|c89)/i) { + $precode =~ s#/\*[^*]*\*+([^/*][^*]*\*+)*/# #gs; + $precode =~ s#|//([^\\]|[^\n][\n]?)*?\n|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $2 ? $2 : " "#gse; + } else { + $precode =~ s#|//([^\\]|[^\n][\n]?)*?\n|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $2 ? $2 : " "#gse; + $precode =~ s#/\*[^*]*\*+([^/*][^*]*\*+)*/# #gs; + } print " precode: [$precode]\n" if $debug;