aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-08-06 15:16:04 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-08-06 15:16:04 +0200
commit97ca7117735044673da6c89ee9dff544a3526f70 (patch)
treea32cc31de9e04a258d8701b4c573051a6924596b
parentc20c3ad3141d88003245c6c7608e1f75c620e866 (diff)
Resolve if-else block ambiguity
-rw-r--r--build2/parser.cxx14
-rw-r--r--old-tests/if-else/buildfile9
-rw-r--r--old-tests/if-else/test.out1
3 files changed, 19 insertions, 5 deletions
diff --git a/build2/parser.cxx b/build2/parser.cxx
index 0c45e17..66af0a5 100644
--- a/build2/parser.cxx
+++ b/build2/parser.cxx
@@ -1396,13 +1396,17 @@ namespace build2
fail (t) << "expected newline instead of " << t << " after " << k
<< (k != "else" ? "-expression" : "");
- // This can be a block or a single line.
+ // This can be a block or a single line. The block part is a bit
+ // tricky, consider:
//
- if (next (t, tt) == type::lcbrace)
+ // else
+ // {hxx cxx}{options}: install = false
+ //
+ // So we treat it as a block if it's followed immediately by newline.
+ //
+ if (next (t, tt) == type::lcbrace && peek () == type::newline)
{
- if (next (t, tt) != type::newline)
- fail (t) << "expected newline after {";
-
+ next (t, tt); // Get newline.
next (t, tt);
if (take)
diff --git a/old-tests/if-else/buildfile b/old-tests/if-else/buildfile
index 25fabf0..16a49fb 100644
--- a/old-tests/if-else/buildfile
+++ b/old-tests/if-else/buildfile
@@ -148,6 +148,15 @@ if true
else
print 1
+# Brace ambiguity.
+#
+if false
+ {dir}{.}: x = 0
+else
+ {dir}{.}: x = 1
+
+print $(dir{.}:x)
+
# EOF test.
#
./:
diff --git a/old-tests/if-else/test.out b/old-tests/if-else/test.out
index 58501cb..4cce943 100644
--- a/old-tests/if-else/test.out
+++ b/old-tests/if-else/test.out
@@ -14,3 +14,4 @@
1
1
1
+1