X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fz3950%2Fzing%2Fcql%2FCQLParser.java;h=795b2f1072f762ada54eefc95e19f2cf5208c6e9;hb=b44d16a11b3f7ab297743bfff3d14a167a647503;hp=be365de2581cf5e4c5fa215e6e2606a8072ec604;hpb=64ca1306b4e0d55a8b15b8da982bc1d37bc8b63c;p=cql-java-moved-to-github.git diff --git a/src/main/java/org/z3950/zing/cql/CQLParser.java b/src/main/java/org/z3950/zing/cql/CQLParser.java index be365de..795b2f1 100644 --- a/src/main/java/org/z3950/zing/cql/CQLParser.java +++ b/src/main/java/org/z3950/zing/cql/CQLParser.java @@ -6,6 +6,8 @@ import java.util.Properties; import java.io.InputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.Reader; +import java.io.StringReader; import java.util.ArrayList; import java.util.List; @@ -55,6 +57,26 @@ public class CQLParser { if (DEBUG) System.err.println("PARSEDEBUG: " + str); } + + /** + * Compiles a CQL query. + *

+ * The resulting parse tree may be further processed by hand (see + * the individual node-types' documentation for details on the + * data structure) or, more often, simply rendered out in the + * desired form using one of the back-ends. toCQL() + * returns a decompiled CQL query equivalent to the one that was + * compiled in the first place; toXCQL() returns an + * XML snippet representing the query; and toPQF() + * returns the query rendered in Index Data's Prefix Query + * Format. + * + * @param cql The query + * @return A CQLNode object which is the root of a parse + * tree representing the query. */ + public CQLNode parse(String cql) throws CQLParseException, IOException { + return parse(new StringReader(cql)); + } /** * Compiles a CQL query. @@ -72,7 +94,7 @@ public class CQLParser { * @param cql The query * @return A CQLNode object which is the root of a parse * tree representing the query. */ - public CQLNode parse(String cql) + public CQLNode parse(Reader cql) throws CQLParseException, IOException { lexer = new CQLLexer(cql, LEXDEBUG); @@ -246,7 +268,7 @@ public class CQLParser { lexer.sval.equals("all") || lexer.sval.equals("within") || lexer.sval.equals("encloses") || - lexer.sval.equals("exact") || + (lexer.sval.equals("exact") && compat != V1POINT2) || (lexer.sval.equals("scr") && compat != V1POINT2) || (lexer.sval.equals("adj") && compat == V1POINT2))) return true;