diff options
author | John Wiegley <johnw@newartisans.com> | 2011-11-10 17:28:24 -0600 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2011-11-10 17:28:24 -0600 |
commit | c2c11d43ca14aad1884ab6efc4637245a4c16746 (patch) | |
tree | 4294a205e76c196a2c05674e3ba774edd83ad730 /src/query.cc | |
parent | f4fd2ab1e5b2b409aade83cc91541314b723ea13 (diff) | |
download | fork-ledger-c2c11d43ca14aad1884ab6efc4637245a4c16746.tar.gz fork-ledger-c2c11d43ca14aad1884ab6efc4637245a4c16746.tar.bz2 fork-ledger-c2c11d43ca14aad1884ab6efc4637245a4c16746.zip |
More report query fixes
Diffstat (limited to 'src/query.cc')
-rw-r--r-- | src/query.cc | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/src/query.cc b/src/query.cc index 365c14f7..b0f8d691 100644 --- a/src/query.cc +++ b/src/query.cc @@ -106,7 +106,7 @@ query_t::lexer_t::next_token(query_t::lexer_t::token_t::kind_t tok_context) case '\r': case '\n': if (++arg_i == arg_end) - return next_token(); + return next_token(tok_context); goto resume; case '(': @@ -152,8 +152,10 @@ query_t::lexer_t::next_token(query_t::lexer_t::token_t::kind_t tok_context) ident.push_back(*arg_i); break; - case '(': case ')': + if (! consume_next && tok_context == token_t::TOK_EXPR) + goto test_ident; + case '(': case '&': case '|': case '!': @@ -161,7 +163,7 @@ query_t::lexer_t::next_token(query_t::lexer_t::token_t::kind_t tok_context) case '#': case '%': case '=': - if (! consume_next) + if (! consume_next && tok_context != token_t::TOK_EXPR) goto test_ident; // fall through... default: @@ -297,10 +299,10 @@ query_t::parser_t::parse_query_term(query_t::lexer_t::token_t::kind_t tok_contex expr_t::ptr_op_t arg1 = new expr_t::op_t(expr_t::op_t::VALUE); arg1->set_value(mask_t(*tok.value)); - tok = lexer.peek_token(); + tok = lexer.peek_token(tok_context); if (tok.kind == lexer_t::token_t::TOK_EQ) { - tok = lexer.next_token(); - tok = lexer.next_token(); + tok = lexer.next_token(tok_context); + tok = lexer.next_token(tok_context); if (tok.kind != lexer_t::token_t::TERM) throw_(parse_error, _("Metadata equality operator not followed by term")); @@ -349,7 +351,7 @@ query_t::parser_t::parse_query_term(query_t::lexer_t::token_t::kind_t tok_contex case lexer_t::token_t::LPAREN: node = parse_query_expr(tok_context, true); - tok = lexer.next_token(); + tok = lexer.next_token(tok_context); if (tok.kind != lexer_t::token_t::RPAREN) tok.expected(')'); break; @@ -367,7 +369,7 @@ query_t::parser_t::parse_unary_expr(lexer_t::token_t::kind_t tok_context) { 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_NOT: { expr_t::ptr_op_t term(parse_query_term(tok_context)); @@ -394,7 +396,7 @@ query_t::parser_t::parse_and_expr(lexer_t::token_t::kind_t tok_context) { if (expr_t::ptr_op_t node = parse_unary_expr(tok_context)) { while (true) { - lexer_t::token_t tok = lexer.next_token(); + lexer_t::token_t tok = lexer.next_token(tok_context); if (tok.kind == lexer_t::token_t::TOK_AND) { expr_t::ptr_op_t prev(node); node = new expr_t::op_t(expr_t::op_t::O_AND); @@ -418,7 +420,7 @@ query_t::parser_t::parse_or_expr(lexer_t::token_t::kind_t tok_context) { if (expr_t::ptr_op_t node = parse_and_expr(tok_context)) { while (true) { - lexer_t::token_t tok = lexer.next_token(); + lexer_t::token_t tok = lexer.next_token(tok_context); if (tok.kind == lexer_t::token_t::TOK_OR) { expr_t::ptr_op_t prev(node); node = new expr_t::op_t(expr_t::op_t::O_OR); @@ -460,13 +462,13 @@ query_t::parser_t::parse_query_expr(lexer_t::token_t::kind_t tok_context, (query_map_t::value_type (QUERY_LIMIT, predicate_t(limiter, what_to_keep).print_to_str())); - lexer_t::token_t tok = lexer.peek_token(); + lexer_t::token_t tok = lexer.peek_token(tok_context); while (tok.kind != lexer_t::token_t::END_REACHED) { switch (tok.kind) { case lexer_t::token_t::TOK_SHOW: case lexer_t::token_t::TOK_ONLY: case lexer_t::token_t::TOK_BOLD: { - lexer.next_token(); + lexer.next_token(tok_context); kind_t kind; switch (tok.kind) { @@ -505,7 +507,7 @@ query_t::parser_t::parse_query_expr(lexer_t::token_t::kind_t tok_context, case lexer_t::token_t::TOK_FOR: case lexer_t::token_t::TOK_SINCE: case lexer_t::token_t::TOK_UNTIL: { - tok = lexer.next_token(); + tok = lexer.next_token(tok_context); string for_string; @@ -515,10 +517,10 @@ query_t::parser_t::parse_query_expr(lexer_t::token_t::kind_t tok_context, for_string = "until"; lexer.consume_next_arg = true; - tok = lexer.peek_token(); + tok = lexer.peek_token(tok_context); while (tok.kind != lexer_t::token_t::END_REACHED) { - tok = lexer.next_token(); + tok = lexer.next_token(tok_context); assert(tok.kind == lexer_t::token_t::TERM); if (*tok.value == "show" || *tok.value == "bold" || @@ -535,7 +537,7 @@ query_t::parser_t::parse_query_expr(lexer_t::token_t::kind_t tok_context, for_string += *tok.value; lexer.consume_next_arg = true; - tok = lexer.peek_token(); + tok = lexer.peek_token(tok_context); } if (! for_string.empty()) @@ -547,7 +549,7 @@ query_t::parser_t::parse_query_expr(lexer_t::token_t::kind_t tok_context, goto done; } - tok = lexer.peek_token(); + tok = lexer.peek_token(tok_context); } done: ; |