-// $Id: CQLParser.java,v 1.21 2002-11-17 23:29:02 mike Exp $
+// $Id: CQLParser.java,v 1.24 2007-06-06 12:22:01 mike Exp $
package org.z3950.zing.cql;
import java.io.IOException;
/**
* Compiles CQL strings into parse trees of CQLNode subtypes.
*
- * @version $Id: CQLParser.java,v 1.21 2002-11-17 23:29:02 mike Exp $
+ * @version $Id: CQLParser.java,v 1.24 2007-06-06 12:22:01 mike Exp $
* @see <A href="http://zing.z3950.org/cql/index.html"
* >http://zing.z3950.org/cql/index.html</A>
*/
* data structure) or, more often, simply rendered out in the
* desired form using one of the back-ends. <TT>toCQL()</TT>
* returns a decompiled CQL query equivalent to the one that was
- * compiled in the first place; and <TT>toXCQL()</TT> returns an
- * XML snippet representing the query.
+ * compiled in the first place; <TT>toXCQL()</TT> returns an
+ * XML snippet representing the query; and <TT>toPQF()</TT>
+ * returns the query rendered in Index Data's Prefix Query
+ * Format.
*
* @param cql The query
* @return A CQLNode object which is the root of a parse
break;
qualifier = word;
- relation = new CQLRelation(lexer.render(lexer.ttype, false));
+ relation = new CQLRelation(lexer.ttype == lexer.TT_WORD ?
+ lexer.sval :
+ lexer.render(lexer.ttype, false));
match(lexer.ttype);
while (lexer.ttype == '/') {
if (lexer.ttype != lexer.TT_RELEVANT &&
lexer.ttype != lexer.TT_FUZZY &&
lexer.ttype != lexer.TT_STEM &&
- lexer.ttype != lexer.TT_PHONETIC)
+ lexer.ttype != lexer.TT_PHONETIC &&
+ lexer.ttype != lexer.TT_WORD)
throw new CQLParseException("expected relation modifier, "
+ "got " + lexer.render());
+ if (lexer.ttype == lexer.TT_WORD &&
+ lexer.sval.indexOf('.') == -1)
+ throw new CQLParseException("unknown first-class " +
+ "relation modifier: " +
+ lexer.sval);
+
relation.addModifier(lexer.sval.toLowerCase());
match(lexer.ttype);
}
match(lexer.ttype);
}
- private boolean isBaseRelation() {
+ private boolean isBaseRelation()
+ throws CQLParseException {
debug("isBaseRelation: checking ttype=" + lexer.ttype +
" (" + lexer.render() + ")");
+
+ if (lexer.ttype == lexer.TT_WORD &&
+ lexer.sval.indexOf('.') == -1)
+ throw new CQLParseException("unknown first-class relation: " +
+ lexer.sval);
+
return (isProxRelation() ||
lexer.ttype == lexer.TT_ANY ||
lexer.ttype == lexer.TT_ALL ||
lexer.ttype == lexer.TT_EXACT ||
- lexer.ttype == lexer.TT_SCR);
+ lexer.ttype == lexer.TT_SCR ||
+ lexer.ttype == lexer.TT_WORD);
}
// Checks for a relation that may be used inside a prox operator
char mode = 'x'; // x=XCQL, c=CQL, p=PQF
String pfile = null;
- Vector argv = new Vector();
+ Vector<String> argv = new Vector<String>();
for (int i = 0; i < args.length; i++) {
argv.add(args[i]);
}