diff options
author | John Wiegley <johnw@newartisans.com> | 2010-06-01 18:32:27 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-06-01 18:33:13 -0400 |
commit | 5cdd36f358dcafddd29e7a6c5e0d8210b65bfd79 (patch) | |
tree | 19a51d0df2e3b67e0db2a1fc11eccde5da398883 /src/query.cc | |
parent | 038c24357e85b3b33460f3b8d41b1ef4ab0ed901 (diff) | |
download | fork-ledger-5cdd36f358dcafddd29e7a6c5e0d8210b65bfd79.tar.gz fork-ledger-5cdd36f358dcafddd29e7a6c5e0d8210b65bfd79.tar.bz2 fork-ledger-5cdd36f358dcafddd29e7a6c5e0d8210b65bfd79.zip |
Further improved parsing of query expressions
Fixes #210 / D4C2DD6F-8967-4FFC-BBBC-A941F9C53475
Diffstat (limited to 'src/query.cc')
-rw-r--r-- | src/query.cc | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/src/query.cc b/src/query.cc index c79fe1c2..363c6f73 100644 --- a/src/query.cc +++ b/src/query.cc @@ -53,25 +53,9 @@ query_t::lexer_t::token_t query_t::lexer_t::next_token() } } - if (consume_next_arg) { - consume_next_arg = false; - token_t tok(token_t::TERM, string(arg_i, arg_end)); - arg_i = arg_end; - return tok; - } - - resume: - bool consume_next = false; switch (*arg_i) { - case ' ': - case '\t': - case '\r': - case '\n': - if (++arg_i == arg_end) - return next_token(); - goto resume; - case '\'': + case '"': case '/': { string pat; char closing = *arg_i; @@ -95,6 +79,25 @@ query_t::lexer_t::token_t query_t::lexer_t::next_token() return token_t(token_t::TERM, pat); } + } + + if (multiple_args && consume_next_arg) { + consume_next_arg = false; + token_t tok(token_t::TERM, string(arg_i, arg_end)); + arg_i = arg_end; + return tok; + } + + resume: + bool consume_next = false; + switch (*arg_i) { + case ' ': + case '\t': + case '\r': + case '\n': + if (++arg_i == arg_end) + return next_token(); + goto resume; case '(': ++arg_i; return token_t(token_t::LPAREN); case ')': ++arg_i; return token_t(token_t::RPAREN); @@ -104,7 +107,10 @@ query_t::lexer_t::token_t query_t::lexer_t::next_token() case '@': ++arg_i; return token_t(token_t::TOK_PAYEE); case '#': ++arg_i; return token_t(token_t::TOK_CODE); case '%': ++arg_i; return token_t(token_t::TOK_META); - case '=': ++arg_i; return token_t(token_t::TOK_EQ); + case '=': + ++arg_i; + consume_next_arg = true; + return token_t(token_t::TOK_EQ); case '\\': consume_next = true; |