X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Forg%2Fz3950%2Fzing%2Fcql%2FCQLParser.java;h=da2af02dc0fe657c26a07a99ee9cf2ac28619eb3;hb=f3c88fe15ee06a671407a0368e449db991526802;hp=6726999398d4f7b09c4b235aa16c90f50539d7f8;hpb=394625a21876d096000c4940049305c27de90321;p=cql-java-moved-to-github.git diff --git a/src/org/z3950/zing/cql/CQLParser.java b/src/org/z3950/zing/cql/CQLParser.java index 6726999..da2af02 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.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; @@ -12,7 +12,7 @@ import java.io.FileNotFoundException; /** * 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 http://zing.z3950.org/cql/index.html */ @@ -34,8 +34,10 @@ public class CQLParser { * data structure) or, more often, simply rendered out in the * desired form using one of the back-ends. toCQL() * returns a decompiled CQL query equivalent to the one that was - * compiled in the first place; and toXCQL() returns an - * XML snippet representing the query. + * compiled in the first place; toXCQL() returns an + * XML snippet representing the query; and toPQF() + * 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 @@ -112,7 +114,9 @@ public class CQLParser { 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 == '/') { @@ -120,9 +124,16 @@ public class CQLParser { 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); } @@ -214,14 +225,22 @@ public class CQLParser { 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 @@ -349,7 +368,7 @@ public class CQLParser { char mode = 'x'; // x=XCQL, c=CQL, p=PQF String pfile = null; - Vector argv = new Vector(); + Vector argv = new Vector(); for (int i = 0; i < args.length; i++) { argv.add(args[i]); }