summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/query.cc13
-rw-r--r--src/query.h2
2 files changed, 15 insertions, 0 deletions
diff --git a/src/query.cc b/src/query.cc
index 705ba151..a157b4d1 100644
--- a/src/query.cc
+++ b/src/query.cc
@@ -36,6 +36,17 @@
namespace ledger {
+// TODO: Extend this to handle all characters which define enclosures
+bool query_t::lexer_t::unbalanced_braces(string str) {
+ int balance = 0;
+ for (char& c : str) {
+ if (c == '(') ++balance;
+ else if (c == ')')
+ if (--balance < 0) return true;
+ }
+ return balance != 0;
+}
+
query_t::lexer_t::token_t
query_t::lexer_t::next_token(query_t::lexer_t::token_t::kind_t tok_context)
{
@@ -157,6 +168,8 @@ query_t::lexer_t::next_token(query_t::lexer_t::token_t::kind_t tok_context)
break;
case ')':
+ if (unbalanced_braces(ident))
+ consume_next = true;
if (! consume_next && tok_context == token_t::TOK_EXPR)
goto test_ident;
// fall through...
diff --git a/src/query.h b/src/query.h
index 20a7bc18..581c7533 100644
--- a/src/query.h
+++ b/src/query.h
@@ -231,6 +231,8 @@ public:
token_cache = next_token(tok_context);
return token_cache;
}
+
+ bool unbalanced_braces(const string str);
};
enum kind_t {