Mark syntax errors
[cql-java-moved-to-github.git] / src / main / java / org / z3950 / zing / cql / CQLLexer.java
index c285902..cb990cd 100644 (file)
@@ -5,6 +5,10 @@
  */
 package org.z3950.zing.cql;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
 /**
  * Implementation of the CQL lexical syntax analyzer
  * @author jakub
@@ -66,7 +70,7 @@ public class CQLLexer implements CQLTokenizer {
       }
     //quoted string
     } else if (strchr("\"", c)) { //no single-quotes
-      what = '"';
+      what = TT_STRING;
       //remember quote char
       char mark = c;
       qi++;
@@ -137,7 +141,7 @@ public class CQLLexer implements CQLTokenizer {
         return "EOF";
       case TT_WORD:
         return "word: '" + val + "'";
-      case '"':
+      case TT_STRING:
         return "string: \"" + val + "\"";
       case TT_LE:
         return "<=";
@@ -182,15 +186,20 @@ public class CQLLexer implements CQLTokenizer {
     if (args.length == 1) {
       cql = args[0];
     } else {
-      byte[] bytes = new byte[10000];
+      BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
       try {
-        // Read in the whole of standard input in one go
-        int nbytes = System.in.read(bytes);
-      } catch (java.io.IOException ex) {
+        // read a single line of input
+        cql = buff.readLine();
+        if (cql == null) {
+          System.err.println("Can't read query from stdin");
+          System.exit(2);
+          return;
+        }
+      } catch (IOException ex) {
         System.err.println("Can't read query: " + ex.getMessage());
         System.exit(2);
+        return;
       }
-      cql = new String(bytes);
     }
 
     CQLTokenizer lexer = new CQLLexer(cql, true);