From: mike Date: Thu, 28 Jun 2007 00:24:48 +0000 (+0000) Subject: Parse complex relation modifiers. X-Git-Tag: v1.5~101 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=eeb414a2fc68d4a0d10a5a052fed97e936de228d;p=cql-java-moved-to-github.git Parse complex relation modifiers. (Getting the lexeme out of the lexer involves sticking my fingers down its throat, which is now done in two places. Should be refactored into the lexer itself.) --- diff --git a/src/org/z3950/zing/cql/CQLParser.java b/src/org/z3950/zing/cql/CQLParser.java index f03c6aa..94e8b87 100644 --- a/src/org/z3950/zing/cql/CQLParser.java +++ b/src/org/z3950/zing/cql/CQLParser.java @@ -1,4 +1,4 @@ -// $Id: CQLParser.java,v 1.29 2007-06-28 00:00:53 mike Exp $ +// $Id: CQLParser.java,v 1.30 2007-06-28 00:24:48 mike Exp $ package org.z3950.zing.cql; import java.io.IOException; @@ -12,7 +12,7 @@ import java.io.FileNotFoundException; /** * Compiles CQL strings into parse trees of CQLNode subtypes. * - * @version $Id: CQLParser.java,v 1.29 2007-06-28 00:00:53 mike Exp $ + * @version $Id: CQLParser.java,v 1.30 2007-06-28 00:24:48 mike Exp $ * @see http://zing.z3950.org/cql/index.html */ @@ -124,8 +124,25 @@ public class CQLParser { if (lexer.ttype != lexer.TT_WORD) throw new CQLParseException("expected relation modifier, " + "got " + lexer.render()); - relation.addModifier(lexer.sval.toLowerCase()); + String type = lexer.sval.toLowerCase(); match(lexer.ttype); + if (!isRelation()) { + // It's a simple modifier consisting of type only + relation.addModifier(type); + } else { + // It's a complex modifier of the form type=value + String comparision = lexer.render(lexer.ttype, false); + match(lexer.ttype); + + // Yuck + String value = lexer.ttype == lexer.TT_WORD ? lexer.sval : + (double) lexer.nval == (int) lexer.nval ? + new Integer((int) lexer.nval).toString() : + new Double((double) lexer.nval).toString(); + + matchSymbol("relation-modifier value"); + relation.addModifier(type, comparision, value); + } } debug("index='" + index + ", " +