org.z3950.zing.cql
Class CQLParser

java.lang.Object
  |
  +--org.z3950.zing.cql.CQLParser

public class CQLParser
extends java.lang.Object

Compiles CQL strings into parse trees of CQLNode subtypes.

Version:
$Id: CQLParser.java,v 1.14 2002/11/03 16:49:38 mike Exp $
See Also:
http://zing.z3950.org/cql/index.html

Constructor Summary
CQLParser()
           
 
Method Summary
static void main(java.lang.String[] args)
          Simple test-harness for the CQLParser class.
 CQLNode parse(java.lang.String cql)
          Compiles a CQL query.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CQLParser

public CQLParser()
Method Detail

parse

public CQLNode parse(java.lang.String cql)
              throws CQLParseException,
                     java.io.IOException
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; and toXCQL() returns an XML snippet representing the query.

Parameters:
cql - The query
Returns:
A CQLNode object which is the root of a parse tree representing the query.

main

public static void main(java.lang.String[] args)
Simple test-harness for the CQLParser class.

Reads a CQL query either from its command-line argument, if there is one, or standard input otherwise. So these two invocations are equivalent:

  CQLParser 'au=(Kerninghan or Ritchie) and ti=Unix'
  echo au=(Kerninghan or Ritchie) and ti=Unix | CQLParser
 
The test-harness parses the supplied query and renders is as XCQL, so that both of the invocations above produce the following output:
	<triple>
	  <boolean>
	    <value>and</value>
	  </boolean>
	  <triple>
	    <boolean>
	      <value>or</value>
	    </boolean>
	    <searchClause>
	      <index>au</index>
	      <relation>
	        <value>=</value>
	      </relation>
	      <term>Kerninghan</term>
	    </searchClause>
	    <searchClause>
	      <index>au</index>
	      <relation>
	        <value>=</value>
	      </relation>
	      <term>Ritchie</term>
	    </searchClause>
	  </triple>
	  <searchClause>
	    <index>ti</index>
	    <relation>
	      <value>=</value>
	    </relation>
	    <term>Unix</term>
	  </searchClause>
	</triple>
 

Parameters:
-c - Causes the output to be written in CQL rather than XCQL - that is, a query equivalent to that which was input, is output. In effect, the test harness acts as a query canonicaliser.
Returns:
The input query, either as XCQL [default] or CQL [if the -c option is supplied].