diff options
author | John Wiegley <johnw@newartisans.com> | 2011-11-10 01:26:38 -0600 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2011-11-10 01:26:38 -0600 |
commit | f4fd2ab1e5b2b409aade83cc91541314b723ea13 (patch) | |
tree | 9c4b95ae78384b3327efd93f9880e90aaace27f6 /src/query.cc | |
parent | 37e9ec8030a2634cbe9b2727f4d5530a582292c7 (diff) | |
download | fork-ledger-f4fd2ab1e5b2b409aade83cc91541314b723ea13.tar.gz fork-ledger-f4fd2ab1e5b2b409aade83cc91541314b723ea13.tar.bz2 fork-ledger-f4fd2ab1e5b2b409aade83cc91541314b723ea13.zip |
Corrections to the query language parser
Fixes #552
Diffstat (limited to 'src/query.cc')
-rw-r--r-- | src/query.cc | 19 |
1 files changed, 14 insertions, 5 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: |