- Change the XCQL output to include the nasty and redundant
[cql-java-moved-to-github.git] / src / org / z3950 / zing / cql / CQLParser.java
index eadedef..85ee63b 100644 (file)
@@ -1,4 +1,4 @@
-// $Id: CQLParser.java,v 1.20 2002-11-14 22:04:16 mike Exp $
+// $Id: CQLParser.java,v 1.22 2002-11-20 01:15:15 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.20 2002-11-14 22:04:16 mike Exp $
+ * @version    $Id: CQLParser.java,v 1.22 2002-11-20 01:15:15 mike Exp $
  * @see                <A href="http://zing.z3950.org/cql/index.html"
  *                     >http://zing.z3950.org/cql/index.html</A>
  */
@@ -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.  <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
@@ -119,7 +121,8 @@ public class CQLParser {
                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)
                    throw new CQLParseException("expected relation modifier, "
                                                + "got " + lexer.render());
                relation.addModifier(lexer.sval.toLowerCase());
@@ -146,7 +149,7 @@ public class CQLParser {
            name = identifier;
            identifier = matchSymbol("prefix-identifer");
        }
-       CQLNode term = parseTerm(qualifier, relation);
+       CQLNode term = parseQuery(qualifier, relation);
        return new CQLPrefixNode(name, identifier, term);
     }
 
@@ -223,6 +226,7 @@ public class CQLParser {
                lexer.ttype == lexer.TT_SCR);
     }
 
+    // Checks for a relation that may be used inside a prox operator
     private boolean isProxRelation() {
        debug("isProxRelation: checking ttype=" + lexer.ttype +
              " (" + lexer.render() + ")");
@@ -257,6 +261,8 @@ public class CQLParser {
            // 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 ||
@@ -273,7 +279,8 @@ public class CQLParser {
            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);