public class StatementFinder
extends java.lang.Object
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'.
Modifier and Type | Field | Description |
---|---|---|
private static char |
ASTERISK |
|
private boolean |
atEOF |
|
private boolean |
continuedStatement |
|
private boolean |
doPrompt |
|
private static char |
DOUBLEQUOTE |
|
private static int |
END_OF_INPUT |
|
private static int |
END_OF_STATEMENT |
|
private static char |
FORMFEED |
|
private static int |
IN_SQLCOMMENT |
|
private static int |
IN_STATEMENT |
|
private static int |
IN_STRING |
|
private static char |
MINUS |
|
private static char |
NEWLINE |
|
private char |
peekChar |
|
private boolean |
peeked |
|
private boolean |
peekEOF |
|
private LocalizedOutput |
promptwriter |
|
private static char |
RETURN |
|
private static char |
SEMICOLON |
|
private static char |
SINGLEQUOTE |
|
private static char |
SLASH |
|
private java.io.Reader |
source |
|
private static char |
SPACE |
|
private int |
state |
|
private java.lang.StringBuffer |
statement |
|
private static char |
TAB |
Constructor | Description |
---|---|
StatementFinder(LocalizedInput s,
LocalizedOutput promptDest) |
The constructor does not assume the stream is data input
or buffered, so it will wrap it appropriately.
|
Modifier and Type | Method | Description |
---|---|---|
private boolean |
atEOF() |
|
void |
close() |
|
java.lang.String |
nextStatement() |
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 |
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.
|
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(LocalizedInput s) |
Reinit is used to redirect the finder to another stream.
|
private boolean |
whiteSpace(char c) |
Determine if the given character is considered whitespace
|
private java.io.Reader source
private java.lang.StringBuffer statement
private int state
private boolean atEOF
private boolean peekEOF
private char peekChar
private boolean peeked
private LocalizedOutput promptwriter
private boolean doPrompt
private boolean continuedStatement
private static final int IN_STATEMENT
private static final int IN_STRING
private static final int IN_SQLCOMMENT
private static final int END_OF_STATEMENT
private static final int END_OF_INPUT
private static final char MINUS
private static final char SINGLEQUOTE
private static final char DOUBLEQUOTE
private static final char SEMICOLON
private static final char NEWLINE
private static final char RETURN
private static final char SPACE
private static final char TAB
private static final char FORMFEED
private static final char SLASH
private static final char ASTERISK
public StatementFinder(LocalizedInput s, LocalizedOutput promptDest)
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.public void ReInit(LocalizedInput s)
s
- the input stream for reading statements from.public void close() throws java.io.IOException
java.io.IOException
public java.lang.String nextStatement()
private boolean whiteSpace(char c)
c
- the character to considerprivate void readBracketedComment()
private void readSingleLineComment(char commentChar)
The form of a single line comment is, in regexp, XX.*$, where XX is two instances of commentChar.
commentChar
- the character whose duplication signifies
the start of the comment.private void readString(char stringDelimiter)
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.
stringDelimiter
- the starting and ending character
for the string being read.private boolean atEOF()
private boolean peekEOF()
private char readChar()
private char peekChar()
Apache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.