Added disabled feature: "date" keyword in queries
This commit is contained in:
parent
5e3f3d7f47
commit
b2e9cf4ebe
2 changed files with 77 additions and 28 deletions
|
|
@ -147,16 +147,16 @@ query_lexer_t::token_t query_lexer_t::next_token()
|
||||||
return token_t(token_t::TOK_OR);
|
return token_t(token_t::TOK_OR);
|
||||||
else if (ident == "not")
|
else if (ident == "not")
|
||||||
return token_t(token_t::TOK_NOT);
|
return token_t(token_t::TOK_NOT);
|
||||||
else if (ident == "account")
|
else if (ident == "code")
|
||||||
return token_t(token_t::TOK_ACCOUNT);
|
return token_t(token_t::TOK_CODE);
|
||||||
else if (ident == "desc")
|
else if (ident == "desc")
|
||||||
return token_t(token_t::TOK_PAYEE);
|
return token_t(token_t::TOK_PAYEE);
|
||||||
else if (ident == "payee")
|
else if (ident == "payee")
|
||||||
return token_t(token_t::TOK_PAYEE);
|
return token_t(token_t::TOK_PAYEE);
|
||||||
else if (ident == "code")
|
|
||||||
return token_t(token_t::TOK_CODE);
|
|
||||||
else if (ident == "note")
|
else if (ident == "note")
|
||||||
return token_t(token_t::TOK_NOTE);
|
return token_t(token_t::TOK_NOTE);
|
||||||
|
else if (ident == "account")
|
||||||
|
return token_t(token_t::TOK_ACCOUNT);
|
||||||
else if (ident == "tag")
|
else if (ident == "tag")
|
||||||
return token_t(token_t::TOK_META);
|
return token_t(token_t::TOK_META);
|
||||||
else if (ident == "meta")
|
else if (ident == "meta")
|
||||||
|
|
@ -169,9 +169,16 @@ query_lexer_t::token_t query_lexer_t::next_token()
|
||||||
DEBUG("pred.show", "string = " << (*begin).as_string());
|
DEBUG("pred.show", "string = " << (*begin).as_string());
|
||||||
return token_t(token_t::END_REACHED);
|
return token_t(token_t::END_REACHED);
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
|
// jww (2009-11-06): This is disabled for the time being.
|
||||||
|
else if (ident == "date") {
|
||||||
|
// The date keyword takes the whole of the next string as its argument.
|
||||||
|
consume_whitespace = true;
|
||||||
|
return token_t(token_t::TOK_DATE);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
else if (ident == "expr") {
|
else if (ident == "expr") {
|
||||||
// The expr keyword takes the whole of the next string as its
|
// The expr keyword takes the whole of the next string as its argument.
|
||||||
// argument.
|
|
||||||
consume_whitespace = true;
|
consume_whitespace = true;
|
||||||
return token_t(token_t::TOK_EXPR);
|
return token_t(token_t::TOK_EXPR);
|
||||||
}
|
}
|
||||||
|
|
@ -227,10 +234,11 @@ query_parser_t::parse_query_term(query_lexer_t::token_t::kind_t tok_context)
|
||||||
case query_lexer_t::token_t::END_REACHED:
|
case query_lexer_t::token_t::END_REACHED:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case query_lexer_t::token_t::TOK_ACCOUNT:
|
case query_lexer_t::token_t::TOK_DATE:
|
||||||
case query_lexer_t::token_t::TOK_PAYEE:
|
|
||||||
case query_lexer_t::token_t::TOK_CODE:
|
case query_lexer_t::token_t::TOK_CODE:
|
||||||
|
case query_lexer_t::token_t::TOK_PAYEE:
|
||||||
case query_lexer_t::token_t::TOK_NOTE:
|
case query_lexer_t::token_t::TOK_NOTE:
|
||||||
|
case query_lexer_t::token_t::TOK_ACCOUNT:
|
||||||
case query_lexer_t::token_t::TOK_META:
|
case query_lexer_t::token_t::TOK_META:
|
||||||
case query_lexer_t::token_t::TOK_EXPR:
|
case query_lexer_t::token_t::TOK_EXPR:
|
||||||
node = parse_query_term(tok.kind);
|
node = parse_query_term(tok.kind);
|
||||||
|
|
@ -241,16 +249,54 @@ query_parser_t::parse_query_term(query_lexer_t::token_t::kind_t tok_context)
|
||||||
|
|
||||||
case query_lexer_t::token_t::TERM:
|
case query_lexer_t::token_t::TERM:
|
||||||
assert(tok.value);
|
assert(tok.value);
|
||||||
if (tok_context == query_lexer_t::token_t::TOK_META) {
|
switch (tok_context) {
|
||||||
|
case query_lexer_t::token_t::TOK_DATE: {
|
||||||
|
expr_t::ptr_op_t ident = new expr_t::op_t(expr_t::op_t::IDENT);
|
||||||
|
ident->set_ident("date");
|
||||||
|
|
||||||
|
date_interval_t interval(*tok.value);
|
||||||
|
|
||||||
|
if (interval.start) {
|
||||||
|
node = new expr_t::op_t(expr_t::op_t::O_GTE);
|
||||||
|
node->set_left(ident);
|
||||||
|
|
||||||
|
expr_t::ptr_op_t arg1 = new expr_t::op_t(expr_t::op_t::VALUE);
|
||||||
|
arg1->set_value(*interval.start);
|
||||||
|
node->set_right(arg1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (interval.end) {
|
||||||
|
expr_t::ptr_op_t lt = new expr_t::op_t(expr_t::op_t::O_LT);
|
||||||
|
lt->set_left(ident);
|
||||||
|
|
||||||
|
expr_t::ptr_op_t arg1 = new expr_t::op_t(expr_t::op_t::VALUE);
|
||||||
|
arg1->set_value(*interval.end);
|
||||||
|
lt->set_right(arg1);
|
||||||
|
|
||||||
|
if (node) {
|
||||||
|
expr_t::ptr_op_t prev(node);
|
||||||
|
node = new expr_t::op_t(expr_t::op_t::O_AND);
|
||||||
|
node->set_left(prev);
|
||||||
|
node->set_right(lt);
|
||||||
|
} else {
|
||||||
|
node = lt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case query_lexer_t::token_t::TOK_EXPR:
|
||||||
|
node = expr_t(*tok.value).get_op();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case query_lexer_t::token_t::TOK_META: {
|
||||||
node = new expr_t::op_t(expr_t::op_t::O_CALL);
|
node = new expr_t::op_t(expr_t::op_t::O_CALL);
|
||||||
|
|
||||||
expr_t::ptr_op_t ident;
|
expr_t::ptr_op_t ident = new expr_t::op_t(expr_t::op_t::IDENT);
|
||||||
ident = new expr_t::op_t(expr_t::op_t::IDENT);
|
|
||||||
ident->set_ident("has_tag");
|
ident->set_ident("has_tag");
|
||||||
node->set_left(ident);
|
node->set_left(ident);
|
||||||
|
|
||||||
expr_t::ptr_op_t arg1;
|
expr_t::ptr_op_t arg1 = new expr_t::op_t(expr_t::op_t::VALUE);
|
||||||
arg1 = new expr_t::op_t(expr_t::op_t::VALUE);
|
|
||||||
arg1->set_value(mask_t(*tok.value));
|
arg1->set_value(mask_t(*tok.value));
|
||||||
|
|
||||||
tok = lexer.peek_token();
|
tok = lexer.peek_token();
|
||||||
|
|
@ -261,11 +307,9 @@ query_parser_t::parse_query_term(query_lexer_t::token_t::kind_t tok_context)
|
||||||
throw_(parse_error,
|
throw_(parse_error,
|
||||||
_("Metadata equality operator not followed by term"));
|
_("Metadata equality operator not followed by term"));
|
||||||
|
|
||||||
expr_t::ptr_op_t cons;
|
expr_t::ptr_op_t cons = new expr_t::op_t(expr_t::op_t::O_CONS);
|
||||||
cons = new expr_t::op_t(expr_t::op_t::O_CONS);
|
|
||||||
|
|
||||||
expr_t::ptr_op_t arg2;
|
expr_t::ptr_op_t arg2 = new expr_t::op_t(expr_t::op_t::VALUE);
|
||||||
arg2 = new expr_t::op_t(expr_t::op_t::VALUE);
|
|
||||||
assert(tok.value);
|
assert(tok.value);
|
||||||
arg2->set_value(mask_t(*tok.value));
|
arg2->set_value(mask_t(*tok.value));
|
||||||
|
|
||||||
|
|
@ -275,11 +319,13 @@ query_parser_t::parse_query_term(query_lexer_t::token_t::kind_t tok_context)
|
||||||
} else {
|
} else {
|
||||||
node->set_right(arg1);
|
node->set_right(arg1);
|
||||||
}
|
}
|
||||||
} else {
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
node = new expr_t::op_t(expr_t::op_t::O_MATCH);
|
node = new expr_t::op_t(expr_t::op_t::O_MATCH);
|
||||||
|
|
||||||
expr_t::ptr_op_t ident;
|
expr_t::ptr_op_t ident = new expr_t::op_t(expr_t::op_t::IDENT);
|
||||||
ident = new expr_t::op_t(expr_t::op_t::IDENT);
|
|
||||||
switch (tok_context) {
|
switch (tok_context) {
|
||||||
case query_lexer_t::token_t::TOK_ACCOUNT:
|
case query_lexer_t::token_t::TOK_ACCOUNT:
|
||||||
ident->set_ident("account"); break;
|
ident->set_ident("account"); break;
|
||||||
|
|
@ -293,13 +339,13 @@ query_parser_t::parse_query_term(query_lexer_t::token_t::kind_t tok_context)
|
||||||
assert(0); break;
|
assert(0); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
expr_t::ptr_op_t mask;
|
expr_t::ptr_op_t mask = new expr_t::op_t(expr_t::op_t::VALUE);
|
||||||
mask = new expr_t::op_t(expr_t::op_t::VALUE);
|
|
||||||
mask->set_value(mask_t(*tok.value));
|
mask->set_value(mask_t(*tok.value));
|
||||||
|
|
||||||
node->set_left(ident);
|
node->set_left(ident);
|
||||||
node->set_right(mask);
|
node->set_right(mask);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case query_lexer_t::token_t::LPAREN:
|
case query_lexer_t::token_t::LPAREN:
|
||||||
|
|
|
||||||
|
|
@ -135,10 +135,11 @@ public:
|
||||||
TOK_OR,
|
TOK_OR,
|
||||||
TOK_EQ,
|
TOK_EQ,
|
||||||
|
|
||||||
TOK_ACCOUNT,
|
TOK_DATE,
|
||||||
TOK_PAYEE,
|
|
||||||
TOK_CODE,
|
TOK_CODE,
|
||||||
|
TOK_PAYEE,
|
||||||
TOK_NOTE,
|
TOK_NOTE,
|
||||||
|
TOK_ACCOUNT,
|
||||||
TOK_META,
|
TOK_META,
|
||||||
TOK_EXPR,
|
TOK_EXPR,
|
||||||
|
|
||||||
|
|
@ -184,10 +185,11 @@ public:
|
||||||
case TOK_AND: return "TOK_AND";
|
case TOK_AND: return "TOK_AND";
|
||||||
case TOK_OR: return "TOK_OR";
|
case TOK_OR: return "TOK_OR";
|
||||||
case TOK_EQ: return "TOK_EQ";
|
case TOK_EQ: return "TOK_EQ";
|
||||||
case TOK_ACCOUNT: return "TOK_ACCOUNT";
|
case TOK_DATE: return "TOK_DATE";
|
||||||
case TOK_PAYEE: return "TOK_PAYEE";
|
|
||||||
case TOK_CODE: return "TOK_CODE";
|
case TOK_CODE: return "TOK_CODE";
|
||||||
|
case TOK_PAYEE: return "TOK_PAYEE";
|
||||||
case TOK_NOTE: return "TOK_NOTE";
|
case TOK_NOTE: return "TOK_NOTE";
|
||||||
|
case TOK_ACCOUNT: return "TOK_ACCOUNT";
|
||||||
case TOK_META: return "TOK_META";
|
case TOK_META: return "TOK_META";
|
||||||
case TOK_EXPR: return "TOK_EXPR";
|
case TOK_EXPR: return "TOK_EXPR";
|
||||||
case TERM: return string("TERM(") + *value + ")";
|
case TERM: return string("TERM(") + *value + ")";
|
||||||
|
|
@ -203,10 +205,11 @@ public:
|
||||||
case TOK_AND: return "and";
|
case TOK_AND: return "and";
|
||||||
case TOK_OR: return "or";
|
case TOK_OR: return "or";
|
||||||
case TOK_EQ: return "=";
|
case TOK_EQ: return "=";
|
||||||
case TOK_ACCOUNT: return "account";
|
case TOK_DATE: return "date";
|
||||||
case TOK_PAYEE: return "payee";
|
|
||||||
case TOK_CODE: return "code";
|
case TOK_CODE: return "code";
|
||||||
|
case TOK_PAYEE: return "payee";
|
||||||
case TOK_NOTE: return "note";
|
case TOK_NOTE: return "note";
|
||||||
|
case TOK_ACCOUNT: return "account";
|
||||||
case TOK_META: return "meta";
|
case TOK_META: return "meta";
|
||||||
case TOK_EXPR: return "expr";
|
case TOK_EXPR: return "expr";
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue