src/utils/raSqlQuery/raSqlQuery.c 1.8
1.8 2009/11/20 06:10:04 kent
Adding parenthesis in expressions.
Index: src/utils/raSqlQuery/raSqlQuery.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/utils/raSqlQuery/raSqlQuery.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -b -B -U 4 -r1.7 -r1.8
--- src/utils/raSqlQuery/raSqlQuery.c 20 Nov 2009 06:00:29 -0000 1.7
+++ src/utils/raSqlQuery/raSqlQuery.c 20 Nov 2009 06:10:04 -0000 1.8
@@ -225,8 +225,27 @@
for (child = p->children; child != NULL; child= child->next)
rqlParseDump(child, depth+1, f);
}
+static void expectingGot(struct tokenizer *tkz, char *expecting, char *got)
+/* Print out error message about unexpected input. */
+{
+errAbort("Expecting %s, got %s, line %d of %s", expecting, got, tkz->lf->lineIx,
+ tkz->lf->fileName);
+}
+
+static void skipOverRequired(struct tokenizer *tkz, char *expecting)
+/* Make sure that next token is tok, and skip over it. */
+{
+tokenizerMustHaveNext(tkz);
+if (!sameString(tkz->string, expecting))
+ expectingGot(tkz, expecting, tkz->string);
+}
+
+
+struct rqlParse *rqlParseExpression(struct tokenizer *tkz);
+/* Parse out a clause, usually a where clause. */
+
struct rqlParse *rqlParseAtom(struct tokenizer *tkz)
/* Return low level (symbol or literal) */
{
char *tok = tokenizerMustHaveNext(tkz);
@@ -264,30 +283,20 @@
else
tokenizerReuse(tkz);
}
}
+else if (c == '(')
+ {
+ p = rqlParseExpression(tkz);
+ skipOverRequired(tkz, ")");
+ }
else
{
errAbort("Unexpected %s line %d of %s", tok, tkz->lf->lineIx, tkz->lf->fileName);
}
return p;
}
-static void expectingGot(struct tokenizer *tkz, char *expecting, char *got)
-/* Print out error message about unexpected input. */
-{
-errAbort("Expecting %s, got %s, line %d of %s", expecting, got, tkz->lf->lineIx,
- tkz->lf->fileName);
-}
-
-static void skipOverRequired(struct tokenizer *tkz, char *expecting)
-/* Make sure that next token is tok, and skip over it. */
-{
-tokenizerMustHaveNext(tkz);
-if (!sameString(tkz->string, expecting))
- expectingGot(tkz, expecting, tkz->string);
-}
-
enum rqlType commonTypeForBop(enum rqlType left, enum rqlType right)
/* Return type that will work for a binary operation. */
{
if (left == right)
@@ -552,9 +561,9 @@
}
}
}
-struct rqlParse *rqlParseClause(struct tokenizer *tkz)
+struct rqlParse *rqlParseExpression(struct tokenizer *tkz)
/* Parse out a clause, usually a where clause. */
{
return rqlParseOrLoop(tkz);
}
@@ -944,9 +953,9 @@
if (where != NULL)
{
if (!sameString(where, "where"))
errAbort("Unknown clause '%s' line %d of %s", where, lf->lineIx, lf->fileName);
- rql->whereClause = rqlParseClause(tkz);
+ rql->whereClause = rqlParseExpression(tkz);
}
char *extra = tokenizerNext(tkz);
if (extra != NULL)