Class Lexer
java.lang.Object
org.datanucleus.store.query.compiler.Lexer
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 being the input of parameter prefixes.
With JDOQL all parameters are prefixed ":", whereas in JPQL you can have numbered parameters "?" and named parameters ":".
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final CharacterIterator
private final String
private final String
Prefixes for any parameter, in a string.private final boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
getIndex()
Accessor for the current index in the input string.getInput()
Accessor for the input string.private static final boolean
isDecDigit
(char c) Utility to return if a character is a decimal digit.private static final boolean
isHexDigit
(char c) Utility to return if a character is a hexadecimal digit.private static final boolean
isOctDigit
(char c) Utility to return if a character is a octal digit.boolean
Utility to return if the next character is a dot.boolean
Utility to return if the next non-whitespace character is a single quote.Parse a boolean from the current position.Parse a boolean from the current position (case insensitive).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 charc
is foundboolean
parseChar
(char c, char unlessFollowedBy) Check if charc
is foundParse a Character literalboolean
parseEOS()
Check if END OF TEXT is reached.private char
Parse an escaped character.Parse a floating point number from the current position.Parse a java identifier from the current position.Parse an integer number from the current position.Checks if a java Method is foundParses the text string (up to the next space) and returns it.boolean
Checks if null literal is parsedboolean
Checks if null literal is parsed (case insensitive).boolean
Check if Strings
is foundboolean
Check if Strings
is found ignoring the caseParse a String literalboolean
peekString
(String s) Check if String "s" is found and not moving the cursor position.boolean
Check if String "s" is found ignoring the case, and not moving the cursor position.Method to return the remaining part of the string not yet processed.void
setIndex
(int idx) int
skipWS()
Skip over any whitespace from the current position.toString()
-
Field Details
-
parameterPrefixes
Prefixes for any parameter, in a string. JDOQL will be ":". JPQL will be ":?". -
input
-
ci
-
parseEscapedChars
private final boolean parseEscapedChars
-
-
Constructor Details
-
Lexer
Constructor- Parameters:
input
- The input stringparamPrefixes
- String containing all possible prefixes for parametersparseEscapedChars
- Whether to prase escaped characters
-
-
Method Details
-
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.
-
setIndex
public void setIndex(int idx) -
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 charc
is found- Parameters:
c
- the Character to find- Returns:
- true if
c
is found
-
parseChar
public boolean parseChar(char c, char unlessFollowedBy) Check if charc
is found- Parameters:
c
- the Character to findunlessFollowedBy
- the character to validate it does not followc
- Returns:
- true if
c
is found and not followed byunlessFollowedBy
-
parseString
Check if Strings
is found- Parameters:
s
- the String to find- Returns:
- true if
s
is found
-
parseStringIgnoreCase
Check if Strings
is found ignoring the case- Parameters:
s
- the String to find- Returns:
- true if
s
is found
-
peekString
Check if String "s" is found and not moving the cursor position.- Parameters:
s
- the String to find- Returns:
- true if string is found
-
peekStringIgnoreCase
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
Parse a java identifier from the current position.- Returns:
- The identifier
-
parseMethod
Checks if a java Method is found- Returns:
- true if a Method is found
-
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
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
-
isDecDigit
private static final boolean isDecDigit(char c) Utility to return if a character is a decimal digit.- Parameters:
c
- The character- Returns:
- Whether it is a decimal digit
-
isOctDigit
private static final boolean isOctDigit(char c) Utility to return if a character is a octal digit.- Parameters:
c
- The character- Returns:
- Whether it is a octal digit
-
isHexDigit
private static final boolean isHexDigit(char c) Utility to return if a character is a hexadecimal digit.- Parameters:
c
- The character- Returns:
- Whether it is a hexadecimal digit
-
parseIntegerLiteral
Parse an integer number from the current position.- Returns:
- The integer number parsed (null if not valid).
-
parseFloatingPointLiteral
Parse a floating point number from the current position.- Returns:
- The floating point number parsed (null if not valid).
-
parseBooleanLiteral
Parse a boolean from the current position.- Returns:
- The boolean parsed (null if not valid).
-
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
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
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
-
parseEscapedCharacter
private char parseEscapedCharacter()Parse an escaped character.- Returns:
- the escaped char
- Throws:
NucleusUserException
- if a escaped character is not valid
-
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
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
-