1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2011 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);
217 * search_term: Parse CCL search term.
219 * qa: Qualifier attributes already applied.
220 * term_list: tokens we accept as terms in context
221 * multi: whether we accept "multiple" tokens
222 * return: pointer to node(s); NULL on error.
224 static struct ccl_rpn_node *search_term_x(CCL_parser cclp,
226 int *term_list, int multi)
228 struct ccl_rpn_node *p_top = 0;
229 struct ccl_token *lookahead = cclp->look_token;
233 const char **truncation_aliases;
234 const char *t_default[2];
237 ccl_qual_search_special(cclp->bibset, "truncation");
238 if (!truncation_aliases)
240 truncation_aliases = t_default;
245 if (qual_val_type(qa, CCL_BIB1_STR, CCL_BIB1_STR_AND_LIST, 0))
247 if (qual_val_type(qa, CCL_BIB1_STR, CCL_BIB1_STR_OR_LIST, 0))
251 struct ccl_rpn_node *p;
254 int relation_value = -1;
255 int position_value = -1;
256 int structure_value = -1;
257 int truncation_value = -1;
258 int completeness_value = -1;
264 if (and_list || or_list || !multi)
267 /* ignore commas when dealing with and-lists .. */
268 if (and_list && lookahead && lookahead->kind == CCL_TOK_COMMA)
270 lookahead = lookahead->next;
274 /* go through each TERM token. If no truncation attribute is yet
275 met, then look for left/right truncation markers (?) and
276 set left_trunc/right_trunc/mid_trunc accordingly */
277 for (no = 0; no < max && is_term_ok(lookahead->kind, term_list); no++)
279 for (i = 0; i<lookahead->len; i++)
280 if (lookahead->name[i] == ' ')
282 len += 1+lookahead->len+lookahead->ws_prefix_len;
283 lookahead = lookahead->next;
287 break; /* no more terms . stop . */
289 /* create the term node, but wait a moment before adding the term */
290 p = ccl_rpn_node_create(CCL_RPN_TERM);
291 p->u.t.attr_list = NULL;
295 const char *n = ccl_qual_get_name(qa[0]);
297 p->u.t.qual = xstrdup(n);
300 /* go through all attributes and add them to the attribute list */
301 for (i=0; qa && qa[i]; i++)
303 struct ccl_rpn_attr *attr;
305 for (attr = ccl_qual_get_attr(qa[i]); attr; attr = attr->next)
308 case CCL_RPN_ATTR_STRING:
309 ccl_add_attr_string(p, attr->set, attr->type,
312 case CCL_RPN_ATTR_NUMERIC:
313 if (attr->value.numeric > 0)
314 { /* deal only with REAL attributes (positive) */
318 if (relation_value != -1)
320 relation_value = attr->value.numeric;
323 if (position_value != -1)
325 position_value = attr->value.numeric;
328 if (structure_value != -1)
330 structure_value = attr->value.numeric;
333 if (truncation_value != -1)
335 truncation_value = attr->value.numeric;
338 if (completeness_value != -1)
340 completeness_value = attr->value.numeric;
343 ccl_add_attr_numeric(p, attr->set, attr->type,
344 attr->value.numeric);
348 /* len now holds the number of characters in the RPN term */
349 /* no holds the number of CCL tokens (1 or more) */
351 if (structure_value == -1 &&
352 qual_val_type(qa, CCL_BIB1_STR, CCL_BIB1_STR_WP, &attset))
353 { /* no structure attribute met. Apply either structure attribute
354 WORD or PHRASE depending on number of CCL tokens */
355 if (no == 1 && no_spaces == 0)
356 ccl_add_attr_numeric(p, attset, CCL_BIB1_STR, 2);
358 ccl_add_attr_numeric(p, attset, CCL_BIB1_STR, 1);
361 if (qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_REGEX,
364 regex_trunc = 1; /* regex trunc (102) allowed */
367 /* make the RPN token */
368 p->u.t.term = (char *)xmalloc(len * 2 + 2);
369 ccl_assert(p->u.t.term);
370 p->u.t.term[0] = '\0';
371 for (i = 0; i<no; i++)
373 const char *src_str = cclp->look_token->name;
374 size_t src_len = cclp->look_token->len;
378 if (p->u.t.term[0] && cclp->look_token->ws_prefix_len)
380 size_t len = strlen(p->u.t.term);
381 memcpy(p->u.t.term + len, cclp->look_token->ws_prefix_buf,
382 cclp->look_token->ws_prefix_len);
383 p->u.t.term[len + cclp->look_token->ws_prefix_len] = '\0';
385 for (j = 0; j < src_len; j++)
387 if (j > 0 && src_str[j-1] == '\\')
389 if (regex_trunc && strchr("()[]?*.", src_str[j]))
392 strcat(p->u.t.term, "\\\\");
394 strxcat(p->u.t.term, src_str + j, 1);
396 else if (src_str[j] == '"')
397 quote_mode = !quote_mode;
398 else if (!quote_mode && src_str[j] == '?')
402 strcat(p->u.t.term, ".*");
403 regex_trunc = 2; /* regex trunc is really needed */
405 else if (i == 0 && j == 0)
407 else if (i == no - 1 && j == src_len - 1)
411 cclp->error_code = CCL_ERR_TRUNC_NOT_BOTH;
416 else if (!quote_mode && src_str[j] == '#')
420 strcat(p->u.t.term, ".");
421 regex_trunc = 2; /* regex trunc is really needed */
425 cclp->error_code = CCL_ERR_TRUNC_NOT_BOTH;
430 else if (src_str[j] != '\\')
432 if (regex_trunc && strchr("()[]?*.", src_str[j]))
435 strcat(p->u.t.term, "\\\\");
437 strxcat(p->u.t.term, src_str + j, 1);
443 /* make the top node point to us.. */
446 struct ccl_rpn_node *tmp;
449 tmp = ccl_rpn_node_create(CCL_RPN_OR);
451 tmp = ccl_rpn_node_create(CCL_RPN_AND);
453 tmp = ccl_rpn_node_create(CCL_RPN_AND);
463 if (left_trunc && right_trunc)
465 if (!qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_BOTH,
468 cclp->error_code = CCL_ERR_TRUNC_NOT_BOTH;
472 ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 3);
474 else if (right_trunc)
476 if (!qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_RIGHT,
479 cclp->error_code = CCL_ERR_TRUNC_NOT_RIGHT;
483 ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 1);
487 if (!qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_LEFT,
490 cclp->error_code = CCL_ERR_TRUNC_NOT_LEFT;
494 ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 2);
496 else if (regex_trunc == 2)
498 ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 102);
502 if (qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_NONE,
504 ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 100);
510 cclp->error_code = CCL_ERR_TERM_EXPECTED;
514 static struct ccl_rpn_node *search_term(CCL_parser cclp, ccl_qualifier_t *qa)
516 static int list[] = {CCL_TOK_TERM, CCL_TOK_COMMA, -1};
517 return search_term_x(cclp, qa, list, 0);
521 struct ccl_rpn_node *qualifiers_order(CCL_parser cclp,
522 ccl_qualifier_t *ap, char *attset)
525 struct ccl_rpn_node *p;
527 if (cclp->look_token->len == 1)
529 if (cclp->look_token->name[0] == '<')
531 else if (cclp->look_token->name[0] == '=')
533 else if (cclp->look_token->name[0] == '>')
536 else if (cclp->look_token->len == 2)
538 if (!memcmp(cclp->look_token->name, "<=", 2))
540 else if (!memcmp(cclp->look_token->name, ">=", 2))
542 else if (!memcmp(cclp->look_token->name, "<>", 2))
547 cclp->error_code = CCL_ERR_BAD_RELATION;
550 ADVANCE; /* skip relation */
552 qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_PORDER, 0))
554 /* allow - inside term and treat it as range _always_ */
555 /* relation is =. Extract "embedded" - to separate terms */
556 if (KIND == CCL_TOK_TERM)
559 for (i = 0; i<cclp->look_token->len; i++)
561 if (cclp->look_token->name[i] == '-')
565 if (cclp->look_token->len > 1 && i == 0)
567 struct ccl_token *ntoken = ccl_token_add(cclp->look_token);
569 ntoken->kind = CCL_TOK_TERM;
570 ntoken->name = cclp->look_token->name + 1;
571 ntoken->len = cclp->look_token->len - 1;
573 cclp->look_token->len = 1;
574 cclp->look_token->name = "-";
576 else if (cclp->look_token->len > 1 && i == cclp->look_token->len-1)
578 struct ccl_token *ntoken = ccl_token_add(cclp->look_token);
580 ntoken->kind = CCL_TOK_TERM;
584 (cclp->look_token->len)--;
586 else if (cclp->look_token->len > 2 && i < cclp->look_token->len)
588 struct ccl_token *ntoken1 = ccl_token_add(cclp->look_token);
589 struct ccl_token *ntoken2 = ccl_token_add(ntoken1);
591 ntoken1->kind = CCL_TOK_TERM; /* generate - */
595 ntoken2->kind = CCL_TOK_TERM; /* generate yy */
596 ntoken2->name = cclp->look_token->name + (i+1);
597 ntoken2->len = cclp->look_token->len - (i+1);
599 cclp->look_token->len = i; /* adjust xx */
601 else if (i == cclp->look_token->len &&
602 cclp->look_token->next &&
603 cclp->look_token->next->kind == CCL_TOK_TERM &&
604 cclp->look_token->next->len > 1 &&
605 cclp->look_token->next->name[0] == '-')
608 /* we _know_ that xx does not have - in it */
609 struct ccl_token *ntoken = ccl_token_add(cclp->look_token);
611 ntoken->kind = CCL_TOK_TERM; /* generate - */
615 (ntoken->next->name)++; /* adjust yy */
616 (ntoken->next->len)--;
622 KIND == CCL_TOK_TERM &&
623 cclp->look_token->next && cclp->look_token->next->len == 1 &&
624 cclp->look_token->next->name[0] == '-')
626 struct ccl_rpn_node *p1;
627 if (!(p1 = search_term(cclp, ap)))
629 ADVANCE; /* skip '-' */
630 if (KIND == CCL_TOK_TERM) /* = term - term ? */
632 struct ccl_rpn_node *p2;
634 if (!(p2 = search_term(cclp, ap)))
639 p = ccl_rpn_node_create(CCL_RPN_AND);
641 ccl_add_attr_numeric(p1, attset, CCL_BIB1_REL, 4);
643 ccl_add_attr_numeric(p2, attset, CCL_BIB1_REL, 2);
648 ccl_add_attr_numeric(p1, attset, CCL_BIB1_REL, 4);
653 cclp->look_token->len == 1 &&
654 cclp->look_token->name[0] == '-') /* = - term ? */
657 if (!(p = search_term(cclp, ap)))
659 ccl_add_attr_numeric(p, attset, CCL_BIB1_REL, 2);
662 else if (KIND == CCL_TOK_LP)
665 if (!(p = find_spec(cclp, ap)))
667 if (KIND != CCL_TOK_RP)
669 cclp->error_code = CCL_ERR_RP_EXPECTED;
678 if (!(p = search_terms(cclp, ap)))
680 ccl_add_attr_numeric(p, attset, CCL_BIB1_REL, rel);
683 cclp->error_code = CCL_ERR_TERM_EXPECTED;
688 struct ccl_rpn_node *qualifier_relation(CCL_parser cclp, ccl_qualifier_t *ap)
691 struct ccl_rpn_node *p;
693 if (qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_ORDER, &attset)
694 || qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_PORDER, &attset))
695 return qualifiers_order(cclp, ap, attset);
697 /* unordered relation */
698 if (KIND != CCL_TOK_EQ)
700 cclp->error_code = CCL_ERR_EQ_EXPECTED;
704 if (KIND == CCL_TOK_LP)
707 if (!(p = find_spec(cclp, ap)))
711 if (KIND != CCL_TOK_RP)
713 cclp->error_code = CCL_ERR_RP_EXPECTED;
720 p = search_terms(cclp, ap);
725 * qualifier_list: Parse CCL qualifiers and search terms.
727 * la: Token pointer to RELATION token.
728 * qa: Qualifier attributes already applied.
729 * return: pointer to node(s); NULL on error.
731 static struct ccl_rpn_node *qualifier_list(CCL_parser cclp,
732 struct ccl_token *la,
735 struct ccl_token *lookahead = cclp->look_token;
736 struct ccl_token *look_start = cclp->look_token;
738 struct ccl_rpn_node *node = 0;
739 const char **field_str;
747 cclp->error_code = CCL_ERR_DOUBLE_QUAL;
751 for (lookahead = cclp->look_token; lookahead != la;
752 lookahead=lookahead->next)
755 for (i=0; qa[i]; i++)
757 ap = (ccl_qualifier_t *)xmalloc((no ? (no+1) : 2) * sizeof(*ap));
760 field_str = ccl_qual_search_special(cclp->bibset, "field");
763 if (!strcmp(field_str[0], "or"))
765 else if (!strcmp(field_str[0], "merge"))
770 /* consider each field separately and OR */
771 lookahead = look_start;
772 while (lookahead != la)
776 while ((ap[0] = ccl_qual_search(cclp, lookahead->name,
777 lookahead->len, seq)) != 0)
779 struct ccl_rpn_node *node_sub;
780 cclp->look_token = la;
782 node_sub = qualifier_relation(cclp, ap);
785 ccl_rpn_delete(node);
791 struct ccl_rpn_node *node_this =
792 ccl_rpn_node_create(CCL_RPN_OR);
793 node_this->u.p[0] = node;
794 node_this->u.p[1] = node_sub;
803 cclp->look_token = lookahead;
804 cclp->error_code = CCL_ERR_UNKNOWN_QUAL;
808 lookahead = lookahead->next;
809 if (lookahead->kind == CCL_TOK_COMMA)
810 lookahead = lookahead->next;
815 /* merge attributes from ALL fields - including inherited ones */
818 struct ccl_rpn_node *node_sub;
820 lookahead = look_start;
821 for (i = 0; lookahead != la; i++)
823 ap[i] = ccl_qual_search(cclp, lookahead->name,
824 lookahead->len, seq);
827 if (!ap[i] && seq > 0)
828 ap[i] = ccl_qual_search(cclp, lookahead->name,
832 cclp->look_token = lookahead;
833 cclp->error_code = CCL_ERR_UNKNOWN_QUAL;
837 lookahead = lookahead->next;
838 if (lookahead->kind == CCL_TOK_COMMA)
839 lookahead = lookahead->next;
843 ccl_qualifier_t *qa0 = qa;
853 cclp->look_token = lookahead;
855 node_sub = qualifier_relation(cclp, ap);
858 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;
880 * search_terms: Parse CCL search terms - including proximity.
882 * qa: Qualifier attributes already applied.
883 * return: pointer to node(s); NULL on error.
885 static struct ccl_rpn_node *search_terms(CCL_parser cclp, ccl_qualifier_t *qa)
887 static int list[] = {
888 CCL_TOK_TERM, CCL_TOK_COMMA,CCL_TOK_EQ, CCL_TOK_REL, CCL_TOK_SET, -1};
889 struct ccl_rpn_node *p1, *p2, *pn;
890 p1 = search_term_x(cclp, qa, list, 1);
895 if (KIND == CCL_TOK_PROX)
897 struct ccl_rpn_node *p_prox = 0;
898 /* ! word order specified */
899 /* % word order not specified */
900 p_prox = ccl_rpn_node_create(CCL_RPN_TERM);
901 p_prox->u.t.term = (char *) xmalloc(1 + cclp->look_token->len);
902 memcpy(p_prox->u.t.term, cclp->look_token->name,
903 cclp->look_token->len);
904 p_prox->u.t.term[cclp->look_token->len] = 0;
905 p_prox->u.t.attr_list = 0;
908 p2 = search_term_x(cclp, qa, list, 1);
914 pn = ccl_rpn_node_create(CCL_RPN_PROX);
920 else if (is_term_ok(KIND, list))
922 p2 = search_term_x(cclp, qa, list, 1);
928 pn = ccl_rpn_node_create(CCL_RPN_PROX);
941 * search_elements: Parse CCL search elements
943 * qa: Qualifier attributes already applied.
944 * return: pointer to node(s); NULL on error.
946 static struct ccl_rpn_node *search_elements(CCL_parser cclp,
949 struct ccl_rpn_node *p1;
950 struct ccl_token *lookahead;
951 if (KIND == CCL_TOK_LP)
954 p1 = find_spec(cclp, qa);
957 if (KIND != CCL_TOK_RP)
959 cclp->error_code = CCL_ERR_RP_EXPECTED;
966 else if (KIND == CCL_TOK_SET)
969 if (KIND == CCL_TOK_EQ)
971 if (KIND != CCL_TOK_TERM)
973 cclp->error_code = CCL_ERR_SETNAME_EXPECTED;
976 p1 = ccl_rpn_node_create(CCL_RPN_SET);
977 p1->u.setname = copy_token_name(cclp->look_token);
981 lookahead = cclp->look_token;
983 while (lookahead->kind==CCL_TOK_TERM)
985 lookahead = lookahead->next;
986 if (lookahead->kind == CCL_TOK_REL || lookahead->kind == CCL_TOK_EQ)
987 return qualifier_list(cclp, lookahead, qa);
988 if (lookahead->kind != CCL_TOK_COMMA)
990 lookahead = lookahead->next;
993 return search_terms(cclp, qa);
996 ccl_qualifier_t qa[2];
997 struct ccl_rpn_node *node = 0;
999 lookahead = cclp->look_token;
1002 for(seq = 0; ;seq++)
1004 struct ccl_rpn_node *node_sub;
1005 qa[0] = ccl_qual_search(cclp, "term", 4, seq);
1009 cclp->look_token = lookahead;
1011 node_sub = search_terms(cclp, qa);
1014 ccl_rpn_delete(node);
1019 struct ccl_rpn_node *node_this =
1020 ccl_rpn_node_create(CCL_RPN_OR);
1021 node_this->u.p[0] = node;
1022 node_this->u.p[1] = node_sub;
1023 node_this->u.p[2] = 0;
1030 node = search_terms(cclp, 0);
1036 * find_spec: Parse CCL find specification
1038 * qa: Qualifier attributes already applied.
1039 * return: pointer to node(s); NULL on error.
1041 static struct ccl_rpn_node *find_spec(CCL_parser cclp, ccl_qualifier_t *qa)
1043 struct ccl_rpn_node *p1, *p2, *pn;
1044 if (!(p1 = search_elements(cclp, qa)))
1052 p2 = search_elements(cclp, qa);
1058 pn = ccl_rpn_node_create(CCL_RPN_AND);
1066 p2 = search_elements(cclp, qa);
1072 pn = ccl_rpn_node_create(CCL_RPN_OR);
1080 p2 = search_elements(cclp, qa);
1086 pn = ccl_rpn_node_create(CCL_RPN_NOT);
1098 struct ccl_rpn_node *ccl_parser_find_str(CCL_parser cclp, const char *str)
1100 struct ccl_rpn_node *p;
1101 struct ccl_token *list = ccl_parser_tokenize(cclp, str);
1102 p = ccl_parser_find_token(cclp, list);
1103 ccl_token_del(list);
1107 struct ccl_rpn_node *ccl_parser_find_token(CCL_parser cclp,
1108 struct ccl_token *list)
1110 struct ccl_rpn_node *p;
1112 cclp->look_token = list;
1113 p = find_spec(cclp, NULL);
1114 if (p && KIND != CCL_TOK_EOL)
1116 if (KIND == CCL_TOK_RP)
1117 cclp->error_code = CCL_ERR_BAD_RP;
1119 cclp->error_code = CCL_ERR_OP_EXPECTED;
1123 cclp->error_pos = cclp->look_token->name;
1125 cclp->error_code = CCL_ERR_OK;
1127 cclp->error_code = cclp->error_code;
1132 * ccl_find_str: Parse CCL find - string representation
1133 * bibset: Bibset to be used for the parsing
1134 * str: String to be parsed
1135 * error: Pointer to integer. Holds error no. on completion.
1136 * pos: Pointer to char position. Holds approximate error position.
1137 * return: RPN tree on successful completion; NULL otherwise.
1139 struct ccl_rpn_node *ccl_find_str(CCL_bibset bibset, const char *str,
1140 int *error, int *pos)
1142 CCL_parser cclp = ccl_parser_create(bibset);
1143 struct ccl_token *list;
1144 struct ccl_rpn_node *p;
1146 list = ccl_parser_tokenize(cclp, str);
1147 p = ccl_parser_find_token(cclp, list);
1149 *error = cclp->error_code;
1151 *pos = cclp->error_pos - str;
1152 ccl_parser_destroy(cclp);
1153 ccl_token_del(list);
1160 * c-file-style: "Stroustrup"
1161 * indent-tabs-mode: nil
1163 * vim: shiftwidth=4 tabstop=8 expandtab