org.basex.query
Class QueryParser

java.lang.Object
  extended by org.basex.query.QueryParser
Direct Known Subclasses:
CommandParser, XPParser, XQParser

public class QueryParser
extends java.lang.Object

Simple query parser; can be overwritten to support more complex parsings.

Author:
Workgroup DBIS, University of Konstanz 2005-08, ISC License, Christian Gruen

Field Summary
 IO file
          Optional reference to query input.
 int ql
          Query length.
 int qm
          Marked query position.
 int qp
          Current query position.
 java.lang.String qu
          Input query.
 
Constructor Summary
QueryParser()
           
 
Method Summary
 char consume()
          Returns next character.
 boolean consume(int ch)
          Peeks forward and consumes the character if it equals the specified one.
 boolean consume(java.lang.String str)
          Peeks forward and consumes the string if it equals the specified one.
 void consumeWS()
          Consumes all whitespace characters from the beginning of the remaining query.
 char curr()
          Returns the current character.
 boolean curr(int ch)
          Checks if the current character equals the specified one.
 java.lang.String ent(TokenBuilder tb)
          Parse and convert entities.
 byte[] found()
          Returns a "found" string, containing the current character.
 void init(java.lang.String q)
          Constructor.
 java.lang.String invalidEnt(int p)
          Returns the current entity snippet.
 void mark()
          Remember the current position.
 boolean more()
          Checks if more characters are found.
 char next()
          Returns the next character.
 boolean quote(char ch)
          Checks if the specified character is a quote.
 java.lang.String rest()
          Returns the remaining, unscanned query substring.
 int valid()
          Checks if the input is valid.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

file

public IO file
Optional reference to query input.


qu

public java.lang.String qu
Input query.


qp

public int qp
Current query position.


qm

public int qm
Marked query position.


ql

public int ql
Query length.

Constructor Detail

QueryParser

public QueryParser()
Method Detail

init

public void init(java.lang.String q)
Constructor.

Parameters:
q - input query

valid

public int valid()
Checks if the input is valid.

Returns:
0 if everything is valid

more

public boolean more()
Checks if more characters are found.

Returns:
current character

curr

public char curr()
Returns the current character.

Returns:
current character

curr

public boolean curr(int ch)
Checks if the current character equals the specified one.

Parameters:
ch - character to be checked
Returns:
result of check

mark

public void mark()
Remember the current position.


next

public char next()
Returns the next character.

Returns:
result of check

consume

public char consume()
Returns next character.

Returns:
next character

consume

public boolean consume(int ch)
Peeks forward and consumes the character if it equals the specified one.

Parameters:
ch - character to consume
Returns:
true if character was found

quote

public boolean quote(char ch)
Checks if the specified character is a quote.

Parameters:
ch - character to be checked
Returns:
result

consumeWS

public void consumeWS()
Consumes all whitespace characters from the beginning of the remaining query.


consume

public boolean consume(java.lang.String str)
Peeks forward and consumes the string if it equals the specified one.

Parameters:
str - string to consume
Returns:
true if string was found

found

public byte[] found()
Returns a "found" string, containing the current character.

Returns:
completion

ent

public java.lang.String ent(TokenBuilder tb)
Parse and convert entities.

Parameters:
tb - token builder
Returns:
error string or null

invalidEnt

public java.lang.String invalidEnt(int p)
Returns the current entity snippet.

Parameters:
p - start position
Returns:
entity

rest

public java.lang.String rest()
Returns the remaining, unscanned query substring.

Returns:
query substring