summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/query.cc19
-rw-r--r--src/query.h2
-rw-r--r--src/token.cc4
3 files changed, 16 insertions, 9 deletions
diff --git a/src/query.cc b/src/query.cc
index 5c11add5..365c14f7 100644
--- a/src/query.cc
+++ b/src/query.cc
@@ -36,7 +36,8 @@
namespace ledger {
-query_t::lexer_t::token_t query_t::lexer_t::next_token()
+query_t::lexer_t::token_t
+query_t::lexer_t::next_token(query_t::lexer_t::token_t::kind_t tok_context)
{
if (token_cache.kind != token_t::UNKNOWN) {
token_t tok = token_cache;
@@ -108,8 +109,16 @@ query_t::lexer_t::token_t query_t::lexer_t::next_token()
return next_token();
goto resume;
- case '(': ++arg_i; return token_t(token_t::LPAREN);
- case ')': ++arg_i; return token_t(token_t::RPAREN);
+ case '(':
+ ++arg_i;
+ if (tok_context == token_t::TOK_EXPR)
+ consume_whitespace = true;
+ return token_t(token_t::LPAREN);
+ case ')':
+ ++arg_i;
+ if (tok_context == token_t::TOK_EXPR)
+ consume_whitespace = false;
+ return token_t(token_t::RPAREN);
case '&': ++arg_i; return token_t(token_t::TOK_AND);
case '|': ++arg_i; return token_t(token_t::TOK_OR);
case '!': ++arg_i; return token_t(token_t::TOK_NOT);
@@ -118,7 +127,7 @@ query_t::lexer_t::token_t query_t::lexer_t::next_token()
case '%': ++arg_i; return token_t(token_t::TOK_META);
case '=':
++arg_i;
- consume_next_arg = true;
+ consume_next = true;
return token_t(token_t::TOK_EQ);
case '\\':
@@ -247,7 +256,7 @@ query_t::parser_t::parse_query_term(query_t::lexer_t::token_t::kind_t tok_contex
{
expr_t::ptr_op_t node;
- lexer_t::token_t tok = lexer.next_token();
+ lexer_t::token_t tok = lexer.next_token(tok_context);
switch (tok.kind) {
case lexer_t::token_t::TOK_SHOW:
case lexer_t::token_t::TOK_ONLY:
diff --git a/src/query.h b/src/query.h
index b5b3b0fc..502ea445 100644
--- a/src/query.h
+++ b/src/query.h
@@ -222,7 +222,7 @@ public:
TRACE_DTOR(query_t::lexer_t);
}
- token_t next_token();
+ token_t next_token(token_t::kind_t tok_context = token_t::UNKNOWN);
void push_token(token_t tok) {
assert(token_cache.kind == token_t::UNKNOWN);
token_cache = tok;
diff --git a/src/token.cc b/src/token.cc
index fc7f73ee..fe7ce7cd 100644
--- a/src/token.cc
+++ b/src/token.cc
@@ -229,7 +229,6 @@ void expr_t::token_t::next(std::istream& in, const parse_flags_t& pflags)
break;
}
-#if 0
case '{': {
in.get(c);
amount_t temp;
@@ -242,7 +241,6 @@ void expr_t::token_t::next(std::istream& in, const parse_flags_t& pflags)
value = temp;
break;
}
-#endif
case '!':
in.get(c);
@@ -426,7 +424,7 @@ void expr_t::token_t::next(std::istream& in, const parse_flags_t& pflags)
throw_(parse_error, _("Failed to reset input stream"));
c = static_cast<char>(in.peek());
- if (std::isdigit(c) || c == '.')
+ if (! std::isalpha(c))
expected('\0', c);
parse_ident(in);