Class StatementFinder
Semicolons inside comments, strings, and delimited identifiers are not considered to be statement terminators but to be part of those tokens.
Comments currently recognized include the SQL comment, which begins with "--" and ends at the next EOL, and nested bracketed comments.
Strings and delimited identifiers are permitted to contain newlines; the actual IJ or JSQL parsers will report errors when those cases occur.
There are no escaped characters, i.e. "\n" is considered to be two characters, '\' and 'n'.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final char
private boolean
private boolean
private boolean
private static final char
private static final int
private static final int
private static final char
private static final int
private static final int
private static final int
private static final char
private static final char
private char
private boolean
private boolean
private LocalizedOutput
private static final char
private static final char
private static final char
private static final char
private Reader
private static final char
private int
private StringBuffer
private static final char
-
Constructor Summary
ConstructorsConstructorDescriptionStatementFinder
(LocalizedInput s, LocalizedOutput promptDest) The constructor does not assume the stream is data input or buffered, so it will wrap it appropriately. -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
atEOF()
void
close()
get the next statement in the input stream.private char
peekChar()
return the next character in the source stream, without advancing.private boolean
peekEOF()
private void
Advance the source stream to the end of a comment if it is on one, assuming the first character of a potential bracketed comment has been found.private char
readChar()
return the next character in the source stream and append it to the statement buffer.private void
readSingleLineComment
(char commentChar) Advance the source stream to the end of a comment if it is on one, assuming the first character of a potential single line comment has been found.private void
readString
(char stringDelimiter) Advance the stream to the end of the string.void
Reinit is used to redirect the finder to another stream.private boolean
whiteSpace
(char c) Determine if the given character is considered whitespace
-
Field Details
-
source
-
statement
-
state
private int state -
atEOF
private boolean atEOF -
peekEOF
private boolean peekEOF -
peekChar
private char peekChar -
peeked
private boolean peeked -
promptwriter
-
doPrompt
private boolean doPrompt -
continuedStatement
private boolean continuedStatement -
IN_STATEMENT
private static final int IN_STATEMENT- See Also:
-
IN_STRING
private static final int IN_STRING- See Also:
-
IN_SQLCOMMENT
private static final int IN_SQLCOMMENT- See Also:
-
END_OF_STATEMENT
private static final int END_OF_STATEMENT- See Also:
-
END_OF_INPUT
private static final int END_OF_INPUT- See Also:
-
MINUS
private static final char MINUS- See Also:
-
SINGLEQUOTE
private static final char SINGLEQUOTE- See Also:
-
DOUBLEQUOTE
private static final char DOUBLEQUOTE- See Also:
-
SEMICOLON
private static final char SEMICOLON- See Also:
-
NEWLINE
private static final char NEWLINE- See Also:
-
RETURN
private static final char RETURN- See Also:
-
SPACE
private static final char SPACE- See Also:
-
TAB
private static final char TAB- See Also:
-
FORMFEED
private static final char FORMFEED- See Also:
-
SLASH
private static final char SLASH- See Also:
-
ASTERISK
private static final char ASTERISK- See Also:
-
-
Constructor Details
-
StatementFinder
The constructor does not assume the stream is data input or buffered, so it will wrap it appropriately. If the StatementFinder's input stream is connected to System.in, a LocalizedOutput stream may be given to print line continuation prompts when StatementFinder reads a newline.- Parameters:
s
- the input stream for reading statements from.promptDest
- LocalizedOutput stream to write line continuation prompts ("> ") to. If null, no such prompts will be written.
-
-
Method Details
-
ReInit
Reinit is used to redirect the finder to another stream. The previous stream should not have been in a PEEK state. If an output stream was given when constructing this StatementFinder and the input is standard input, continuation prompting will be enabled.- Parameters:
s
- the input stream for reading statements from.
-
close
- Throws:
IOException
-
nextStatement
get the next statement in the input stream. Returns it, dropping its closing semicolon if it has one. If there is no next statement, return a null.- Returns:
- the next statement in the input stream.
-
whiteSpace
private boolean whiteSpace(char c) Determine if the given character is considered whitespace- Parameters:
c
- the character to consider- Returns:
- true if the character is whitespace
-
readBracketedComment
private void readBracketedComment()Advance the source stream to the end of a comment if it is on one, assuming the first character of a potential bracketed comment has been found. If it is not a comment, do not advance the stream. -
readSingleLineComment
private void readSingleLineComment(char commentChar) Advance the source stream to the end of a comment if it is on one, assuming the first character of a potential single line comment has been found. If it is not a comment, do not advance the stream.The form of a single line comment is, in regexp, XX.*$, where XX is two instances of commentChar.
- Parameters:
commentChar
- the character whose duplication signifies the start of the comment.
-
readString
private void readString(char stringDelimiter) Advance the stream to the end of the string. Assumes the opening delimiter of the string has been read. This handles the SQL ability to put the delimiter within the string by doubling it, by reading those as two strings sitting next to one another. I.e, 'Mary''s lamb' is read by this class as two strings, 'Mary' and 's lamb'.The delimiter of the string is expected to be repeated at its other end. If the other flavor of delimiter occurs within the string, it is just a normal character within it.
All characters except the delimiter are permitted within the string. If EOF is hit before the closing delimiter is found, the end of the string is assumed. Parsers using this parser will detect the error in that case and return appropriate messages.
- Parameters:
stringDelimiter
- the starting and ending character for the string being read.
-
atEOF
private boolean atEOF() -
peekEOF
private boolean peekEOF() -
readChar
private char readChar()return the next character in the source stream and append it to the statement buffer.- Returns:
- the next character in the source stream.
-
peekChar
private char peekChar()return the next character in the source stream, without advancing.- Returns:
- the next character in the source stream.
-