1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2013 Index Data
3 * See the file LICENSE for details.
7 * \brief Implements parsing of a CCL FIND query.
9 * This source file implements parsing of a CCL Query (ISO8777).
10 * The parser uses predictive parsing, but it does several tokens
11 * of lookahead in the handling of relational operations.. So
12 * it's not really pure.
24 /* returns type of current lookahead */
25 #define KIND (cclp->look_token->kind)
27 /* move one token forward */
28 #define ADVANCE cclp->look_token = cclp->look_token->next
31 * qual_val_type: test for existance of attribute type/value pair.
33 * type: Type of attribute to search for
34 * value: Value of attribute to seach for
35 * return: 1 if found; 0 otherwise.
37 static int qual_val_type(ccl_qualifier_t *qa, int type, int value,
44 for (i = 0; qa[i]; i++)
46 struct ccl_rpn_attr *q = ccl_qual_get_attr(qa[i]);
49 if (q->type == type && q->kind == CCL_RPN_ATTR_NUMERIC &&
50 q->value.numeric == value)
63 * strxcat: concatenate strings.
64 * n: Null-terminated Destination string
65 * src: Source string to be appended (not null-terminated)
66 * len: Length of source string.
68 static void strxcat(char *n, const char *src, int len)
78 * copy_token_name: Return copy of CCL token name
79 * tp: Pointer to token info.
80 * return: malloc(3) allocated copy of token name.
82 static char *copy_token_name(struct ccl_token *tp)
84 char *str = (char *)xmalloc(tp->len + 1);
86 memcpy(str, tp->name, tp->len);
92 * mk_node: Create RPN node.
94 * return: pointer to allocated node.
96 struct ccl_rpn_node *ccl_rpn_node_create(enum ccl_rpn_kind kind)
98 struct ccl_rpn_node *p;
99 p = (struct ccl_rpn_node *)xmalloc(sizeof(*p));
106 p->u.t.attr_list = 0;
117 * ccl_rpn_delete: Delete RPN tree.
118 * rpn: Pointer to tree.
120 void ccl_rpn_delete(struct ccl_rpn_node *rpn)
122 struct ccl_rpn_attr *attr, *attr1;
130 ccl_rpn_delete(rpn->u.p[0]);
131 ccl_rpn_delete(rpn->u.p[1]);
134 xfree(rpn->u.t.term);
135 xfree(rpn->u.t.qual);
136 for (attr = rpn->u.t.attr_list; attr; attr = attr1)
139 if (attr->kind == CCL_RPN_ATTR_STRING)
140 xfree(attr->value.str);
147 xfree(rpn->u.setname);
150 ccl_rpn_delete(rpn->u.p[0]);
151 ccl_rpn_delete(rpn->u.p[1]);
152 ccl_rpn_delete(rpn->u.p[2]);
158 static struct ccl_rpn_node *find_spec(CCL_parser cclp, ccl_qualifier_t *qa);
160 static int is_term_ok(int look, int *list)
162 for (;*list >= 0; list++)
168 static struct ccl_rpn_node *search_terms(CCL_parser cclp, ccl_qualifier_t *qa);
170 static struct ccl_rpn_attr *add_attr_node(struct ccl_rpn_node *p,
171 const char *set, int type)
173 struct ccl_rpn_attr *n;
175 n = (struct ccl_rpn_attr *)xmalloc(sizeof(*n));
178 n->set = xstrdup(set);
182 n->next = p->u.t.attr_list;
183 p->u.t.attr_list = n;
189 * add_attr_numeric: Add attribute (type/value) to RPN term node.
190 * p: RPN node of type term.
191 * type: Type of attribute
192 * value: Value of attribute
193 * set: Attribute set name
195 void ccl_add_attr_numeric(struct ccl_rpn_node *p, const char *set,
198 struct ccl_rpn_attr *n;
200 n = add_attr_node(p, set, type);
201 n->kind = CCL_RPN_ATTR_NUMERIC;
202 n->value.numeric = value;
205 void ccl_add_attr_string(struct ccl_rpn_node *p, const char *set,
206 int type, char *value)
208 struct ccl_rpn_attr *n;
210 n = add_attr_node(p, set, type);
211 n->kind = CCL_RPN_ATTR_STRING;
212 n->value.str = xstrdup(value);
215 static size_t cmp_operator(const char **aliases, const char *input)
217 for (; *aliases; aliases++)
219 const char *cp = *aliases;
221 for (i = 0; *cp && *cp == input[i]; i++, cp++)
230 #define REGEX_CHARS "^[]{}()|.*+?!$"
231 #define CCL_CHARS "#?\\"
232 static int append_term(CCL_parser cclp, const char *src_str, size_t src_len,
233 char *dst_term, int *regex_trunc, int *z3958_trunc,
234 const char **truncation_aliases,
235 const char **mask_aliases,
236 int is_first, int is_last,
237 int *left_trunc, int *right_trunc)
242 for (j = 0; j < src_len; j++)
245 if (j > 0 && src_str[j-1] == '\\')
247 if (*regex_trunc && strchr(REGEX_CHARS "\\", src_str[j]))
250 strcat(dst_term, "\\");
252 else if (*z3958_trunc && strchr(CCL_CHARS "\\", src_str[j]))
255 strcat(dst_term, "\\");
257 strxcat(dst_term, src_str + j, 1);
259 else if (src_str[j] == '"')
260 quote_mode = !quote_mode;
261 else if (!quote_mode &&
262 (op_size = cmp_operator(truncation_aliases,
266 j += (op_size - 1); /* j++ in for loop */
269 strcat(dst_term, ".*");
270 *regex_trunc = 2; /* regex trunc is really needed */
272 else if (*z3958_trunc)
274 strcat(dst_term, "?");
277 else if (is_first && j == 0)
279 else if (is_last && j == src_len - 1)
283 cclp->error_code = CCL_ERR_TRUNC_NOT_EMBED;
287 else if (!quote_mode &&
288 (op_size = cmp_operator(mask_aliases, src_str + j)))
290 j += (op_size - 1); /* j++ in for loop */
293 strcat(dst_term, ".");
294 *regex_trunc = 2; /* regex trunc is really needed */
296 else if (*z3958_trunc)
298 strcat(dst_term, "#");
303 cclp->error_code = CCL_ERR_TRUNC_NOT_SINGLE;
307 else if (src_str[j] != '\\')
309 if (*regex_trunc && strchr(REGEX_CHARS, src_str[j]))
312 strcat(dst_term, "\\");
314 else if (*z3958_trunc && strchr(CCL_CHARS, src_str[j]))
317 strcat(dst_term, "\\");
319 strxcat(dst_term, src_str + j, 1);
326 * search_term: Parse CCL search term.
328 * qa: Qualifier attributes already applied.
329 * term_list: tokens we accept as terms in context
330 * multi: whether we accept "multiple" tokens
331 * return: pointer to node(s); NULL on error.
333 static struct ccl_rpn_node *search_term_x(CCL_parser cclp,
335 int *term_list, int multi)
337 struct ccl_rpn_node *p_top = 0;
338 struct ccl_token *lookahead = cclp->look_token;
343 const char **truncation_aliases;
344 const char *t_default[2];
345 const char **mask_aliases;
346 const char *m_default[2];
349 ccl_qual_search_special(cclp->bibset, "truncation");
350 if (!truncation_aliases)
352 truncation_aliases = t_default;
358 ccl_qual_search_special(cclp->bibset, "mask");
361 mask_aliases = m_default;
367 if (qual_val_type(qa, CCL_BIB1_STR, CCL_BIB1_STR_AND_LIST, 0))
369 if (qual_val_type(qa, CCL_BIB1_STR, CCL_BIB1_STR_AUTO_GROUP, 0))
371 if (qual_val_type(qa, CCL_BIB1_STR, CCL_BIB1_STR_OR_LIST, 0))
375 struct ccl_rpn_node *p;
378 int relation_value = -1;
379 int position_value = -1;
380 int structure_value = -1;
381 int truncation_value = -1;
382 int completeness_value = -1;
389 if (and_list || or_list || !multi)
392 /* ignore commas when dealing with and-lists .. */
393 if (and_list && lookahead && lookahead->kind == CCL_TOK_COMMA)
395 lookahead = lookahead->next;
399 for (no = 0; no < max && is_term_ok(lookahead->kind, term_list); no++)
401 int this_is_phrase = 0;
402 for (i = 0; i<lookahead->len; i++)
403 if (lookahead->name[i] == ' ')
408 if (no > 0 && (is_phrase || is_phrase != this_is_phrase))
410 is_phrase = this_is_phrase;
412 else if (this_is_phrase || no > 0)
414 len += 1+lookahead->len+lookahead->ws_prefix_len;
415 lookahead = lookahead->next;
419 break; /* no more terms . stop . */
421 /* create the term node, but wait a moment before adding the term */
422 p = ccl_rpn_node_create(CCL_RPN_TERM);
423 p->u.t.attr_list = NULL;
427 const char *n = ccl_qual_get_name(qa[0]);
429 p->u.t.qual = xstrdup(n);
432 /* go through all attributes and add them to the attribute list */
433 for (i=0; qa && qa[i]; i++)
435 struct ccl_rpn_attr *attr;
437 for (attr = ccl_qual_get_attr(qa[i]); attr; attr = attr->next)
440 case CCL_RPN_ATTR_STRING:
441 ccl_add_attr_string(p, attr->set, attr->type,
444 case CCL_RPN_ATTR_NUMERIC:
445 if (attr->value.numeric > 0)
446 { /* deal only with REAL attributes (positive) */
450 if (relation_value != -1)
452 relation_value = attr->value.numeric;
455 if (position_value != -1)
457 position_value = attr->value.numeric;
460 if (structure_value != -1)
462 structure_value = attr->value.numeric;
465 if (truncation_value != -1)
467 truncation_value = attr->value.numeric;
470 if (completeness_value != -1)
472 completeness_value = attr->value.numeric;
475 ccl_add_attr_numeric(p, attr->set, attr->type,
476 attr->value.numeric);
481 if (structure_value == -1 && (
483 qual_val_type(qa, CCL_BIB1_STR, CCL_BIB1_STR_WP, &attset))
487 ccl_add_attr_numeric(p, attset, CCL_BIB1_STR, 2);
489 ccl_add_attr_numeric(p, attset, CCL_BIB1_STR, 1);
492 if (qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_REGEX,
495 regex_trunc = 1; /* regex trunc (102) allowed */
497 else if (qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_Z3958,
500 z3958_trunc = 1; /* Z39.58 trunc (CCL) trunc allowed */
503 /* make the RPN token */
504 p->u.t.term = (char *)xmalloc(len * 2 + 2);
505 ccl_assert(p->u.t.term);
506 p->u.t.term[0] = '\0';
507 for (i = 0; i<no; i++)
509 const char *src_str = cclp->look_token->name;
510 size_t src_len = cclp->look_token->len;
512 if (p->u.t.term[0] && cclp->look_token->ws_prefix_len)
514 strxcat(p->u.t.term, cclp->look_token->ws_prefix_buf,
515 cclp->look_token->ws_prefix_len);
517 if (append_term(cclp, src_str, src_len, p->u.t.term, ®ex_trunc,
518 &z3958_trunc, truncation_aliases, mask_aliases,
520 &left_trunc, &right_trunc))
527 /* make the top node point to us.. */
530 struct ccl_rpn_node *tmp;
533 tmp = ccl_rpn_node_create(CCL_RPN_OR);
535 tmp = ccl_rpn_node_create(CCL_RPN_AND);
537 tmp = ccl_rpn_node_create(CCL_RPN_AND);
547 if (left_trunc && right_trunc)
549 if (!qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_BOTH,
552 cclp->error_code = CCL_ERR_TRUNC_NOT_BOTH;
556 ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 3);
558 else if (right_trunc)
560 if (!qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_RIGHT,
563 cclp->error_code = CCL_ERR_TRUNC_NOT_RIGHT;
567 ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 1);
571 if (!qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_LEFT,
574 cclp->error_code = CCL_ERR_TRUNC_NOT_LEFT;
578 ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 2);
580 else if (regex_trunc == 2)
582 ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 102);
584 else if (z3958_trunc == 2)
586 ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 104);
590 if (qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_NONE,
592 ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 100);
598 cclp->error_code = CCL_ERR_TERM_EXPECTED;
602 static struct ccl_rpn_node *search_term(CCL_parser cclp, ccl_qualifier_t *qa)
604 static int list[] = {CCL_TOK_TERM, CCL_TOK_COMMA, -1};
605 return search_term_x(cclp, qa, list, 0);
609 static struct ccl_rpn_node *search_terms2(CCL_parser cclp,
612 if (KIND == CCL_TOK_LP)
614 struct ccl_rpn_node *p;
616 if (!(p = find_spec(cclp, qa)))
618 if (KIND != CCL_TOK_RP)
620 cclp->error_code = CCL_ERR_RP_EXPECTED;
629 static int list[] = {
630 CCL_TOK_TERM, CCL_TOK_COMMA,CCL_TOK_EQ,
631 CCL_TOK_REL, CCL_TOK_SET, -1};
633 return search_term_x(cclp, qa, list, 1);
640 struct ccl_rpn_node *qualifiers_order(CCL_parser cclp,
641 ccl_qualifier_t *ap, char *attset)
644 struct ccl_rpn_node *p;
646 if (cclp->look_token->len == 1)
648 if (cclp->look_token->name[0] == '<')
650 else if (cclp->look_token->name[0] == '=')
652 else if (cclp->look_token->name[0] == '>')
655 else if (cclp->look_token->len == 2)
657 if (!memcmp(cclp->look_token->name, "<=", 2))
659 else if (!memcmp(cclp->look_token->name, ">=", 2))
661 else if (!memcmp(cclp->look_token->name, "<>", 2))
666 cclp->error_code = CCL_ERR_BAD_RELATION;
669 ADVANCE; /* skip relation */
671 qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_PORDER, 0))
673 /* allow - inside term and treat it as range _always_ */
674 /* relation is =. Extract "embedded" - to separate terms */
675 if (KIND == CCL_TOK_TERM)
678 for (i = 0; i<cclp->look_token->len; i++)
680 if (cclp->look_token->name[i] == '-')
684 if (cclp->look_token->len > 1 && i == 0)
686 struct ccl_token *ntoken = ccl_token_add(cclp->look_token);
688 ntoken->kind = CCL_TOK_TERM;
689 ntoken->name = cclp->look_token->name + 1;
690 ntoken->len = cclp->look_token->len - 1;
692 cclp->look_token->len = 1;
693 cclp->look_token->name = "-";
695 else if (cclp->look_token->len > 1 && i == cclp->look_token->len-1)
697 struct ccl_token *ntoken = ccl_token_add(cclp->look_token);
699 ntoken->kind = CCL_TOK_TERM;
703 (cclp->look_token->len)--;
705 else if (cclp->look_token->len > 2 && i < cclp->look_token->len)
707 struct ccl_token *ntoken1 = ccl_token_add(cclp->look_token);
708 struct ccl_token *ntoken2 = ccl_token_add(ntoken1);
710 ntoken1->kind = CCL_TOK_TERM; /* generate - */
714 ntoken2->kind = CCL_TOK_TERM; /* generate yy */
715 ntoken2->name = cclp->look_token->name + (i+1);
716 ntoken2->len = cclp->look_token->len - (i+1);
718 cclp->look_token->len = i; /* adjust xx */
720 else if (i == cclp->look_token->len &&
721 cclp->look_token->next &&
722 cclp->look_token->next->kind == CCL_TOK_TERM &&
723 cclp->look_token->next->len > 1 &&
724 cclp->look_token->next->name[0] == '-')
727 /* we _know_ that xx does not have - in it */
728 struct ccl_token *ntoken = ccl_token_add(cclp->look_token);
730 ntoken->kind = CCL_TOK_TERM; /* generate - */
734 (ntoken->next->name)++; /* adjust yy */
735 (ntoken->next->len)--;
741 KIND == CCL_TOK_TERM &&
742 cclp->look_token->next && cclp->look_token->next->len == 1 &&
743 cclp->look_token->next->name[0] == '-')
745 struct ccl_rpn_node *p1;
746 if (!(p1 = search_term(cclp, ap)))
748 ADVANCE; /* skip '-' */
749 if (KIND == CCL_TOK_TERM) /* = term - term ? */
751 struct ccl_rpn_node *p2;
753 if (!(p2 = search_term(cclp, ap)))
758 p = ccl_rpn_node_create(CCL_RPN_AND);
760 ccl_add_attr_numeric(p1, attset, CCL_BIB1_REL, 4);
762 ccl_add_attr_numeric(p2, attset, CCL_BIB1_REL, 2);
767 ccl_add_attr_numeric(p1, attset, CCL_BIB1_REL, 4);
772 cclp->look_token->len == 1 &&
773 cclp->look_token->name[0] == '-') /* = - term ? */
776 if (!(p = search_term(cclp, ap)))
778 ccl_add_attr_numeric(p, attset, CCL_BIB1_REL, 2);
783 if (!(p = search_terms(cclp, ap)))
785 ccl_add_attr_numeric(p, attset, CCL_BIB1_REL, rel);
788 cclp->error_code = CCL_ERR_TERM_EXPECTED;
793 struct ccl_rpn_node *qualifier_relation(CCL_parser cclp, ccl_qualifier_t *ap)
797 if (qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_ORDER, &attset)
798 || qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_PORDER, &attset))
799 return qualifiers_order(cclp, ap, attset);
801 /* unordered relation */
802 if (KIND != CCL_TOK_EQ)
804 cclp->error_code = CCL_ERR_EQ_EXPECTED;
808 return search_terms(cclp, ap);
812 * qualifier_list: Parse CCL qualifiers and search terms.
814 * la: Token pointer to RELATION token.
815 * qa: Qualifier attributes already applied.
816 * return: pointer to node(s); NULL on error.
818 static struct ccl_rpn_node *qualifier_list(CCL_parser cclp,
819 struct ccl_token *la,
822 struct ccl_token *lookahead = cclp->look_token;
823 struct ccl_token *look_start = cclp->look_token;
825 struct ccl_rpn_node *node = 0;
826 const char **field_str;
834 cclp->error_code = CCL_ERR_DOUBLE_QUAL;
838 for (lookahead = cclp->look_token; lookahead != la;
839 lookahead=lookahead->next)
842 for (i=0; qa[i]; i++)
844 ap = (ccl_qualifier_t *)xmalloc((no ? (no+1) : 2) * sizeof(*ap));
847 field_str = ccl_qual_search_special(cclp->bibset, "field");
850 if (!strcmp(field_str[0], "or"))
852 else if (!strcmp(field_str[0], "merge"))
857 /* consider each field separately and OR */
858 lookahead = look_start;
859 while (lookahead != la)
863 while ((ap[0] = ccl_qual_search(cclp, lookahead->name,
864 lookahead->len, seq)) != 0)
866 struct ccl_rpn_node *node_sub;
867 cclp->look_token = la;
869 node_sub = qualifier_relation(cclp, ap);
872 ccl_rpn_delete(node);
878 struct ccl_rpn_node *node_this =
879 ccl_rpn_node_create(CCL_RPN_OR);
880 node_this->u.p[0] = node;
881 node_this->u.p[1] = node_sub;
890 cclp->look_token = lookahead;
891 cclp->error_code = CCL_ERR_UNKNOWN_QUAL;
895 lookahead = lookahead->next;
896 if (lookahead->kind == CCL_TOK_COMMA)
897 lookahead = lookahead->next;
902 /* merge attributes from ALL fields - including inherited ones */
905 struct ccl_rpn_node *node_sub;
907 lookahead = look_start;
908 for (i = 0; lookahead != la; i++)
910 ap[i] = ccl_qual_search(cclp, lookahead->name,
911 lookahead->len, seq);
914 if (!ap[i] && seq > 0)
915 ap[i] = ccl_qual_search(cclp, lookahead->name,
919 cclp->look_token = lookahead;
920 cclp->error_code = CCL_ERR_UNKNOWN_QUAL;
924 lookahead = lookahead->next;
925 if (lookahead->kind == CCL_TOK_COMMA)
926 lookahead = lookahead->next;
930 ccl_qualifier_t *qa0 = qa;
940 cclp->look_token = lookahead;
942 node_sub = qualifier_relation(cclp, ap);
945 ccl_rpn_delete(node);
950 struct ccl_rpn_node *node_this =
951 ccl_rpn_node_create(CCL_RPN_OR);
952 node_this->u.p[0] = node;
953 node_this->u.p[1] = node_sub;
967 * search_terms: Parse CCL search terms - including proximity.
969 * qa: Qualifier attributes already applied.
970 * return: pointer to node(s); NULL on error.
972 static struct ccl_rpn_node *search_terms(CCL_parser cclp, ccl_qualifier_t *qa)
974 static int list[] = {
975 CCL_TOK_TERM, CCL_TOK_COMMA,CCL_TOK_EQ,
976 CCL_TOK_REL, CCL_TOK_SET, -1};
977 struct ccl_rpn_node *p1, *p2, *pn;
978 p1 = search_terms2(cclp, qa);
983 if (KIND == CCL_TOK_PROX)
985 struct ccl_rpn_node *p_prox = 0;
986 /* ! word order specified */
987 /* % word order not specified */
988 p_prox = ccl_rpn_node_create(CCL_RPN_TERM);
989 p_prox->u.t.term = (char *) xmalloc(1 + cclp->look_token->len);
990 memcpy(p_prox->u.t.term, cclp->look_token->name,
991 cclp->look_token->len);
992 p_prox->u.t.term[cclp->look_token->len] = 0;
993 p_prox->u.t.attr_list = 0;
996 p2 = search_terms2(cclp, qa);
1002 pn = ccl_rpn_node_create(CCL_RPN_PROX);
1005 pn->u.p[2] = p_prox;
1008 else if (is_term_ok(KIND, list))
1010 p2 = search_terms2(cclp, qa);
1016 pn = ccl_rpn_node_create(CCL_RPN_PROX);
1029 * search_elements: Parse CCL search elements
1031 * qa: Qualifier attributes already applied.
1032 * return: pointer to node(s); NULL on error.
1034 static struct ccl_rpn_node *search_elements(CCL_parser cclp,
1035 ccl_qualifier_t *qa)
1037 struct ccl_rpn_node *p1;
1038 struct ccl_token *lookahead;
1039 if (KIND == CCL_TOK_SET)
1042 if (KIND == CCL_TOK_EQ)
1044 if (KIND != CCL_TOK_TERM)
1046 cclp->error_code = CCL_ERR_SETNAME_EXPECTED;
1049 p1 = ccl_rpn_node_create(CCL_RPN_SET);
1050 p1->u.setname = copy_token_name(cclp->look_token);
1054 lookahead = cclp->look_token;
1056 while (lookahead->kind==CCL_TOK_TERM)
1058 lookahead = lookahead->next;
1059 if (lookahead->kind == CCL_TOK_REL || lookahead->kind == CCL_TOK_EQ)
1060 return qualifier_list(cclp, lookahead, qa);
1061 if (lookahead->kind != CCL_TOK_COMMA)
1063 lookahead = lookahead->next;
1065 if (qa || lookahead->kind == CCL_TOK_LP)
1066 return search_terms(cclp, qa);
1069 ccl_qualifier_t qa[2];
1070 struct ccl_rpn_node *node = 0;
1072 lookahead = cclp->look_token;
1075 for(seq = 0; ;seq++)
1077 struct ccl_rpn_node *node_sub;
1078 qa[0] = ccl_qual_search(cclp, "term", 4, seq);
1082 cclp->look_token = lookahead;
1084 node_sub = search_terms(cclp, qa);
1087 ccl_rpn_delete(node);
1092 struct ccl_rpn_node *node_this =
1093 ccl_rpn_node_create(CCL_RPN_OR);
1094 node_this->u.p[0] = node;
1095 node_this->u.p[1] = node_sub;
1096 node_this->u.p[2] = 0;
1103 node = search_terms(cclp, 0);
1109 * find_spec: Parse CCL find specification
1111 * qa: Qualifier attributes already applied.
1112 * return: pointer to node(s); NULL on error.
1114 static struct ccl_rpn_node *find_spec(CCL_parser cclp, ccl_qualifier_t *qa)
1116 struct ccl_rpn_node *p1, *p2, *pn;
1117 if (!(p1 = search_elements(cclp, qa)))
1125 p2 = search_elements(cclp, qa);
1131 pn = ccl_rpn_node_create(CCL_RPN_AND);
1139 p2 = search_elements(cclp, qa);
1145 pn = ccl_rpn_node_create(CCL_RPN_OR);
1153 p2 = search_elements(cclp, qa);
1159 pn = ccl_rpn_node_create(CCL_RPN_NOT);
1171 struct ccl_rpn_node *ccl_parser_find_str(CCL_parser cclp, const char *str)
1173 struct ccl_rpn_node *p;
1174 struct ccl_token *list = ccl_parser_tokenize(cclp, str);
1175 p = ccl_parser_find_token(cclp, list);
1176 ccl_token_del(list);
1180 struct ccl_rpn_node *ccl_parser_find_token(CCL_parser cclp,
1181 struct ccl_token *list)
1183 struct ccl_rpn_node *p;
1185 cclp->look_token = list;
1186 p = find_spec(cclp, NULL);
1187 if (p && KIND != CCL_TOK_EOL)
1189 if (KIND == CCL_TOK_RP)
1190 cclp->error_code = CCL_ERR_BAD_RP;
1192 cclp->error_code = CCL_ERR_OP_EXPECTED;
1196 cclp->error_pos = cclp->look_token->name;
1198 cclp->error_code = CCL_ERR_OK;
1200 cclp->error_code = cclp->error_code;
1205 * ccl_find_str: Parse CCL find - string representation
1206 * bibset: Bibset to be used for the parsing
1207 * str: String to be parsed
1208 * error: Pointer to integer. Holds error no. on completion.
1209 * pos: Pointer to char position. Holds approximate error position.
1210 * return: RPN tree on successful completion; NULL otherwise.
1212 struct ccl_rpn_node *ccl_find_str(CCL_bibset bibset, const char *str,
1213 int *error, int *pos)
1215 CCL_parser cclp = ccl_parser_create(bibset);
1216 struct ccl_token *list;
1217 struct ccl_rpn_node *p;
1219 list = ccl_parser_tokenize(cclp, str);
1220 p = ccl_parser_find_token(cclp, list);
1222 *error = cclp->error_code;
1224 *pos = cclp->error_pos - str;
1225 ccl_parser_destroy(cclp);
1226 ccl_token_del(list);
1233 * c-file-style: "Stroustrup"
1234 * indent-tabs-mode: nil
1236 * vim: shiftwidth=4 tabstop=8 expandtab