Allow '.' to begin a word character
[cql-java-moved-to-github.git] / src / main / java / org / z3950 / zing / cql / CQLLexer.java
index 5df3822..5376f1d 100644 (file)
@@ -1,9 +1,9 @@
-// $Id: CQLLexer.java,v 1.14 2007-07-03 13:30:42 mike Exp $
 
 package org.z3950.zing.cql;
+import java.io.InputStream;
+import java.io.Reader;
 import java.io.StreamTokenizer;
 import java.io.StringReader;
-import java.util.Hashtable;
 
 
 // This is a semi-trivial subclass for java.io.StreamTokenizer that:
@@ -16,15 +16,15 @@ import java.util.Hashtable;
 //
 class CQLLexer extends StreamTokenizer {
     // New publicly visible token-types
-    static int TT_LE        = 1000;    // The "<=" relation
-    static int TT_GE        = 1001;    // The ">=" relation
-    static int TT_NE        = 1002;    // The "<>" 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
+    public final static int TT_LE        = 1000;       // The "<=" relation
+    public final static int TT_GE        = 1001;       // The ">=" relation
+    public final static int TT_NE        = 1002;       // The "<>" relation
+    public final static int TT_EQEQ      = 1003;       // The "==" relation
+    public final static int TT_AND       = 1004;       // The "and" boolean
+    public final static int TT_OR        = 1005;       // The "or" boolean
+    public final static int TT_NOT       = 1006;       // The "not" boolean
+    public final static int TT_PROX      = 1007;       // The "prox" boolean
+    public final 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
@@ -58,7 +58,11 @@ class CQLLexer extends StreamTokenizer {
     private static boolean DEBUG;
 
     CQLLexer(String cql, boolean lexdebug) {
-       super(new StringReader(cql));
+        this(new StringReader(cql), lexdebug);
+    }
+    
+    CQLLexer(Reader cql, boolean lexdebug) {
+       super(cql);
        wordChars('!', '?');    // ASCII-dependency!
        wordChars('[', '`');    // ASCII-dependency!
        quoteChar('"');
@@ -68,8 +72,14 @@ class CQLLexer extends StreamTokenizer {
        ordinaryChar('/');
        ordinaryChar('(');
        ordinaryChar(')');
+        ordinaryChar('.');
+        wordChars('.', '.');
        wordChars('\'', '\''); // prevent this from introducing strings
-       parseNumbers();
+       //parseNumbers();
+       ordinaryChar('-');
+       wordChars('-', '-');
+       ordinaryChars('0', '9');
+       wordChars('0', '9');
        DEBUG = lexdebug;
     }
 
@@ -90,6 +100,7 @@ class CQLLexer extends StreamTokenizer {
        saved_sval = sval;
     }
 
+    @Override
     public int nextToken() throws java.io.IOException {
        if (saved_ttype != TT_UNDEFINED) {
            ttype = saved_ttype;