summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/query.cc13
-rw-r--r--src/query.h2
-rw-r--r--test/regress/1182_3.test14
3 files changed, 29 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 {
diff --git a/test/regress/1182_3.test b/test/regress/1182_3.test
new file mode 100644
index 00000000..cc7cf06c
--- /dev/null
+++ b/test/regress/1182_3.test
@@ -0,0 +1,14 @@
+= expr has_tag('SecondTag')
+ Expenses:Cookies $1
+ $account -$1
+
+2004/05/27 Book Store
+ ; This note applies to all postings. :SecondTag:
+ Expenses:Books 20 BOOK @ $10
+ ; Metadata: Some Value
+ ; Typed:: $100 + $200
+ ; :ExampleTag:
+ ; Here follows a note describing the posting.
+ Liabilities:MasterCard $-200.00
+
+test bal Expenses:Cookies -> 0