X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fz3950%2Fzing%2Fcql%2FCQLLexer.java;h=d7adeac047d0fc5bdab39c84d118fbb887498122;hb=59200080b45184be8779f545d21ce87c4020ccf4;hp=2c867ea2e9d38f0cbd9611c8b5f1c7a437d68a66;hpb=d48bccaed9308a737cdfa55ba555891d0ad85b87;p=cql-java-moved-to-github.git diff --git a/src/main/java/org/z3950/zing/cql/CQLLexer.java b/src/main/java/org/z3950/zing/cql/CQLLexer.java index 2c867ea..d7adeac 100644 --- a/src/main/java/org/z3950/zing/cql/CQLLexer.java +++ b/src/main/java/org/z3950/zing/cql/CQLLexer.java @@ -5,8 +5,12 @@ */ 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 { @@ -136,7 +140,7 @@ 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: @@ -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);