Revert "Added Netbeans project."
[cql-java-moved-to-github.git] / src / org / z3950 / zing / cql / CQLLexer.java
index 8ae5085..5df3822 100644 (file)
@@ -1,4 +1,4 @@
-// $Id: CQLLexer.java,v 1.5 2002-11-14 22:04:16 mike Exp $
+// $Id: CQLLexer.java,v 1.14 2007-07-03 13:30:42 mike Exp $
 
 package org.z3950.zing.cql;
 import java.io.StreamTokenizer;
@@ -19,23 +19,12 @@ class CQLLexer extends StreamTokenizer {
     static int TT_LE        = 1000;    // The "<=" relation
     static int TT_GE        = 1001;    // The ">=" relation
     static int TT_NE        = 1002;    // The "<>" relation
-    static int TT_AND       = 1003;    // The "and" boolean
-    static int TT_OR        = 1004;    // The "or" boolean
-    static int TT_NOT       = 1005;    // The "not" boolean
-    static int TT_PROX      = 1006;    // The "prox" boolean
-    static int TT_ANY       = 1007;    // The "any" relation
-    static int TT_ALL       = 1008;    // The "all" relation
-    static int TT_EXACT     = 1009;    // The "exact" relation
-    static int TT_pWORD     = 1010;    // The "word" proximity unit
-    static int TT_SENTENCE  = 1011;    // The "sentence" proximity unit
-    static int TT_PARAGRAPH = 1012;    // The "paragraph" proximity unit
-    static int TT_ELEMENT   = 1013;    // The "element" proximity unit
-    static int TT_ORDERED   = 1014;    // The "ordered" proximity ordering
-    static int TT_UNORDERED = 1015;    // The "unordered" proximity ordering
-    static int TT_RELEVANT  = 1016;    // The "relevant" relation modifier
-    static int TT_FUZZY     = 1017;    // The "fuzzy" relation modifier
-    static int TT_STEM      = 1018;    // The "stem" relation modifier
-    static int TT_SCR       = 1019;    // The server choice relation
+    static int TT_EQEQ      = 1003;    // The "==" relation
+    static int TT_AND       = 1004;    // The "and" boolean
+    static int TT_OR        = 1005;    // The "or" boolean
+    static int TT_NOT       = 1006;    // The "not" boolean
+    static int TT_PROX      = 1007;    // The "prox" boolean
+    static int TT_SORTBY     = 1008;   // The "sortby" operator
 
     // Support for keywords.  It would be nice to compile this linear
     // list into a Hashtable, but it's hard to store ints as hash
@@ -56,19 +45,7 @@ class CQLLexer extends StreamTokenizer {
        new Keyword(TT_OR,  "or"),
        new Keyword(TT_NOT, "not"),
        new Keyword(TT_PROX, "prox"),
-       new Keyword(TT_ANY, "any"),
-       new Keyword(TT_ALL, "all"),
-       new Keyword(TT_EXACT, "exact"),
-       new Keyword(TT_pWORD, "word"),
-       new Keyword(TT_SENTENCE, "sentence"),
-       new Keyword(TT_PARAGRAPH, "paragraph"),
-       new Keyword(TT_ELEMENT, "element"),
-       new Keyword(TT_ORDERED, "ordered"),
-       new Keyword(TT_UNORDERED, "unordered"),
-       new Keyword(TT_RELEVANT, "relevant"),
-       new Keyword(TT_FUZZY, "fuzzy"),
-       new Keyword(TT_STEM, "stem"),
-       new Keyword(TT_SCR, "scr"),
+       new Keyword(TT_SORTBY, "sortby"),
     };
 
     // For halfDecentPushBack() and the code at the top of nextToken()
@@ -152,6 +129,18 @@ class CQLLexer extends StreamTokenizer {
                ttype = '>';
                debug("AFTER: ttype is now " + ttype + " - " + render());
            }
+       } else if (ttype == '=') {
+           debug("token starts with '=' ...");
+           underlyingNextToken();
+           if (ttype == '=') {
+               debug("token continues with '=' - it's '=='");
+               ttype = TT_EQEQ;
+           } else {
+               debug("next token is " + render() + " (pushed back)");
+               halfDecentPushBack();
+               ttype = '=';
+               debug("AFTER: ttype is now " + ttype + " - " + render());
+           }
        }
 
        debug("done nextToken(): ttype=" + ttype + ", " +
@@ -186,7 +175,11 @@ class CQLLexer extends StreamTokenizer {
        if (token == TT_EOF) {
            return "EOF";
        } else if (token == TT_NUMBER) {
-           return new Integer((int) nval).toString();
+           if ((double) nval == (int) nval) {
+               return new Integer((int) nval).toString();
+           } else {
+               return new Double((double) nval).toString();
+           }
        } else if (token == TT_WORD) {
            return "word: " + sval;
        } else if (token == '"') {
@@ -197,6 +190,8 @@ class CQLLexer extends StreamTokenizer {
            return ">=";
        } else if (token == TT_NE) {
            return "<>";
+       } else if (token == TT_EQEQ) {
+           return "==";
        }
 
        // Check whether its associated with one of the keywords