From 9ddbdf848f115043940d3e2edc72d434ebd53a0d Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 12 Apr 2013 14:16:37 +0200 Subject: [PATCH] Revert "Remove HDCQL functionality" This reverts commit 9084e20f4c5ffad9cfea2087396206b75a3a6654. --- src/cql.y | 36 ++++++++++++++++++++++++++++++++---- src/cql2ccl.c | 43 +++++++++++++++++++++++++++---------------- src/cqltransform.c | 23 +++++++++++++++++++++-- src/xcqlutil.c | 10 ++++++++++ test/cql/11.1.err | 1 - test/cql/11.1.out | 8 ++++++++ test/cql/11.2.out | 6 ++++-- test/cql/11.3.err | 1 - test/cql/11.3.out | 8 ++++++++ test/cql/11.4.out | 6 ++++-- test/cql/11.5.err | 1 - test/cql/11.5.out | 8 ++++++++ test/cql/11.7.err | 1 - test/cql/11.7.out | 26 ++++++++++++++++++++++++++ test/cql2pqf/1.2.err | 1 - test/cql2pqf/1.2.out | 1 + test/test_cql2ccl.c | 8 +++++++- 17 files changed, 156 insertions(+), 32 deletions(-) diff --git a/src/cql.y b/src/cql.y index 67e2f76..ea828dc 100644 --- a/src/cql.y +++ b/src/cql.y @@ -56,7 +56,7 @@ %} %pure_parser -%token SIMPLE_STRING AND OR NOT PROX GE LE NE EXACT SORTBY +%token PREFIX_NAME SIMPLE_STRING AND OR NOT PROX GE LE NE EXACT SORTBY %% @@ -145,12 +145,12 @@ searchClause: $$.cql = $3.cql; } | -searchTerm { +searchTerm extraTerms { struct cql_node *st = cql_node_dup(((CQL_parser) parm)->nmem, $0.rel); + st->u.st.extra_terms = $2.cql; st->u.st.term = nmem_strdup(((CQL_parser)parm)->nmem, $1.buf); $$.cql = st; } - | index relation modifiers { $$.rel = cql_node_mk_sc(((CQL_parser) parm)->nmem, $1.buf, $2.buf, 0); @@ -161,6 +161,18 @@ searchTerm { } ; +extraTerms: +SIMPLE_STRING extraTerms { + struct cql_node *st = cql_node_mk_sc(((CQL_parser) parm)->nmem, + /* index */ 0, /* rel */ 0, $1.buf); + st->u.st.extra_terms = $2.cql; + $$.cql = st; +} +| +{ $$.cql = 0; } +; + + /* unary NOT search SIMPLE_STRING here .. */ boolean: @@ -189,7 +201,7 @@ modifiers '/' searchTerm relation_symbol searchTerm } ; -relation: SIMPLE_STRING | relation_symbol; +relation: PREFIX_NAME | relation_symbol; relation_symbol: '=' @@ -206,6 +218,7 @@ index: searchTerm: SIMPLE_STRING +| PREFIX_NAME | AND | OR | NOT @@ -325,8 +338,11 @@ int yylex(YYSTYPE *lval, void *vp) } else { + int relation_like = 0; while (c != 0 && !strchr(" \n()=<>/", c)) { + if (c == '.') + relation_like = 1; if (c == '\\') { putb(lval, cp, c); @@ -368,6 +384,18 @@ int yylex(YYSTYPE *lval, void *vp) lval->buf = "sortby"; return SORTBY; } + if (!cql_strcmp(lval->buf, "all")) + relation_like = 1; + if (!cql_strcmp(lval->buf, "any")) + relation_like = 1; + if (!cql_strcmp(lval->buf, "adj")) + relation_like = 1; + if (!cql_strcmp(lval->buf, "within")) + relation_like = 1; + if (!cql_strcmp(lval->buf, "encloses")) + relation_like = 1; + if (relation_like) + return PREFIX_NAME; } return SIMPLE_STRING; } diff --git a/src/cql2ccl.c b/src/cql2ccl.c index 331b6db..81e2c5f 100644 --- a/src/cql2ccl.c +++ b/src/cql2ccl.c @@ -91,7 +91,6 @@ static int node(struct cql_node *cn, const char *split_op = 0; const char *ccl_rel = 0; const char *rel = cn->u.st.relation; - const char *cp; if (cn->u.st.index && strcmp(cn->u.st.index, "cql.serverChoice")) @@ -122,26 +121,38 @@ static int node(struct cql_node *cn, /* unsupported relation */ return -1; } - cp = cn->u.st.term; - while (1) + for (; cn; cn = cn->u.st.extra_terms) { - if (ccl_field && ccl_rel) + const char *cp = cn->u.st.term; + while (1) { - pr(ccl_field, client_data); - pr(ccl_rel, client_data); - if (!split_op) - ccl_rel = 0; + if (ccl_field && ccl_rel) + { + pr(ccl_field, client_data); + pr(ccl_rel, client_data); + if (!split_op) + ccl_rel = 0; + } + pr_term(&cp, split_op ? 1 : 0, pr, client_data); + while (*cp == ' ') + cp++; + if (*cp == '\0') + break; + pr(" ", client_data); + if (split_op) + { + pr(split_op, client_data); + pr(" ", client_data); + } } - pr_term(&cp, split_op ? 1 : 0, pr, client_data); - while (*cp == ' ') - cp++; - if (*cp == '\0') - break; - pr(" ", client_data); - if (split_op) + if (cn->u.st.extra_terms) { - pr(split_op, client_data); pr(" ", client_data); + if (split_op) + { + pr(split_op, client_data); + pr(" ", client_data); + } } } return 0; diff --git a/src/cqltransform.c b/src/cqltransform.c index 90dcb37..8253e50 100644 --- a/src/cqltransform.c +++ b/src/cqltransform.c @@ -762,10 +762,29 @@ static void emit_term(cql_transform_t ct, static void emit_terms(cql_transform_t ct, struct cql_node *cn, void (*pr)(const char *buf, void *client_data), - void *client_data) + void *client_data, + const char *op) { + struct cql_node *ne = cn->u.st.extra_terms; + if (ne) + { + (*pr)("@", client_data); + (*pr)(op, client_data); + (*pr)(" ", client_data); + } emit_term(ct, cn, cn->u.st.term, strlen(cn->u.st.term), pr, client_data); + for (; ne; ne = ne->u.st.extra_terms) + { + if (ne->u.st.extra_terms) + { + (*pr)("@", client_data); + (*pr)(op, client_data); + (*pr)(" ", client_data); + } + emit_term(ct, cn, ne->u.st.term, strlen(ne->u.st.term), + pr, client_data); + } } static void emit_wordlist(cql_transform_t ct, @@ -844,7 +863,7 @@ void cql_transform_r(cql_transform_t ct, else if (cn->u.st.relation && !cql_strcmp(cn->u.st.relation, "any")) emit_wordlist(ct, cn, pr, client_data, "or"); else - emit_terms(ct, cn, pr, client_data); + emit_terms(ct, cn, pr, client_data, "and"); break; case CQL_NODE_BOOL: (*pr)("@", client_data); diff --git a/src/xcqlutil.c b/src/xcqlutil.c index de6116c..fe75f0b 100644 --- a/src/xcqlutil.c +++ b/src/xcqlutil.c @@ -188,6 +188,16 @@ static void cql_to_xml_r(struct cql_node *cn, pr_cdata(cn->u.st.term, pr, client_data); pr_n("\n", pr, client_data, 0); } + if (cn->u.st.extra_terms) + { + struct cql_node *n = cn->u.st.extra_terms; + for (; n; n = n->u.st.extra_terms) + { + pr_n("", pr, client_data, level+2); + pr_cdata(n->u.st.term, pr, client_data); + pr_n("\n", pr, client_data, 0); + } + } cql_sort_to_xml(sort_node, pr, client_data, level+2); pr_n("\n", pr, client_data, level); break; diff --git a/test/cql/11.1.err b/test/cql/11.1.err index f83d884..e69de29 100644 --- a/test/cql/11.1.err +++ b/test/cql/11.1.err @@ -1 +0,0 @@ -Syntax error diff --git a/test/cql/11.1.out b/test/cql/11.1.out index e69de29..a8ff186 100644 --- a/test/cql/11.1.out +++ b/test/cql/11.1.out @@ -0,0 +1,8 @@ + + cql.serverChoice + + = + + a + b + diff --git a/test/cql/11.2.out b/test/cql/11.2.out index 88c7cb3..aaa51fb 100644 --- a/test/cql/11.2.out +++ b/test/cql/11.2.out @@ -1,7 +1,9 @@ - a + cql.serverChoice - b + = + a + b c diff --git a/test/cql/11.3.err b/test/cql/11.3.err index f83d884..e69de29 100644 --- a/test/cql/11.3.err +++ b/test/cql/11.3.err @@ -1 +0,0 @@ -Syntax error diff --git a/test/cql/11.3.out b/test/cql/11.3.out index e69de29..3a66149 100644 --- a/test/cql/11.3.out +++ b/test/cql/11.3.out @@ -0,0 +1,8 @@ + + cql.serverChoice + + = + + a.b + c + diff --git a/test/cql/11.4.out b/test/cql/11.4.out index b5c4126..ef54784 100644 --- a/test/cql/11.4.out +++ b/test/cql/11.4.out @@ -1,7 +1,9 @@ - and + cql.serverChoice - b + = + and + b c diff --git a/test/cql/11.5.err b/test/cql/11.5.err index f83d884..e69de29 100644 --- a/test/cql/11.5.err +++ b/test/cql/11.5.err @@ -1 +0,0 @@ -Syntax error diff --git a/test/cql/11.5.out b/test/cql/11.5.out index e69de29..50f2571 100644 --- a/test/cql/11.5.out +++ b/test/cql/11.5.out @@ -0,0 +1,8 @@ + + cql.serverChoice + + = + + all + a + diff --git a/test/cql/11.7.err b/test/cql/11.7.err index f83d884..e69de29 100644 --- a/test/cql/11.7.err +++ b/test/cql/11.7.err @@ -1 +0,0 @@ -Syntax error diff --git a/test/cql/11.7.out b/test/cql/11.7.out index e69de29..0d59eb1 100644 --- a/test/cql/11.7.out +++ b/test/cql/11.7.out @@ -0,0 +1,26 @@ + + + and + + + + cql.serverChoice + + = + + dc.title + a + b + c + + + + + cql.serverChoice + + = + + d + + + diff --git a/test/cql2pqf/1.2.err b/test/cql2pqf/1.2.err index f83d884..e69de29 100644 --- a/test/cql2pqf/1.2.err +++ b/test/cql2pqf/1.2.err @@ -1 +0,0 @@ -Syntax error diff --git a/test/cql2pqf/1.2.out b/test/cql2pqf/1.2.out index c4d2fb1..413ec53 100644 --- a/test/cql2pqf/1.2.out +++ b/test/cql2pqf/1.2.out @@ -1 +1,2 @@ Parsing CQL a b +@attr 6=1 @attr 2=3 @attr 4=1 @and @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "a" @attr 3=3 @attr 6=1 @attr 5=100 @attr 1=1016 "b" diff --git a/test/test_cql2ccl.c b/test/test_cql2ccl.c index 06a1c61..b52ad14 100644 --- a/test/test_cql2ccl.c +++ b/test/test_cql2ccl.c @@ -110,7 +110,8 @@ static void tst(void) YAZ_CHECK(tst_query("\\*", "\"*\"")); YAZ_CHECK(tst_query("\"\\*\"", "\"*\"")); - YAZ_CHECK(tst_query("\"a b\"", "\"a b\"")); + YAZ_CHECK(tst_query("a b", "\"a\" \"b\"")); + YAZ_CHECK(tst_query("ab bc", "\"ab\" \"bc\"")); YAZ_CHECK(tst_query("\\\\", "\"\\\\\"")); YAZ_CHECK(tst_query("\\\"", "\"\\\"\"")); @@ -130,12 +131,17 @@ static void tst(void) YAZ_CHECK(tst_query("title all \"\"", "title=\"\"")); YAZ_CHECK(tst_query("title all x", "title=\"x\"")); + YAZ_CHECK(tst_query("title all x y", "title=\"x\" and title=\"y\"")); YAZ_CHECK(tst_query("title all \"x y\"", "title=\"x\" and title=\"y\"")); YAZ_CHECK(tst_query("title any x", "title=\"x\"")); + YAZ_CHECK(tst_query("title any x y", "title=\"x\" or title=\"y\"")); YAZ_CHECK(tst_query("title any \"x y\"", "title=\"x\" or title=\"y\"")); YAZ_CHECK(tst_query("title = \"x y\"", "title=\"x y\"")); + YAZ_CHECK(tst_query("title = x y", "title=\"x\" \"y\"")); + + YAZ_CHECK(tst_query("title = x y z", "title=\"x\" \"y\" \"z\"")); YAZ_CHECK(tst_query("dc.title=encyclopedia prox dinosaurs", "(dc.title=\"encyclopedia\") % (\"dinosaurs\")")); -- 1.7.10.4