From 4d134880196e85e06d5ff4e83a26a3b15027706a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 10 Jul 2015 16:06:17 +0200 Subject: Keep track of {}-balance in addition to ()-balance in expressions This allows us, for example, to use brace-initializer syntax. --- odb/pragma.cxx | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/odb/pragma.cxx b/odb/pragma.cxx index 11e1d4e..9bf38c5 100644 --- a/odb/pragma.cxx +++ b/odb/pragma.cxx @@ -163,9 +163,9 @@ parse_expression (cxx_lexer& l, string const& prag) { // Keep reading tokens until we see a mis-matching ')' or ',' while - // keeping track of the '()' balance. + // keeping track of the '()' and '{}' balance. // - size_t balance (0); + size_t p_balance (0), b_balance (0); for (; tt != CPP_EOF; tt = l.next (tl, &tn)) { @@ -174,22 +174,32 @@ parse_expression (cxx_lexer& l, switch (tt) { + case CPP_OPEN_BRACE: + { + b_balance++; + break; + } + case CPP_CLOSE_BRACE: + { + b_balance--; + break; + } case CPP_OPEN_PAREN: { - balance++; + p_balance++; break; } case CPP_CLOSE_PAREN: { - if (balance == 0) + if (p_balance == 0 && b_balance == 0) done = true; else - balance--; + p_balance--; break; } case CPP_COMMA: { - if (balance == 0) + if (p_balance == 0 && b_balance == 0) done = true; else break; -- cgit v1.1