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);
216 #define REGEX_CHARS "^[]{}()|.*+?!\"$"
218 * search_term: Parse CCL search term.
220 * qa: Qualifier attributes already applied.
221 * term_list: tokens we accept as terms in context
222 * multi: whether we accept "multiple" tokens
223 * return: pointer to node(s); NULL on error.
225 static struct ccl_rpn_node *search_term_x(CCL_parser cclp,
227 int *term_list, int multi)
229 struct ccl_rpn_node *p_top = 0;
230 struct ccl_token *lookahead = cclp->look_token;
234 const char **truncation_aliases;
235 const char *t_default[2];
238 ccl_qual_search_special(cclp->bibset, "truncation");
239 if (!truncation_aliases)
241 truncation_aliases = t_default;
246 if (qual_val_type(qa, CCL_BIB1_STR, CCL_BIB1_STR_AND_LIST, 0))
248 if (qual_val_type(qa, CCL_BIB1_STR, CCL_BIB1_STR_OR_LIST, 0))
252 struct ccl_rpn_node *p;
255 int relation_value = -1;
256 int position_value = -1;
257 int structure_value = -1;
258 int truncation_value = -1;
259 int completeness_value = -1;
265 if (and_list || or_list || !multi)
268 /* ignore commas when dealing with and-lists .. */
269 if (and_list && lookahead && lookahead->kind == CCL_TOK_COMMA)
271 lookahead = lookahead->next;
275 /* go through each TERM token. If no truncation attribute is yet
276 met, then look for left/right truncation markers (?) and
277 set left_trunc/right_trunc/mid_trunc accordingly */
278 for (no = 0; no < max && is_term_ok(lookahead->kind, term_list); no++)
280 for (i = 0; i<lookahead->len; i++)
281 if (lookahead->name[i] == ' ')
283 len += 1+lookahead->len+lookahead->ws_prefix_len;
284 lookahead = lookahead->next;
288 break; /* no more terms . stop . */
290 /* create the term node, but wait a moment before adding the term */
291 p = ccl_rpn_node_create(CCL_RPN_TERM);
292 p->u.t.attr_list = NULL;
296 const char *n = ccl_qual_get_name(qa[0]);
298 p->u.t.qual = xstrdup(n);
301 /* go through all attributes and add them to the attribute list */
302 for (i=0; qa && qa[i]; i++)
304 struct ccl_rpn_attr *attr;
306 for (attr = ccl_qual_get_attr(qa[i]); attr; attr = attr->next)
309 case CCL_RPN_ATTR_STRING:
310 ccl_add_attr_string(p, attr->set, attr->type,
313 case CCL_RPN_ATTR_NUMERIC:
314 if (attr->value.numeric > 0)
315 { /* deal only with REAL attributes (positive) */
319 if (relation_value != -1)
321 relation_value = attr->value.numeric;
324 if (position_value != -1)
326 position_value = attr->value.numeric;
329 if (structure_value != -1)
331 structure_value = attr->value.numeric;
334 if (truncation_value != -1)
336 truncation_value = attr->value.numeric;
339 if (completeness_value != -1)
341 completeness_value = attr->value.numeric;
344 ccl_add_attr_numeric(p, attr->set, attr->type,
345 attr->value.numeric);
349 /* len now holds the number of characters in the RPN term */
350 /* no holds the number of CCL tokens (1 or more) */
352 if (structure_value == -1 &&
353 qual_val_type(qa, CCL_BIB1_STR, CCL_BIB1_STR_WP, &attset))
354 { /* no structure attribute met. Apply either structure attribute
355 WORD or PHRASE depending on number of CCL tokens */
356 if (no == 1 && no_spaces == 0)
357 ccl_add_attr_numeric(p, attset, CCL_BIB1_STR, 2);
359 ccl_add_attr_numeric(p, attset, CCL_BIB1_STR, 1);
362 if (qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_REGEX,
365 regex_trunc = 1; /* regex trunc (102) allowed */
368 /* make the RPN token */
369 p->u.t.term = (char *)xmalloc(len * 2 + 2);
370 ccl_assert(p->u.t.term);
371 p->u.t.term[0] = '\0';
372 for (i = 0; i<no; i++)
374 const char *src_str = cclp->look_token->name;
375 size_t src_len = cclp->look_token->len;
379 if (p->u.t.term[0] && cclp->look_token->ws_prefix_len)
381 size_t len = strlen(p->u.t.term);
382 memcpy(p->u.t.term + len, cclp->look_token->ws_prefix_buf,
383 cclp->look_token->ws_prefix_len);
384 p->u.t.term[len + cclp->look_token->ws_prefix_len] = '\0';
386 for (j = 0; j < src_len; j++)
388 if (j > 0 && src_str[j-1] == '\\')
390 if (regex_trunc && strchr(REGEX_CHARS "\\", src_str[j]))
393 strcat(p->u.t.term, "\\\\");
395 if (src_str[j] == '\\')
396 strcat(p->u.t.term, "\\");
397 strxcat(p->u.t.term, src_str + j, 1);
399 else if (src_str[j] == '"')
400 quote_mode = !quote_mode;
401 else if (!quote_mode && src_str[j] == '?')
405 strcat(p->u.t.term, ".*");
406 regex_trunc = 2; /* regex trunc is really needed */
408 else if (i == 0 && j == 0)
410 else if (i == no - 1 && j == src_len - 1)
414 cclp->error_code = CCL_ERR_TRUNC_NOT_BOTH;
419 else if (!quote_mode && src_str[j] == '#')
423 strcat(p->u.t.term, ".");
424 regex_trunc = 2; /* regex trunc is really needed */
428 cclp->error_code = CCL_ERR_TRUNC_NOT_BOTH;
433 else if (src_str[j] != '\\')
435 if (regex_trunc && strchr(REGEX_CHARS, src_str[j]))
438 strcat(p->u.t.term, "\\\\");
440 strxcat(p->u.t.term, src_str + j, 1);
446 /* make the top node point to us.. */
449 struct ccl_rpn_node *tmp;
452 tmp = ccl_rpn_node_create(CCL_RPN_OR);
454 tmp = ccl_rpn_node_create(CCL_RPN_AND);
456 tmp = ccl_rpn_node_create(CCL_RPN_AND);
466 if (left_trunc && right_trunc)
468 if (!qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_BOTH,
471 cclp->error_code = CCL_ERR_TRUNC_NOT_BOTH;
475 ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 3);
477 else if (right_trunc)
479 if (!qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_RIGHT,
482 cclp->error_code = CCL_ERR_TRUNC_NOT_RIGHT;
486 ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 1);
490 if (!qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_LEFT,
493 cclp->error_code = CCL_ERR_TRUNC_NOT_LEFT;
497 ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 2);
499 else if (regex_trunc == 2)
501 ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 102);
505 if (qual_val_type(qa, CCL_BIB1_TRU, CCL_BIB1_TRU_CAN_NONE,
507 ccl_add_attr_numeric(p, attset, CCL_BIB1_TRU, 100);
513 cclp->error_code = CCL_ERR_TERM_EXPECTED;
517 static struct ccl_rpn_node *search_term(CCL_parser cclp, ccl_qualifier_t *qa)
519 static int list[] = {CCL_TOK_TERM, CCL_TOK_COMMA, -1};
520 return search_term_x(cclp, qa, list, 0);
524 struct ccl_rpn_node *qualifiers_order(CCL_parser cclp,
525 ccl_qualifier_t *ap, char *attset)
528 struct ccl_rpn_node *p;
530 if (cclp->look_token->len == 1)
532 if (cclp->look_token->name[0] == '<')
534 else if (cclp->look_token->name[0] == '=')
536 else if (cclp->look_token->name[0] == '>')
539 else if (cclp->look_token->len == 2)
541 if (!memcmp(cclp->look_token->name, "<=", 2))
543 else if (!memcmp(cclp->look_token->name, ">=", 2))
545 else if (!memcmp(cclp->look_token->name, "<>", 2))
550 cclp->error_code = CCL_ERR_BAD_RELATION;
553 ADVANCE; /* skip relation */
555 qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_PORDER, 0))
557 /* allow - inside term and treat it as range _always_ */
558 /* relation is =. Extract "embedded" - to separate terms */
559 if (KIND == CCL_TOK_TERM)
562 for (i = 0; i<cclp->look_token->len; i++)
564 if (cclp->look_token->name[i] == '-')
568 if (cclp->look_token->len > 1 && i == 0)
570 struct ccl_token *ntoken = ccl_token_add(cclp->look_token);
572 ntoken->kind = CCL_TOK_TERM;
573 ntoken->name = cclp->look_token->name + 1;
574 ntoken->len = cclp->look_token->len - 1;
576 cclp->look_token->len = 1;
577 cclp->look_token->name = "-";
579 else if (cclp->look_token->len > 1 && i == cclp->look_token->len-1)
581 struct ccl_token *ntoken = ccl_token_add(cclp->look_token);
583 ntoken->kind = CCL_TOK_TERM;
587 (cclp->look_token->len)--;
589 else if (cclp->look_token->len > 2 && i < cclp->look_token->len)
591 struct ccl_token *ntoken1 = ccl_token_add(cclp->look_token);
592 struct ccl_token *ntoken2 = ccl_token_add(ntoken1);
594 ntoken1->kind = CCL_TOK_TERM; /* generate - */
598 ntoken2->kind = CCL_TOK_TERM; /* generate yy */
599 ntoken2->name = cclp->look_token->name + (i+1);
600 ntoken2->len = cclp->look_token->len - (i+1);
602 cclp->look_token->len = i; /* adjust xx */
604 else if (i == cclp->look_token->len &&
605 cclp->look_token->next &&
606 cclp->look_token->next->kind == CCL_TOK_TERM &&
607 cclp->look_token->next->len > 1 &&
608 cclp->look_token->next->name[0] == '-')
611 /* we _know_ that xx does not have - in it */
612 struct ccl_token *ntoken = ccl_token_add(cclp->look_token);
614 ntoken->kind = CCL_TOK_TERM; /* generate - */
618 (ntoken->next->name)++; /* adjust yy */
619 (ntoken->next->len)--;
625 KIND == CCL_TOK_TERM &&
626 cclp->look_token->next && cclp->look_token->next->len == 1 &&
627 cclp->look_token->next->name[0] == '-')
629 struct ccl_rpn_node *p1;
630 if (!(p1 = search_term(cclp, ap)))
632 ADVANCE; /* skip '-' */
633 if (KIND == CCL_TOK_TERM) /* = term - term ? */
635 struct ccl_rpn_node *p2;
637 if (!(p2 = search_term(cclp, ap)))
642 p = ccl_rpn_node_create(CCL_RPN_AND);
644 ccl_add_attr_numeric(p1, attset, CCL_BIB1_REL, 4);
646 ccl_add_attr_numeric(p2, attset, CCL_BIB1_REL, 2);
651 ccl_add_attr_numeric(p1, attset, CCL_BIB1_REL, 4);
656 cclp->look_token->len == 1 &&
657 cclp->look_token->name[0] == '-') /* = - term ? */
660 if (!(p = search_term(cclp, ap)))
662 ccl_add_attr_numeric(p, attset, CCL_BIB1_REL, 2);
665 else if (KIND == CCL_TOK_LP)
668 if (!(p = find_spec(cclp, ap)))
670 if (KIND != CCL_TOK_RP)
672 cclp->error_code = CCL_ERR_RP_EXPECTED;
681 if (!(p = search_terms(cclp, ap)))
683 ccl_add_attr_numeric(p, attset, CCL_BIB1_REL, rel);
686 cclp->error_code = CCL_ERR_TERM_EXPECTED;
691 struct ccl_rpn_node *qualifier_relation(CCL_parser cclp, ccl_qualifier_t *ap)
694 struct ccl_rpn_node *p;
696 if (qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_ORDER, &attset)
697 || qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_PORDER, &attset))
698 return qualifiers_order(cclp, ap, attset);
700 /* unordered relation */
701 if (KIND != CCL_TOK_EQ)
703 cclp->error_code = CCL_ERR_EQ_EXPECTED;
707 if (KIND == CCL_TOK_LP)
710 if (!(p = find_spec(cclp, ap)))
714 if (KIND != CCL_TOK_RP)
716 cclp->error_code = CCL_ERR_RP_EXPECTED;
723 p = search_terms(cclp, ap);
728 * qualifier_list: Parse CCL qualifiers and search terms.
730 * la: Token pointer to RELATION token.
731 * qa: Qualifier attributes already applied.
732 * return: pointer to node(s); NULL on error.
734 static struct ccl_rpn_node *qualifier_list(CCL_parser cclp,
735 struct ccl_token *la,
738 struct ccl_token *lookahead = cclp->look_token;
739 struct ccl_token *look_start = cclp->look_token;
741 struct ccl_rpn_node *node = 0;
742 const char **field_str;
750 cclp->error_code = CCL_ERR_DOUBLE_QUAL;
754 for (lookahead = cclp->look_token; lookahead != la;
755 lookahead=lookahead->next)
758 for (i=0; qa[i]; i++)
760 ap = (ccl_qualifier_t *)xmalloc((no ? (no+1) : 2) * sizeof(*ap));
763 field_str = ccl_qual_search_special(cclp->bibset, "field");
766 if (!strcmp(field_str[0], "or"))
768 else if (!strcmp(field_str[0], "merge"))
773 /* consider each field separately and OR */
774 lookahead = look_start;
775 while (lookahead != la)
779 while ((ap[0] = ccl_qual_search(cclp, lookahead->name,
780 lookahead->len, seq)) != 0)
782 struct ccl_rpn_node *node_sub;
783 cclp->look_token = la;
785 node_sub = qualifier_relation(cclp, ap);
788 ccl_rpn_delete(node);
794 struct ccl_rpn_node *node_this =
795 ccl_rpn_node_create(CCL_RPN_OR);
796 node_this->u.p[0] = node;
797 node_this->u.p[1] = node_sub;
806 cclp->look_token = lookahead;
807 cclp->error_code = CCL_ERR_UNKNOWN_QUAL;
811 lookahead = lookahead->next;
812 if (lookahead->kind == CCL_TOK_COMMA)
813 lookahead = lookahead->next;
818 /* merge attributes from ALL fields - including inherited ones */
821 struct ccl_rpn_node *node_sub;
823 lookahead = look_start;
824 for (i = 0; lookahead != la; i++)
826 ap[i] = ccl_qual_search(cclp, lookahead->name,
827 lookahead->len, seq);
830 if (!ap[i] && seq > 0)
831 ap[i] = ccl_qual_search(cclp, lookahead->name,
835 cclp->look_token = lookahead;
836 cclp->error_code = CCL_ERR_UNKNOWN_QUAL;
840 lookahead = lookahead->next;
841 if (lookahead->kind == CCL_TOK_COMMA)
842 lookahead = lookahead->next;
846 ccl_qualifier_t *qa0 = qa;
856 cclp->look_token = lookahead;
858 node_sub = qualifier_relation(cclp, ap);
861 ccl_rpn_delete(node);
866 struct ccl_rpn_node *node_this =
867 ccl_rpn_node_create(CCL_RPN_OR);
868 node_this->u.p[0] = node;
869 node_this->u.p[1] = node_sub;
883 * search_terms: Parse CCL search terms - including proximity.
885 * qa: Qualifier attributes already applied.
886 * return: pointer to node(s); NULL on error.
888 static struct ccl_rpn_node *search_terms(CCL_parser cclp, ccl_qualifier_t *qa)
890 static int list[] = {
891 CCL_TOK_TERM, CCL_TOK_COMMA,CCL_TOK_EQ, CCL_TOK_REL, CCL_TOK_SET, -1};
892 struct ccl_rpn_node *p1, *p2, *pn;
893 p1 = search_term_x(cclp, qa, list, 1);
898 if (KIND == CCL_TOK_PROX)
900 struct ccl_rpn_node *p_prox = 0;
901 /* ! word order specified */
902 /* % word order not specified */
903 p_prox = ccl_rpn_node_create(CCL_RPN_TERM);
904 p_prox->u.t.term = (char *) xmalloc(1 + cclp->look_token->len);
905 memcpy(p_prox->u.t.term, cclp->look_token->name,
906 cclp->look_token->len);
907 p_prox->u.t.term[cclp->look_token->len] = 0;
908 p_prox->u.t.attr_list = 0;
911 p2 = search_term_x(cclp, qa, list, 1);
917 pn = ccl_rpn_node_create(CCL_RPN_PROX);
923 else if (is_term_ok(KIND, list))
925 p2 = search_term_x(cclp, qa, list, 1);
931 pn = ccl_rpn_node_create(CCL_RPN_PROX);
944 * search_elements: Parse CCL search elements
946 * qa: Qualifier attributes already applied.
947 * return: pointer to node(s); NULL on error.
949 static struct ccl_rpn_node *search_elements(CCL_parser cclp,
952 struct ccl_rpn_node *p1;
953 struct ccl_token *lookahead;
954 if (KIND == CCL_TOK_LP)
957 p1 = find_spec(cclp, qa);
960 if (KIND != CCL_TOK_RP)
962 cclp->error_code = CCL_ERR_RP_EXPECTED;
969 else if (KIND == CCL_TOK_SET)
972 if (KIND == CCL_TOK_EQ)
974 if (KIND != CCL_TOK_TERM)
976 cclp->error_code = CCL_ERR_SETNAME_EXPECTED;
979 p1 = ccl_rpn_node_create(CCL_RPN_SET);
980 p1->u.setname = copy_token_name(cclp->look_token);
984 lookahead = cclp->look_token;
986 while (lookahead->kind==CCL_TOK_TERM)
988 lookahead = lookahead->next;
989 if (lookahead->kind == CCL_TOK_REL || lookahead->kind == CCL_TOK_EQ)
990 return qualifier_list(cclp, lookahead, qa);
991 if (lookahead->kind != CCL_TOK_COMMA)
993 lookahead = lookahead->next;
996 return search_terms(cclp, qa);
999 ccl_qualifier_t qa[2];
1000 struct ccl_rpn_node *node = 0;
1002 lookahead = cclp->look_token;
1005 for(seq = 0; ;seq++)
1007 struct ccl_rpn_node *node_sub;
1008 qa[0] = ccl_qual_search(cclp, "term", 4, seq);
1012 cclp->look_token = lookahead;
1014 node_sub = search_terms(cclp, qa);
1017 ccl_rpn_delete(node);
1022 struct ccl_rpn_node *node_this =
1023 ccl_rpn_node_create(CCL_RPN_OR);
1024 node_this->u.p[0] = node;
1025 node_this->u.p[1] = node_sub;
1026 node_this->u.p[2] = 0;
1033 node = search_terms(cclp, 0);
1039 * find_spec: Parse CCL find specification
1041 * qa: Qualifier attributes already applied.
1042 * return: pointer to node(s); NULL on error.
1044 static struct ccl_rpn_node *find_spec(CCL_parser cclp, ccl_qualifier_t *qa)
1046 struct ccl_rpn_node *p1, *p2, *pn;
1047 if (!(p1 = search_elements(cclp, qa)))
1055 p2 = search_elements(cclp, qa);
1061 pn = ccl_rpn_node_create(CCL_RPN_AND);
1069 p2 = search_elements(cclp, qa);
1075 pn = ccl_rpn_node_create(CCL_RPN_OR);
1083 p2 = search_elements(cclp, qa);
1089 pn = ccl_rpn_node_create(CCL_RPN_NOT);
1101 struct ccl_rpn_node *ccl_parser_find_str(CCL_parser cclp, const char *str)
1103 struct ccl_rpn_node *p;
1104 struct ccl_token *list = ccl_parser_tokenize(cclp, str);
1105 p = ccl_parser_find_token(cclp, list);
1106 ccl_token_del(list);
1110 struct ccl_rpn_node *ccl_parser_find_token(CCL_parser cclp,
1111 struct ccl_token *list)
1113 struct ccl_rpn_node *p;
1115 cclp->look_token = list;
1116 p = find_spec(cclp, NULL);
1117 if (p && KIND != CCL_TOK_EOL)
1119 if (KIND == CCL_TOK_RP)
1120 cclp->error_code = CCL_ERR_BAD_RP;
1122 cclp->error_code = CCL_ERR_OP_EXPECTED;
1126 cclp->error_pos = cclp->look_token->name;
1128 cclp->error_code = CCL_ERR_OK;
1130 cclp->error_code = cclp->error_code;
1135 * ccl_find_str: Parse CCL find - string representation
1136 * bibset: Bibset to be used for the parsing
1137 * str: String to be parsed
1138 * error: Pointer to integer. Holds error no. on completion.
1139 * pos: Pointer to char position. Holds approximate error position.
1140 * return: RPN tree on successful completion; NULL otherwise.
1142 struct ccl_rpn_node *ccl_find_str(CCL_bibset bibset, const char *str,
1143 int *error, int *pos)
1145 CCL_parser cclp = ccl_parser_create(bibset);
1146 struct ccl_token *list;
1147 struct ccl_rpn_node *p;
1149 list = ccl_parser_tokenize(cclp, str);
1150 p = ccl_parser_find_token(cclp, list);
1152 *error = cclp->error_code;
1154 *pos = cclp->error_pos - str;
1155 ccl_parser_destroy(cclp);
1156 ccl_token_del(list);
1163 * c-file-style: "Stroustrup"
1164 * indent-tabs-mode: nil
1166 * vim: shiftwidth=4 tabstop=8 expandtab