-// $Id: CQLParser.java,v 1.20 2002-11-14 22:04:16 mike Exp $
+// $Id: CQLParser.java,v 1.23 2003-09-04 21:56:46 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.20 2002-11-14 22:04:16 mike Exp $
+ * @version $Id: CQLParser.java,v 1.23 2003-09-04 21:56:46 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 == '/') {
match('/');
if (lexer.ttype != lexer.TT_RELEVANT &&
lexer.ttype != lexer.TT_FUZZY &&
- lexer.ttype != lexer.TT_STEM)
+ lexer.ttype != lexer.TT_STEM &&
+ 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);
}
name = identifier;
identifier = matchSymbol("prefix-identifer");
}
- CQLNode term = parseTerm(qualifier, relation);
+ CQLNode term = parseQuery(qualifier, relation);
return new CQLPrefixNode(name, identifier, term);
}
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
private boolean isProxRelation() {
debug("isProxRelation: checking ttype=" + lexer.ttype +
" (" + lexer.render() + ")");
// The following is a complete list of keywords. Because
// they're listed here, they can be used unquoted as
// qualifiers, terms, prefix names and prefix identifiers.
+ // ### Instead, we should ask the lexer whether what we
+ // have is a keyword, and let the knowledge reside there.
lexer.ttype == lexer.TT_AND ||
lexer.ttype == lexer.TT_OR ||
lexer.ttype == lexer.TT_NOT ||
lexer.ttype == lexer.TT_RELEVANT ||
lexer.ttype == lexer.TT_FUZZY ||
lexer.ttype == lexer.TT_STEM ||
- lexer.ttype == lexer.TT_SCR) {
+ lexer.ttype == lexer.TT_SCR ||
+ lexer.ttype == lexer.TT_PHONETIC) {
String symbol = (lexer.ttype == lexer.TT_NUMBER) ?
lexer.render() : lexer.sval;
match(lexer.ttype);