org.datanucleus.query.compiler
Class Lexer

java.lang.Object
  extended by org.datanucleus.query.compiler.Lexer

public class Lexer
extends java.lang.Object

Lexer for a Query. Allows a class to work its way through the parsed string, obtaining relevant components with each call, or peeking ahead before deciding what component to parse next. Would work with JDOQL or JPQL. The only difference is the input of parameter prefixes. With JDOQL all parameters are prefixed ":", whereas in JPQL you can have numbered parameters "?" and named parameters ":".


Field Summary
protected  java.text.CharacterIterator ci
           
protected static Localiser LOCALISER
          Localiser for messages.
 
Constructor Summary
Lexer(java.lang.String input, java.lang.String paramPrefixes, boolean parseEscapedChars)
          Constructor
 
Method Summary
 int getIndex()
          Accessor for the current index in the input string.
 java.lang.String getInput()
          Accessor for the input string.
 boolean nextIsDot()
          Utility to return if the next character is a dot.
 boolean nextIsSingleQuote()
          Utility to return if the next non-whitespace character is a single quote.
 java.lang.Boolean parseBooleanLiteral()
          Parse a boolean from the current position.
 java.lang.Boolean parseBooleanLiteralIgnoreCase()
          Parse a boolean from the current position (case insensitive).
 java.lang.String parseCast()
          Parse a cast in the query from the current position, returning the name of the class that is being cast to.
 boolean parseChar(char c)
          Check if char c is found
 boolean parseChar(char c, char unlessFollowedBy)
          Check if char c is found
 java.lang.Character parseCharacterLiteral()
          Parse a Character literal
 boolean parseEOS()
          Check if END OF TEXT is reached.
 java.math.BigDecimal parseFloatingPointLiteral()
          Parse a floating point number from the current position.
 java.lang.String parseIdentifier()
          Parse a java identifier from the current position.
 java.math.BigInteger parseIntegerLiteral()
          Parse an integer number from the current position.
 java.lang.String parseMethod()
          Checks if a java Method is found
 java.lang.String parseName()
          Parses the text string (up to the next space) and returns it.
 boolean parseNullLiteral()
          Checks if null literal is parsed
 boolean parseNullLiteralIgnoreCase()
          Checks if null literal is parsed (case insensitive).
 boolean parseString(java.lang.String s)
          Check if String s is found
 boolean parseStringIgnoreCase(java.lang.String s)
          Check if String s is found ignoring the case
 java.lang.String parseStringLiteral()
          Parse a String literal
 boolean peekStringIgnoreCase(java.lang.String s)
          Check if String "s" is found ignoring the case, and not moving the cursor position.
 java.lang.String remaining()
          Method to return the remaining part of the string not yet processed.
 int skipWS()
          Skip over any whitespace from the current position.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOCALISER

protected static final Localiser LOCALISER
Localiser for messages.


ci

protected final java.text.CharacterIterator ci
Constructor Detail

Lexer

public Lexer(java.lang.String input,
             java.lang.String paramPrefixes,
             boolean parseEscapedChars)
Constructor

Parameters:
input - The input string
paramPrefixes - String containing all possible prefixes for parameters
parseEscapedChars - Whether to prase escaped characters
Method Detail

getInput

public java.lang.String getInput()
Accessor for the input string.

Returns:
The input string.

getIndex

public int getIndex()
Accessor for the current index in the input string.

Returns:
The current index.

skipWS

public int skipWS()
Skip over any whitespace from the current position.

Returns:
The new position

parseEOS

public boolean parseEOS()
Check if END OF TEXT is reached.

Returns:
true if END OF TEXT is reached

parseChar

public boolean parseChar(char c)
Check if char c is found

Parameters:
c - the Character to find
Returns:
true if c is found

parseChar

public boolean parseChar(char c,
                         char unlessFollowedBy)
Check if char c is found

Parameters:
c - the Character to find
unlessFollowedBy - the character to validate it does not follow c
Returns:
true if c is found and not followed by unlessFollowedBy

parseString

public boolean parseString(java.lang.String s)
Check if String s is found

Parameters:
s - the String to find
Returns:
true if s is found

parseStringIgnoreCase

public boolean parseStringIgnoreCase(java.lang.String s)
Check if String s is found ignoring the case

Parameters:
s - the String to find
Returns:
true if s is found

peekStringIgnoreCase

public boolean peekStringIgnoreCase(java.lang.String s)
Check if String "s" is found ignoring the case, and not moving the cursor position.

Parameters:
s - the String to find
Returns:
true if string is found

parseIdentifier

public java.lang.String parseIdentifier()
Parse a java identifier from the current position.

Returns:
The identifier

parseMethod

public java.lang.String parseMethod()
Checks if a java Method is found

Returns:
true if a Method is found

parseName

public java.lang.String parseName()
Parses the text string (up to the next space) and returns it. The name includes '.' characters. This can be used, for example, when parsing a class name wanting to read in the full name (including package) so that it can then be checked for existence in the CLASSPATH.

Returns:
The name

parseCast

public java.lang.String parseCast()
Parse a cast in the query from the current position, returning the name of the class that is being cast to. Returns null if the current position doesn't have a cast. Does no checking as to whether the name is a valid class name, just whether there is "({name})" from the current position.

Returns:
The name of the class to cast to

parseIntegerLiteral

public java.math.BigInteger parseIntegerLiteral()
Parse an integer number from the current position.

Returns:
The integer number parsed (null if not valid).

parseFloatingPointLiteral

public java.math.BigDecimal parseFloatingPointLiteral()
Parse a floating point number from the current position.

Returns:
The floating point number parsed (null if not valid).

parseBooleanLiteral

public java.lang.Boolean parseBooleanLiteral()
Parse a boolean from the current position.

Returns:
The boolean parsed (null if not valid).

parseBooleanLiteralIgnoreCase

public java.lang.Boolean parseBooleanLiteralIgnoreCase()
Parse a boolean from the current position (case insensitive).

Returns:
The boolean parsed (null if not valid).

nextIsSingleQuote

public boolean nextIsSingleQuote()
Utility to return if the next non-whitespace character is a single quote.

Returns:
Whether it is a single quote at the current point (ignoring whitespace)

nextIsDot

public boolean nextIsDot()
Utility to return if the next character is a dot.

Returns:
Whether it is a dot at the current point

parseCharacterLiteral

public java.lang.Character parseCharacterLiteral()
Parse a Character literal

Returns:
the Character parsed. null if single quotes is found
Throws:
NucleusUserException - if an invalid character is found or the CharacterIterator is finished

parseStringLiteral

public java.lang.String parseStringLiteral()
Parse a String literal

Returns:
the String parsed. null if single quotes or double quotes is found
Throws:
NucleusUserException - if an invalid character is found or the CharacterIterator is finished

parseNullLiteral

public boolean parseNullLiteral()
Checks if null literal is parsed

Returns:
true if null literal is found

parseNullLiteralIgnoreCase

public boolean parseNullLiteralIgnoreCase()
Checks if null literal is parsed (case insensitive).

Returns:
true if null literal is found

remaining

public java.lang.String remaining()
Method to return the remaining part of the string not yet processed. Doesn't move the current position.

Returns:
The remaining part of the string

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2010. All Rights Reserved.