1 /* $Id: cql.y,v 1.4 2003-04-11 15:53:39 adam Exp $
2 Copyright (C) 2002-2003
5 This file is part of the YAZ toolkit.
9 bison parser for CQL grammar.
28 int (*getbyte)(void *client_data);
29 void (*ungetbyte)(int b, void *client_data);
39 #define YYPARSE_PARAM parm
40 #define YYLEX_PARAM parm
42 int yylex(YYSTYPE *lval, void *vp);
47 %token TERM AND OR NOT PROX EXACT ALL ANY GE LE NE SCR
53 $$.rel = cql_node_mk_sc("srw.serverChoice", "scr", 0);
54 ((CQL_parser) parm)->top = 0;
56 cql_node_destroy($$.rel);
57 ((CQL_parser) parm)->top = $2.cql;
63 cql_node_destroy($1.cql);
74 struct cql_node *cn = cql_node_mk_boolean($2.buf);
76 cn->u.boolean.modifiers = $2.rel;
77 cn->u.boolean.left = $1.cql;
78 cn->u.boolean.right = $4.cql;
93 struct cql_node *st = cql_node_dup ($0.rel);
94 st->u.st.term = strdup($1.buf);
100 $$.rel->u.st.index = strdup($1.buf);
103 cql_node_destroy($2.rel);
105 | '>' searchTerm '=' searchTerm {
108 $$.cql = cql_node_prefix($6.cql, $2.buf, $4.buf);
113 $$.cql = cql_node_prefix($4.cql, 0, $2.buf);
118 AND | OR | NOT | PROX proxqualifiers {
126 $$.rel = cql_node_mk_proxargs ($1.buf, 0, 0, 0);
129 PrelationO Pdistance {
130 $$.rel = cql_node_mk_proxargs ($1.buf, $2.buf, 0, 0);
133 PrelationO PdistanceO Punit {
134 $$.rel = cql_node_mk_proxargs ($1.buf, $2.buf, $3.buf, 0);
137 PrelationO PdistanceO PunitO Pordering {
138 $$.rel = cql_node_mk_proxargs ($1.buf, $2.buf, $3.buf, $4.buf);
144 Punit: '/' searchTerm {
149 PunitO: '/' searchTerm {
153 '/' { $$.buf[0] = 0; }
155 Prelation: '/' baseRelation {
159 PrelationO: '/' baseRelation {
162 | '/' { $$.buf[0] = 0; }
164 Pdistance: '/' searchTerm {
169 PdistanceO: '/' searchTerm {
172 | '/' { $$.buf[0] = 0; }
174 Pordering: '/' searchTerm {
179 relation: baseRelation modifiers {
180 struct cql_node *st = cql_node_mk_sc(/* index */ 0,
181 /* relation */ $1.buf,
184 st->u.st.modifiers = $2.cql;
189 modifiers: '/' searchTerm modifiers
191 struct cql_node *mod = cql_node_mk_mod(0, $2.buf);
193 mod->u.mod.next = $3.cql;
239 int cql_parser_stream(CQL_parser cp,
240 int (*getbyte)(void *client_data),
241 void (*ungetbyte)(int b, void *client_data),
244 cp->getbyte = getbyte;
245 cp->ungetbyte = ungetbyte;
246 cp->client_data = client_data;
253 CQL_parser cql_parser_create(void)
255 CQL_parser cp = (CQL_parser) malloc (sizeof(*cp));
263 cp->nmem = nmem_create();
267 void cql_parser_destroy(CQL_parser cp)
269 cql_node_destroy(cp->top);
270 nmem_destroy(cp->nmem);
274 struct cql_node *cql_parser_result(CQL_parser cp)