Skip to content
Snippets Groups Projects
Commit b44dc138 authored by Marco Biasini's avatar Marco Biasini
Browse files

also parse queries like 'aname=?G' correctly

parent d0d84227
Branches
Tags
No related merge requests found
......@@ -155,15 +155,20 @@ bool is_ident_or_str(char c) {
QueryToken QueryLexer::LexIdentOrStringToken() {
static IdentTokens ident_tokens;
size_t start=current_;
bool force_string=false;
while (current_<query_string_.length() &&
is_ident_or_str(query_string_[current_])) {
if (query_string_[current_]=='*' || query_string_[current_]=='?') {
force_string=true;
}
current_++;
}
String ident=query_string_.substr(start, current_-start);
if (tok::Type* t=find(ident_tokens, ident.c_str())) {
return QueryToken(Range(start, current_-start), *t);
}
return QueryToken(Range(start, current_-start), tok::Identifier);
return QueryToken(Range(start, current_-start),
force_string? tok::String : tok::Identifier);
}
QueryToken QueryLexer::LexToken() {
......@@ -174,7 +179,7 @@ QueryToken QueryLexer::LexToken() {
if (isdigit(current_char) || current_char=='-') {
return this->LexNumericToken();
}
if (isalpha(current_char)) {
if (isalpha(current_char) || current_char=='?' || current_char=='*') {
return this->LexIdentOrStringToken();
}
switch (current_char) {
......
......@@ -123,6 +123,8 @@ BOOST_AUTO_TEST_CASE(test_query_parse_properties)
BOOST_CHECK(Query("grtest:2=8").IsValid());
BOOST_CHECK(Query("gctest:3.0=9").IsValid());
BOOST_CHECK(Query("anita=3").IsValid()==false);
BOOST_CHECK(Query("gc*test=3").IsValid()==false);
BOOST_CHECK(Query("gc?test=3").IsValid()==false);
}
BOOST_AUTO_TEST_CASE(test_query_parse_value_type)
......@@ -279,8 +281,10 @@ BOOST_AUTO_TEST_CASE(test_glob)
ensure_counts(e, "rname=ARG and aname=N?1", 1, 1, 1);
ensure_counts(e, "rname=ARG and aname=NH?", 1, 1, 2);
ensure_counts(e, "rname=ARG and aname=\"*2\"", 1, 1, 1);
ensure_counts(e, "rname=ARG and aname=*2", 1, 1, 1);
ensure_counts(e, "rname=ARG and aname=N?", 1, 1, 1);
ensure_counts(e, "rname=LEU and aname=\"?D?\"", 1, 1, 2);
ensure_counts(e, "rname=LEU and aname=?D?", 1, 1, 2);
}
BOOST_AUTO_TEST_SUITE_END()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment