summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/util/unbrace
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2013-11-14 22:56:27 +0100
committerAdam Borowski <kilobyte@angband.pl>2013-11-15 21:03:44 +0100
commit0b023e03c57e49cc2de9124c9984fe57ef06f68d (patch)
tree1cc9f3a96d47181127f77cffd32a37208a637baa /crawl-ref/source/util/unbrace
parent774998e0237268321527e3865bce6bb96c381bc6 (diff)
downloadcrawl-ref-0b023e03c57e49cc2de9124c9984fe57ef06f68d.tar.gz
crawl-ref-0b023e03c57e49cc2de9124c9984fe57ef06f68d.zip
Teach util/unbrace that "return" is not a function.
Diffstat (limited to 'crawl-ref/source/util/unbrace')
-rwxr-xr-xcrawl-ref/source/util/unbrace25
1 files changed, 25 insertions, 0 deletions
diff --git a/crawl-ref/source/util/unbrace b/crawl-ref/source/util/unbrace
index a2d4e3395b..a0eb3981e8 100755
--- a/crawl-ref/source/util/unbrace
+++ b/crawl-ref/source/util/unbrace
@@ -11,8 +11,33 @@ for $f (grep /\.(cc|h)$/, split /\n/, `git ls-files`)
# Should have told you to:
# for x in *.cc *.h;do unbrace <"$x" >aa && mv aa "$x";done
# like I always did before...
+ # Eliminate braces around one-line blocks.
s&^( +(?:if|while|for|do|else)\b[^\n]*)\n +{\n( *[^/ }][^\n]*)\n +}$&$1\n$2&msg;
+ # return is not a function, eliminate totally enclosing parentheses.
+ # This part handles parenthese-less payloads.
+ while (/^( *)return \(([^()]+)\);/sm)
+ {
+ # Done this roundabout way to properly unindent multiline blocks.
+ my $prev = "$`$1return ";
+ my $next = ";$'";
+ my $cur = $2;
+ $cur =~ s/\n /\n/sg;
+ $_ = "$prev$cur$next";
+ }
+
+ # return (x) where x contains parentheses.
+ # Looks like no one told Larry Wall properties of regular expression,
+ # including the part where they can't do arbitrarily nested parentheses.
+ while (/^(\ *)return\ \( ([^()]++) (\( (?: [^()]++ | (?3) )* \)) ([^()]++)\);/sxm)
+ {
+ my $prev = "$`$1return ";
+ my $next = ";$'";
+ my $cur = "$2$3$4";
+ $cur =~ s/\n /\n/sg;
+ $_ = "$prev$cur$next";
+ }
+
if ($old ne $_)
{
print "$f\n";