*/
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
*/
public class CQLLexer implements CQLTokenizer {
case TT_EOF:
return "EOF";
case TT_WORD:
- return "word: " + val;
+ return "word: '" + val + "'";
case '"':
return "string: \"" + val + "\"";
case TT_LE:
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);