1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2012 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 int is_first, int is_last,
236 int *left_trunc, int *right_trunc)
241 for (j = 0; j < src_len; j++)
244 if (j > 0 && src_str[j-1] == '\\')
246 if (*regex_trunc && strchr(REGEX_CHARS "\\", src_str[j]))
249 strcat(dst_term, "\\");
251 else if (*z3958_trunc && strchr(CCL_CHARS "\\", src_str[j]))
254 strcat(dst_term, "\\");
256 strxcat(dst_term, src_str + j, 1);
258 else if (src_str[j] == '"')
259 quote_mode = !quote_mode;
260 else if (!quote_mode &&
261 (op_size = cmp_operator(truncation_aliases,
265 j += (op_size - 1); /* j++ in for loop */
268 strcat(dst_term, ".*");
269 *regex_trunc = 2; /* regex trunc is really needed */
271 else if (*z3958_trunc)
273 strcat(dst_term, "?");
276 else if (is_first && j == 0)
278 else if (is_last && j == src_len - 1)
282 cclp->error_code = CCL_ERR_TRUNC_NOT_EMBED;
286 else if (!quote_mode && src_str[j] == '#')
290 strcat(dst_term, ".");
291 *regex_trunc = 2; /* regex trunc is really needed */
293 else if (*z3958_trunc)
295 strcat(dst_term, "#");
300 cclp->error_code = CCL_ERR_TRUNC_NOT_SINGLE;
304 else if (src_str[j] != '\\')
306 if (*regex_trunc && strchr(REGEX_CHARS, src_str[j]))
309 strcat(dst_term, "\\");
311 else if (*z3958_trunc && strchr(CCL_CHARS, src_str[j]))
314 strcat(dst_term, "\\");
316 strxcat(dst_term, src_str + j, 1);
323 * search_term: Parse CCL search term.
325 * qa: Qualifier attributes already applied.
326 * term_list: tokens we accept as terms in context
327 * multi: whether we accept "multiple" tokens
328 * return: pointer to node(s); NULL on error.
330 static struct ccl_rpn_node *search_term_x(CCL_parser cclp,
332 int *term_list, int multi)
334 struct ccl_rpn_node *p_top = 0;
335 struct ccl_token *lookahead = cclp->look_token;
340 const char **truncation_aliases;
341 const char *t_default[2];
344 ccl_qual_search_special(cclp->bibset, "truncation");
345 if (!truncation_aliases)
347 truncation_aliases = t_default;
352 if (qual_val_type(qa, CCL_BIB1_STR, CCL_BIB1_STR_AND_LIST, 0))
354 if (qual_val_type(qa, CCL_BIB1_STR, CCL_BIB1_STR_AUTO_GROUP, 0))
356 if (qual_val_type(qa, CCL_BIB1_STR, CCL_BIB1_STR_OR_LIST, 0))
360 struct ccl_rpn_node *p;
363 int relation_value = -1;
364 int position_value = -1;
365 int structure_value = -1;
366 int truncation_value = -1;
367 int completeness_value = -1;
374 if (and_list || or_list || !multi)
377 /* ignore commas when dealing with and-lists .. */
378 if (and_list && lookahead && lookahead->kind == CCL_TOK_COMMA)
380 lookahead = lookahead->next;
384 for (no = 0; no < max && is_term_ok(lookahead->kind, term_list); no++)
386 int this_is_phrase = 0;
387 for (i = 0; i<lookahead->len; i++)
388 if (lookahead->name[i] == ' ')
393 if (no > 0 && (is_phrase || is_phrase != this_is_phrase))
395 is_phrase = this_is_phrase;
397 else if (this_is_phrase || no > 0)
399 len += 1+lookahead->len+lookahead->ws_prefix_len;
400 lookahead = lookahead->next;
404 break; /* no more terms . stop . */
406 /* create the term node, but wait a moment before adding the term */
407 p = ccl_rpn_node_create(CCL_RPN_TERM);
408 p->u.t.attr_list = NULL;
412 const char *n = ccl_qual_get_name(qa[0]);
414 p->u.t.qual = xstrdup(n);
417 /* go through all attributes and add them to the attribute list */
418 for (i=0; qa && qa[i]; i++)
420 struct ccl_rpn_attr *attr;
422 for (attr = ccl_qual_get_attr(qa[i]); attr; attr = attr->next)
425 case CCL_RPN_ATTR_STRING:
426 ccl_add_attr_string(p, attr->set, attr->type,
429 case CCL_RPN_ATTR_NUMERIC:
430 if (attr->value.numeric > 0)
431 { /* deal only with REAL attributes (positive) */
435 if (relation_value != -1)
437 relation_value = attr->value.numeric;
440 if (position_value != -1)
442 position_value = attr->value.numeric;
445 if (structure_value != -1)
447 structure_value = attr->value.numeric;
450 if (truncation_value != -1)
452 truncation_value = attr->value.numeric;
455 if (completeness_value != -1)
457 completeness_value = attr->value.numeric;
460 ccl_add_attr_numeric(p, attr->set, attr->type,
461 attr->value.numeric);
465 /* len now holds the number of characters in the RPN term */
466 /* no holds the number of CCL tokens (1 or more) */
468 if (structure_value == -1 &&
469 qual_val_type(qa, CCL_BIB1_STR, CCL_BIB1_STR_WP, &attset))
470 { /* no structure attribute met. Apply either structure attribute
471 WORD or PHRASE depending on number of CCL tokens */
473 ccl_add_attr_numeric(p, attset, CCL_BIB1_STR, 2);
475 ccl_add_attr_numeric(p, attset, CCL_BIB1_STR, 1);
478 if (qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_REGEX,
481 regex_trunc = 1; /* regex trunc (102) allowed */
483 else if (qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_Z3958,
486 z3958_trunc = 1; /* Z39.58 trunc (CCL) trunc allowed */
489 /* make the RPN token */
490 p->u.t.term = (char *)xmalloc(len * 2 + 2);
491 ccl_assert(p->u.t.term);
492 p->u.t.term[0] = '\0';
493 for (i = 0; i<no; i++)
495 const char *src_str = cclp->look_token->name;
496 size_t src_len = cclp->look_token->len;
498 if (p->u.t.term[0] && cclp->look_token->ws_prefix_len)
500 strxcat(p->u.t.term, cclp->look_token->ws_prefix_buf,
501 cclp->look_token->ws_prefix_len);
503 if (append_term(cclp, src_str, src_len, p->u.t.term, ®ex_trunc,
504 &z3958_trunc, truncation_aliases, i == 0, i == no - 1,
505 &left_trunc, &right_trunc))
512 /* make the top node point to us.. */
515 struct ccl_rpn_node *tmp;
518 tmp = ccl_rpn_node_create(CCL_RPN_OR);
520 tmp = ccl_rpn_node_create(CCL_RPN_AND);
522 tmp = ccl_rpn_node_create(CCL_RPN_AND);
532 if (left_trunc && right_trunc)
534 if (!qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_BOTH,
537 cclp->error_code = CCL_ERR_TRUNC_NOT_BOTH;
541 ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 3);
543 else if (right_trunc)
545 if (!qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_RIGHT,
548 cclp->error_code = CCL_ERR_TRUNC_NOT_RIGHT;
552 ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 1);
556 if (!qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_LEFT,
559 cclp->error_code = CCL_ERR_TRUNC_NOT_LEFT;
563 ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 2);
565 else if (regex_trunc == 2)
567 ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 102);
569 else if (z3958_trunc == 2)
571 ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 104);
575 if (qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_NONE,
577 ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 100);
583 cclp->error_code = CCL_ERR_TERM_EXPECTED;
587 static struct ccl_rpn_node *search_term(CCL_parser cclp, ccl_qualifier_t *qa)
589 static int list[] = {CCL_TOK_TERM, CCL_TOK_COMMA, -1};
590 return search_term_x(cclp, qa, list, 0);
594 static struct ccl_rpn_node *search_terms2(CCL_parser cclp,
597 if (KIND == CCL_TOK_LP)
599 struct ccl_rpn_node *p;
601 if (!(p = find_spec(cclp, qa)))
603 if (KIND != CCL_TOK_RP)
605 cclp->error_code = CCL_ERR_RP_EXPECTED;
614 static int list[] = {
615 CCL_TOK_TERM, CCL_TOK_COMMA,CCL_TOK_EQ,
616 CCL_TOK_REL, CCL_TOK_SET, -1};
618 return search_term_x(cclp, qa, list, 1);
625 struct ccl_rpn_node *qualifiers_order(CCL_parser cclp,
626 ccl_qualifier_t *ap, char *attset)
629 struct ccl_rpn_node *p;
631 if (cclp->look_token->len == 1)
633 if (cclp->look_token->name[0] == '<')
635 else if (cclp->look_token->name[0] == '=')
637 else if (cclp->look_token->name[0] == '>')
640 else if (cclp->look_token->len == 2)
642 if (!memcmp(cclp->look_token->name, "<=", 2))
644 else if (!memcmp(cclp->look_token->name, ">=", 2))
646 else if (!memcmp(cclp->look_token->name, "<>", 2))
651 cclp->error_code = CCL_ERR_BAD_RELATION;
654 ADVANCE; /* skip relation */
656 qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_PORDER, 0))
658 /* allow - inside term and treat it as range _always_ */
659 /* relation is =. Extract "embedded" - to separate terms */
660 if (KIND == CCL_TOK_TERM)
663 for (i = 0; i<cclp->look_token->len; i++)
665 if (cclp->look_token->name[i] == '-')
669 if (cclp->look_token->len > 1 && i == 0)
671 struct ccl_token *ntoken = ccl_token_add(cclp->look_token);
673 ntoken->kind = CCL_TOK_TERM;
674 ntoken->name = cclp->look_token->name + 1;
675 ntoken->len = cclp->look_token->len - 1;
677 cclp->look_token->len = 1;
678 cclp->look_token->name = "-";
680 else if (cclp->look_token->len > 1 && i == cclp->look_token->len-1)
682 struct ccl_token *ntoken = ccl_token_add(cclp->look_token);
684 ntoken->kind = CCL_TOK_TERM;
688 (cclp->look_token->len)--;
690 else if (cclp->look_token->len > 2 && i < cclp->look_token->len)
692 struct ccl_token *ntoken1 = ccl_token_add(cclp->look_token);
693 struct ccl_token *ntoken2 = ccl_token_add(ntoken1);
695 ntoken1->kind = CCL_TOK_TERM; /* generate - */
699 ntoken2->kind = CCL_TOK_TERM; /* generate yy */
700 ntoken2->name = cclp->look_token->name + (i+1);
701 ntoken2->len = cclp->look_token->len - (i+1);
703 cclp->look_token->len = i; /* adjust xx */
705 else if (i == cclp->look_token->len &&
706 cclp->look_token->next &&
707 cclp->look_token->next->kind == CCL_TOK_TERM &&
708 cclp->look_token->next->len > 1 &&
709 cclp->look_token->next->name[0] == '-')
712 /* we _know_ that xx does not have - in it */
713 struct ccl_token *ntoken = ccl_token_add(cclp->look_token);
715 ntoken->kind = CCL_TOK_TERM; /* generate - */
719 (ntoken->next->name)++; /* adjust yy */
720 (ntoken->next->len)--;
726 KIND == CCL_TOK_TERM &&
727 cclp->look_token->next && cclp->look_token->next->len == 1 &&
728 cclp->look_token->next->name[0] == '-')
730 struct ccl_rpn_node *p1;
731 if (!(p1 = search_term(cclp, ap)))
733 ADVANCE; /* skip '-' */
734 if (KIND == CCL_TOK_TERM) /* = term - term ? */
736 struct ccl_rpn_node *p2;
738 if (!(p2 = search_term(cclp, ap)))
743 p = ccl_rpn_node_create(CCL_RPN_AND);
745 ccl_add_attr_numeric(p1, attset, CCL_BIB1_REL, 4);
747 ccl_add_attr_numeric(p2, attset, CCL_BIB1_REL, 2);
752 ccl_add_attr_numeric(p1, attset, CCL_BIB1_REL, 4);
757 cclp->look_token->len == 1 &&
758 cclp->look_token->name[0] == '-') /* = - term ? */
761 if (!(p = search_term(cclp, ap)))
763 ccl_add_attr_numeric(p, attset, CCL_BIB1_REL, 2);
768 if (!(p = search_terms(cclp, ap)))
770 ccl_add_attr_numeric(p, attset, CCL_BIB1_REL, rel);
773 cclp->error_code = CCL_ERR_TERM_EXPECTED;
778 struct ccl_rpn_node *qualifier_relation(CCL_parser cclp, ccl_qualifier_t *ap)
782 if (qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_ORDER, &attset)
783 || qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_PORDER, &attset))
784 return qualifiers_order(cclp, ap, attset);
786 /* unordered relation */
787 if (KIND != CCL_TOK_EQ)
789 cclp->error_code = CCL_ERR_EQ_EXPECTED;
793 return search_terms(cclp, ap);
797 * qualifier_list: Parse CCL qualifiers and search terms.
799 * la: Token pointer to RELATION token.
800 * qa: Qualifier attributes already applied.
801 * return: pointer to node(s); NULL on error.
803 static struct ccl_rpn_node *qualifier_list(CCL_parser cclp,
804 struct ccl_token *la,
807 struct ccl_token *lookahead = cclp->look_token;
808 struct ccl_token *look_start = cclp->look_token;
810 struct ccl_rpn_node *node = 0;
811 const char **field_str;
819 cclp->error_code = CCL_ERR_DOUBLE_QUAL;
823 for (lookahead = cclp->look_token; lookahead != la;
824 lookahead=lookahead->next)
827 for (i=0; qa[i]; i++)
829 ap = (ccl_qualifier_t *)xmalloc((no ? (no+1) : 2) * sizeof(*ap));
832 field_str = ccl_qual_search_special(cclp->bibset, "field");
835 if (!strcmp(field_str[0], "or"))
837 else if (!strcmp(field_str[0], "merge"))
842 /* consider each field separately and OR */
843 lookahead = look_start;
844 while (lookahead != la)
848 while ((ap[0] = ccl_qual_search(cclp, lookahead->name,
849 lookahead->len, seq)) != 0)
851 struct ccl_rpn_node *node_sub;
852 cclp->look_token = la;
854 node_sub = qualifier_relation(cclp, ap);
857 ccl_rpn_delete(node);
863 struct ccl_rpn_node *node_this =
864 ccl_rpn_node_create(CCL_RPN_OR);
865 node_this->u.p[0] = node;
866 node_this->u.p[1] = node_sub;
875 cclp->look_token = lookahead;
876 cclp->error_code = CCL_ERR_UNKNOWN_QUAL;
880 lookahead = lookahead->next;
881 if (lookahead->kind == CCL_TOK_COMMA)
882 lookahead = lookahead->next;
887 /* merge attributes from ALL fields - including inherited ones */
890 struct ccl_rpn_node *node_sub;
892 lookahead = look_start;
893 for (i = 0; lookahead != la; i++)
895 ap[i] = ccl_qual_search(cclp, lookahead->name,
896 lookahead->len, seq);
899 if (!ap[i] && seq > 0)
900 ap[i] = ccl_qual_search(cclp, lookahead->name,
904 cclp->look_token = lookahead;
905 cclp->error_code = CCL_ERR_UNKNOWN_QUAL;
909 lookahead = lookahead->next;
910 if (lookahead->kind == CCL_TOK_COMMA)
911 lookahead = lookahead->next;
915 ccl_qualifier_t *qa0 = qa;
925 cclp->look_token = lookahead;
927 node_sub = qualifier_relation(cclp, ap);
930 ccl_rpn_delete(node);
935 struct ccl_rpn_node *node_this =
936 ccl_rpn_node_create(CCL_RPN_OR);
937 node_this->u.p[0] = node;
938 node_this->u.p[1] = node_sub;
952 * search_terms: Parse CCL search terms - including proximity.
954 * qa: Qualifier attributes already applied.
955 * return: pointer to node(s); NULL on error.
957 static struct ccl_rpn_node *search_terms(CCL_parser cclp, ccl_qualifier_t *qa)
959 static int list[] = {
960 CCL_TOK_TERM, CCL_TOK_COMMA,CCL_TOK_EQ,
961 CCL_TOK_REL, CCL_TOK_SET, -1};
962 struct ccl_rpn_node *p1, *p2, *pn;
963 p1 = search_terms2(cclp, qa);
968 if (KIND == CCL_TOK_PROX)
970 struct ccl_rpn_node *p_prox = 0;
971 /* ! word order specified */
972 /* % word order not specified */
973 p_prox = ccl_rpn_node_create(CCL_RPN_TERM);
974 p_prox->u.t.term = (char *) xmalloc(1 + cclp->look_token->len);
975 memcpy(p_prox->u.t.term, cclp->look_token->name,
976 cclp->look_token->len);
977 p_prox->u.t.term[cclp->look_token->len] = 0;
978 p_prox->u.t.attr_list = 0;
981 p2 = search_terms2(cclp, qa);
987 pn = ccl_rpn_node_create(CCL_RPN_PROX);
993 else if (is_term_ok(KIND, list))
995 p2 = search_terms2(cclp, qa);
1001 pn = ccl_rpn_node_create(CCL_RPN_PROX);
1014 * search_elements: Parse CCL search elements
1016 * qa: Qualifier attributes already applied.
1017 * return: pointer to node(s); NULL on error.
1019 static struct ccl_rpn_node *search_elements(CCL_parser cclp,
1020 ccl_qualifier_t *qa)
1022 struct ccl_rpn_node *p1;
1023 struct ccl_token *lookahead;
1024 if (KIND == CCL_TOK_SET)
1027 if (KIND == CCL_TOK_EQ)
1029 if (KIND != CCL_TOK_TERM)
1031 cclp->error_code = CCL_ERR_SETNAME_EXPECTED;
1034 p1 = ccl_rpn_node_create(CCL_RPN_SET);
1035 p1->u.setname = copy_token_name(cclp->look_token);
1039 lookahead = cclp->look_token;
1041 while (lookahead->kind==CCL_TOK_TERM)
1043 lookahead = lookahead->next;
1044 if (lookahead->kind == CCL_TOK_REL || lookahead->kind == CCL_TOK_EQ)
1045 return qualifier_list(cclp, lookahead, qa);
1046 if (lookahead->kind != CCL_TOK_COMMA)
1048 lookahead = lookahead->next;
1050 if (qa || lookahead->kind == CCL_TOK_LP)
1051 return search_terms(cclp, qa);
1054 ccl_qualifier_t qa[2];
1055 struct ccl_rpn_node *node = 0;
1057 lookahead = cclp->look_token;
1060 for(seq = 0; ;seq++)
1062 struct ccl_rpn_node *node_sub;
1063 qa[0] = ccl_qual_search(cclp, "term", 4, seq);
1067 cclp->look_token = lookahead;
1069 node_sub = search_terms(cclp, qa);
1072 ccl_rpn_delete(node);
1077 struct ccl_rpn_node *node_this =
1078 ccl_rpn_node_create(CCL_RPN_OR);
1079 node_this->u.p[0] = node;
1080 node_this->u.p[1] = node_sub;
1081 node_this->u.p[2] = 0;
1088 node = search_terms(cclp, 0);
1094 * find_spec: Parse CCL find specification
1096 * qa: Qualifier attributes already applied.
1097 * return: pointer to node(s); NULL on error.
1099 static struct ccl_rpn_node *find_spec(CCL_parser cclp, ccl_qualifier_t *qa)
1101 struct ccl_rpn_node *p1, *p2, *pn;
1102 if (!(p1 = search_elements(cclp, qa)))
1110 p2 = search_elements(cclp, qa);
1116 pn = ccl_rpn_node_create(CCL_RPN_AND);
1124 p2 = search_elements(cclp, qa);
1130 pn = ccl_rpn_node_create(CCL_RPN_OR);
1138 p2 = search_elements(cclp, qa);
1144 pn = ccl_rpn_node_create(CCL_RPN_NOT);
1156 struct ccl_rpn_node *ccl_parser_find_str(CCL_parser cclp, const char *str)
1158 struct ccl_rpn_node *p;
1159 struct ccl_token *list = ccl_parser_tokenize(cclp, str);
1160 p = ccl_parser_find_token(cclp, list);
1161 ccl_token_del(list);
1165 struct ccl_rpn_node *ccl_parser_find_token(CCL_parser cclp,
1166 struct ccl_token *list)
1168 struct ccl_rpn_node *p;
1170 cclp->look_token = list;
1171 p = find_spec(cclp, NULL);
1172 if (p && KIND != CCL_TOK_EOL)
1174 if (KIND == CCL_TOK_RP)
1175 cclp->error_code = CCL_ERR_BAD_RP;
1177 cclp->error_code = CCL_ERR_OP_EXPECTED;
1181 cclp->error_pos = cclp->look_token->name;
1183 cclp->error_code = CCL_ERR_OK;
1185 cclp->error_code = cclp->error_code;
1190 * ccl_find_str: Parse CCL find - string representation
1191 * bibset: Bibset to be used for the parsing
1192 * str: String to be parsed
1193 * error: Pointer to integer. Holds error no. on completion.
1194 * pos: Pointer to char position. Holds approximate error position.
1195 * return: RPN tree on successful completion; NULL otherwise.
1197 struct ccl_rpn_node *ccl_find_str(CCL_bibset bibset, const char *str,
1198 int *error, int *pos)
1200 CCL_parser cclp = ccl_parser_create(bibset);
1201 struct ccl_token *list;
1202 struct ccl_rpn_node *p;
1204 list = ccl_parser_tokenize(cclp, str);
1205 p = ccl_parser_find_token(cclp, list);
1207 *error = cclp->error_code;
1209 *pos = cclp->error_pos - str;
1210 ccl_parser_destroy(cclp);
1211 ccl_token_del(list);
1218 * c-file-style: "Stroustrup"
1219 * indent-tabs-mode: nil
1221 * vim: shiftwidth=4 tabstop=8 expandtab