projects
/
yaz-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Ignore generated diagsru_update.h
[yaz-moved-to-github.git]
/
src
/
cql.y
diff --git
a/src/cql.y
b/src/cql.y
index
8b3d3ee
..
f4293e7
100644
(file)
--- a/
src/cql.y
+++ b/
src/cql.y
@@
-1,6
+1,6
@@
-/* $Id: cql.y,v 1.4 2004-03-17 18:31:11 adam Exp $
- Copyright (C) 2002-2004
- Index Data Aps
+/* $Id: cql.y,v 1.11 2006-10-05 16:19:16 adam Exp $
+ Copyright (C) 2002-2006
+ Index Data ApS
This file is part of the YAZ toolkit.
This file is part of the YAZ toolkit.
@@
-9,6
+9,13
@@
See the file LICENSE.
bison parser for CQL grammar.
*/
%{
bison parser for CQL grammar.
*/
%{
+/**
+ * \file cql.c
+ * \brief Implements CQL parser.
+ *
+ * This is a YACC parser, but since it must be reentrant, Bison is required.
+ * The original source file is cql.y.
+ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@
-16,12
+23,18
@@
See the file LICENSE.
#include <yaz/xmalloc.h>
#include <yaz/nmem.h>
#include <yaz/cql.h>
#include <yaz/xmalloc.h>
#include <yaz/nmem.h>
#include <yaz/cql.h>
-
+
+ /** Node in the LALR parse tree. */
typedef struct {
typedef struct {
+ /** Inhereted attribute: relation */
struct cql_node *rel;
struct cql_node *rel;
+ /** Synthesized attribute: CQL node */
struct cql_node *cql;
struct cql_node *cql;
+ /** string buffer with token */
char *buf;
char *buf;
+ /** length of token */
size_t len;
size_t len;
+ /** size of buffer (len <= size) */
size_t size;
} token;
size_t size;
} token;
@@
-51,7
+64,8
@@
See the file LICENSE.
%%
top: {
%%
top: {
- $$.rel = cql_node_mk_sc("cql.serverChoice", "scr", 0);
+ $$.rel = cql_node_mk_sc(((CQL_parser) parm)->nmem,
+ "cql.serverChoice", "scr", 0);
((CQL_parser) parm)->top = 0;
} cqlQuery1 {
cql_node_destroy($$.rel);
((CQL_parser) parm)->top = 0;
} cqlQuery1 {
cql_node_destroy($$.rel);
@@
-72,7
+86,8
@@
cqlQuery:
cqlQuery boolean modifiers {
$$.rel = $0.rel;
} searchClause {
cqlQuery boolean modifiers {
$$.rel = $0.rel;
} searchClause {
- struct cql_node *cn = cql_node_mk_boolean($2.buf);
+ struct cql_node *cn = cql_node_mk_boolean(((CQL_parser) parm)->nmem,
+ $2.buf);
cn->u.boolean.modifiers = $3.cql;
cn->u.boolean.left = $1.cql;
cn->u.boolean.modifiers = $3.cql;
cn->u.boolean.left = $1.cql;
@@
-91,13
+106,13
@@
searchClause:
}
|
searchTerm {
}
|
searchTerm {
- struct cql_node *st = cql_node_dup ($0.rel);
- st->u.st.term = xstrdup($1.buf);
+ struct cql_node *st = cql_node_dup (((CQL_parser) parm)->nmem, $0.rel);
+ st->u.st.term = nmem_strdup(((CQL_parser)parm)->nmem, $1.buf);
$$.cql = st;
}
|
index relation modifiers {
$$.cql = st;
}
|
index relation modifiers {
- $$.rel = cql_node_mk_sc($1.buf, $2.buf, 0);
+ $$.rel = cql_node_mk_sc(((CQL_parser) parm)->nmem, $1.buf, $2.buf, 0);
$$.rel->u.st.modifiers = $3.cql;
} searchClause {
$$.cql = $5.cql;
$$.rel->u.st.modifiers = $3.cql;
} searchClause {
$$.cql = $5.cql;
@@
-106,12
+121,14
@@
searchClause:
| '>' searchTerm '=' searchTerm {
$$.rel = $0.rel;
} cqlQuery {
| '>' searchTerm '=' searchTerm {
$$.rel = $0.rel;
} cqlQuery {
- $$.cql = cql_apply_prefix($6.cql, $2.buf, $4.buf);
+ $$.cql = cql_apply_prefix(((CQL_parser) parm)->nmem,
+ $6.cql, $2.buf, $4.buf);
}
| '>' searchTerm {
$$.rel = $0.rel;
} cqlQuery {
}
| '>' searchTerm {
$$.rel = $0.rel;
} cqlQuery {
- $$.cql = cql_apply_prefix($4.cql, 0, $2.buf);
+ $$.cql = cql_apply_prefix(((CQL_parser) parm)->nmem,
+ $4.cql, 0, $2.buf);
}
;
}
;
@@
-123,7
+140,8
@@
boolean:
modifiers: modifiers '/' searchTerm
{
modifiers: modifiers '/' searchTerm
{
- struct cql_node *mod = cql_node_mk_sc($3.buf, "=", 0);
+ struct cql_node *mod = cql_node_mk_sc(((CQL_parser)parm)->nmem,
+ $3.buf, "=", 0);
mod->u.st.modifiers = $1.cql;
$$.cql = mod;
mod->u.st.modifiers = $1.cql;
$$.cql = mod;
@@
-131,7
+149,8
@@
modifiers: modifiers '/' searchTerm
|
modifiers '/' searchTerm mrelation searchTerm
{
|
modifiers '/' searchTerm mrelation searchTerm
{
- struct cql_node *mod = cql_node_mk_sc($3.buf, $4.buf, $5.buf);
+ struct cql_node *mod = cql_node_mk_sc(((CQL_parser)parm)->nmem,
+ $3.buf, $4.buf, $5.buf);
mod->u.st.modifiers = $1.cql;
$$.cql = mod;
mod->u.st.modifiers = $1.cql;
$$.cql = mod;
@@
-179,15
+198,18
@@
int yyerror(char *s)
return 0;
}
return 0;
}
-/*
- * bison lexer for CQL.
+/**
+ * putb is a utility that puts one character to the string
+ * in current lexical token. This routine deallocates as
+ * necessary using NMEM.
*/
static void putb(YYSTYPE *lval, CQL_parser cp, int c)
{
if (lval->len+1 >= lval->size)
{
*/
static void putb(YYSTYPE *lval, CQL_parser cp, int c)
{
if (lval->len+1 >= lval->size)
{
- char *nb = nmem_malloc(cp->nmem, (lval->size = lval->len * 2 + 20));
+ char *nb = (char *)
+ nmem_malloc(cp->nmem, (lval->size = lval->len * 2 + 20));
memcpy (nb, lval->buf, lval->len);
lval->buf = nb;
}
memcpy (nb, lval->buf, lval->len);
lval->buf = nb;
}
@@
-197,6
+219,10
@@
static void putb(YYSTYPE *lval, CQL_parser cp, int c)
}
}
+/**
+ * yylex returns next token for Bison to be read. In this
+ * case one of the CQL terminals are returned.
+ */
int yylex(YYSTYPE *lval, void *vp)
{
CQL_parser cp = (CQL_parser) vp;
int yylex(YYSTYPE *lval, void *vp)
{
CQL_parser cp = (CQL_parser) vp;
@@
-205,7
+231,7
@@
int yylex(YYSTYPE *lval, void *vp)
lval->rel = 0;
lval->len = 0;
lval->size = 10;
lval->rel = 0;
lval->len = 0;
lval->size = 10;
- lval->buf = nmem_malloc(cp->nmem, lval->size);
+ lval->buf = (char *) nmem_malloc(cp->nmem, lval->size);
lval->buf[0] = '\0';
do
{
lval->buf[0] = '\0';
do
{
@@
-260,26
+286,25
@@
int yylex(YYSTYPE *lval, void *vp)
}
else
{
}
else
{
- putb(lval, cp, c);
- while ((c = cp->getbyte(cp->client_data)) != 0 &&
- !strchr(" \n()=<>/", c))
+ while (c != 0 && !strchr(" \n()=<>/", c))
{
if (c == '\\')
c = cp->getbyte(cp->client_data);
putb(lval, cp, c);
{
if (c == '\\')
c = cp->getbyte(cp->client_data);
putb(lval, cp, c);
+ c = cp->getbyte(cp->client_data);
}
#if YYDEBUG
printf ("got %s\n", lval->buf);
#endif
if (c != 0)
cp->ungetbyte(c, cp->client_data);
}
#if YYDEBUG
printf ("got %s\n", lval->buf);
#endif
if (c != 0)
cp->ungetbyte(c, cp->client_data);
- if (!strcmp(lval->buf, "and"))
+ if (!cql_strcmp(lval->buf, "and"))
return AND;
return AND;
- if (!strcmp(lval->buf, "or"))
+ if (!cql_strcmp(lval->buf, "or"))
return OR;
return OR;
- if (!strcmp(lval->buf, "not"))
+ if (!cql_strcmp(lval->buf, "not"))
return NOT;
return NOT;
- if (!strncmp(lval->buf, "prox", 4))
+ if (!cql_strcmp(lval->buf, "prox"))
return PROX;
}
return TERM;
return PROX;
}
return TERM;