From: Jakub Skoczen Date: Mon, 17 Mar 2014 13:08:14 +0000 (+0100) Subject: Allow a list of quoted terms X-Git-Tag: v1.12~5 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=b76b718c1994b348b66a994dcf15c819c4e94617;p=cql-java-moved-to-github.git Allow a list of quoted terms Also mixed with a list of words. To align with C CQL parser. --- diff --git a/src/main/java/org/z3950/zing/cql/CQLLexer.java b/src/main/java/org/z3950/zing/cql/CQLLexer.java index d7adeac..669dde7 100644 --- a/src/main/java/org/z3950/zing/cql/CQLLexer.java +++ b/src/main/java/org/z3950/zing/cql/CQLLexer.java @@ -70,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++; diff --git a/src/main/java/org/z3950/zing/cql/CQLParser.java b/src/main/java/org/z3950/zing/cql/CQLParser.java index a4f2fc8..b435aa3 100644 --- a/src/main/java/org/z3950/zing/cql/CQLParser.java +++ b/src/main/java/org/z3950/zing/cql/CQLParser.java @@ -235,13 +235,13 @@ public class CQLParser { debug("non-parenthesised term"); word = matchSymbol("index or term"); - while (lexer.what() == CQLTokenizer.TT_WORD && !isRelation()) { + while (isWordOrString() && !isRelation()) { word = word + " " + lexer.value(); - match(CQLTokenizer.TT_WORD); + match(lexer.what()); } if (!isRelation()) - break; + break; index = word; String relstr = (lexer.what() == CQLTokenizer.TT_WORD ? @@ -278,6 +278,11 @@ public class CQLParser { return new CQLPrefixNode(name, identifier, node); } + + private boolean isWordOrString() { + return CQLTokenizer.TT_WORD == lexer.what() + || CQLTokenizer.TT_STRING == lexer.what(); + } private boolean isRelation() { debug("isRelation: checking what()=" + lexer.what() + @@ -326,12 +331,10 @@ public class CQLParser { debug("in matchSymbol()"); if (lexer.what() == CQLTokenizer.TT_WORD || - lexer.what() == '"' || + lexer.what() == CQLTokenizer.TT_STRING || // The following is a complete list of keywords. Because // they're listed here, they can be used unquoted as // indexes, terms, prefix names and prefix identifiers. - // ### Instead, we should ask the lexer whether what we - // have is a keyword, and let the knowledge reside there. (allowKeywordTerms && lexer.what() == CQLTokenizer.TT_AND || lexer.what() == CQLTokenizer.TT_OR || diff --git a/src/main/java/org/z3950/zing/cql/CQLTokenizer.java b/src/main/java/org/z3950/zing/cql/CQLTokenizer.java index 0425bb4..2d8b6b1 100644 --- a/src/main/java/org/z3950/zing/cql/CQLTokenizer.java +++ b/src/main/java/org/z3950/zing/cql/CQLTokenizer.java @@ -15,6 +15,7 @@ public interface CQLTokenizer { public static final int TT_WORD = -3; public static final int TT_NOTHING = -4; + public final static int TT_STRING = 999; // quoted string 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