1 /* $Id: cql.y,v 1.6 2003-09-04 18:13: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 GE LE NE
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);
117 /* unary NOT search TERM here .. */
120 AND | OR | NOT | PROX proxqualifiers {
128 $$.rel = cql_node_mk_proxargs ($1.buf, 0, 0, 0);
131 PrelationO Pdistance {
132 $$.rel = cql_node_mk_proxargs ($1.buf, $2.buf, 0, 0);
135 PrelationO PdistanceO Punit {
136 $$.rel = cql_node_mk_proxargs ($1.buf, $2.buf, $3.buf, 0);
139 PrelationO PdistanceO PunitO Pordering {
140 $$.rel = cql_node_mk_proxargs ($1.buf, $2.buf, $3.buf, $4.buf);
146 Punit: '/' searchTerm {
151 PunitO: '/' searchTerm {
155 '/' { $$.buf[0] = 0; }
157 Prelation: '/' baseRelation {
161 PrelationO: '/' baseRelation {
164 | '/' { $$.buf[0] = 0; }
166 Pdistance: '/' searchTerm {
171 PdistanceO: '/' searchTerm {
174 | '/' { $$.buf[0] = 0; }
176 Pordering: '/' searchTerm {
181 relation: baseRelation modifiers {
182 struct cql_node *st = cql_node_mk_sc(/* index */ 0,
183 /* relation */ $1.buf,
186 st->u.st.modifiers = $2.cql;
191 modifiers: '/' searchTerm modifiers
193 struct cql_node *mod = cql_node_mk_mod(0, $2.buf);
195 mod->u.mod.next = $3.cql;
235 int cql_parser_stream(CQL_parser cp,
236 int (*getbyte)(void *client_data),
237 void (*ungetbyte)(int b, void *client_data),
240 cp->getbyte = getbyte;
241 cp->ungetbyte = ungetbyte;
242 cp->client_data = client_data;
244 cql_node_destroy(cp->top);
251 CQL_parser cql_parser_create(void)
253 CQL_parser cp = (CQL_parser) malloc (sizeof(*cp));
261 cp->nmem = nmem_create();
265 void cql_parser_destroy(CQL_parser cp)
267 cql_node_destroy(cp->top);
268 nmem_destroy(cp->nmem);
272 struct cql_node *cql_parser_result(CQL_parser cp)