From c0af4134ef13c309b8fa84fa44aad751aa297de6 Mon Sep 17 00:00:00 2001 From: Neil Moore Date: Sat, 3 May 2014 01:41:26 -0400 Subject: Add a comment to util/unbrace. With a regexp to match things that need braces. Unfortunately, there are some false positives, and we can't tell where the braces are supposed to go. --- crawl-ref/source/util/unbrace | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'crawl-ref/source/util') 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) -- cgit v1.2.3-54-g00ecf