Corrections to the query language parser

Fixes #552
This commit is contained in:
John Wiegley 2011-11-10 01:26:38 -06:00
parent 37e9ec8030
commit f4fd2ab1e5
3 changed files with 16 additions and 9 deletions

View file

@ -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:

View file

@ -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;

View file

@ -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);