summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xcrawl-ref/source/util/unbrace21
1 files changed, 21 insertions, 0 deletions
diff --git a/crawl-ref/source/util/unbrace b/crawl-ref/source/util/unbrace
index ac73a24fa2..9febd6dc62 100755
--- a/crawl-ref/source/util/unbrace
+++ b/crawl-ref/source/util/unbrace
@@ -26,6 +26,27 @@ for $f (@files)
# Eliminate braces around one-line blocks.
s&^( +(?:if|while|for|do|else)\b[^\n]*)\n +{\n( *[^/ }][^\n]*)\n +}$&$1\n$2&msg;
+ # Something like the following should match multi-line flow-control statements
+ # with missing braces, but:
+ # 1. it's slow (for example, on beam.cc);
+ # 2. it has false positives at the end of do-while loops; and
+ # 3. it's not clear how to determine where to put the braces.
+ #
+ # /( # Save multi-line statement with missing braces in \1.
+ # # Save indent of first line in \2
+ # ^(\s+) (?:if|while|for|do|else)\b .*\n
+ #
+ # # Second line: not flow-control, greater indent.
+ # \2 \s+ (?! \s | (?:if|while|for|do|else)\b) .*\n
+ #
+ # # One or more lines of greater indent than the first.
+ # (?: \2 \s+ .*\n)+
+ # )
+ # # Next line falls outside the indentation of the first line: it has
+ # # either a smaller indent, or the same indent then a non-brace.
+ # (?! \2 [\s{])
+ # /mgx; # No /s !
+
# return is not a function, eliminate totally enclosing parentheses.
# This part handles parenthese-less payloads.
while (/^( *)return \(([^()]+)\);/sm)