in core/src/main/java/com/alibaba/druid/sql/dialect/mysql/parser/MySqlLexer.java [698:914]
public void scanComment() {
Token lastToken = this.token;
if (ch == '-') {
boolean supportStandardComment = (features & SQLParserFeature.MySQLSupportStandardComment.mask) != 0;
/*
* just for tddl test case;
* test case : MySqlSelectTest_plus_sub_comment.java
*/
char before_1 = pos == 0 ? ' ' : charAt(pos - 1);
char next_2 = charAt(pos + 2);
if (isDigit(next_2)) {
scanChar();
token = Token.SUB;
return;
} else if (supportStandardComment
|| ((before_1 == ' ' || (before_1 != '-' && before_1 != '+'))
&& (next_2 == ' ' || next_2 == EOI || next_2 == '\n'))
) {
// it is comments
} else if ((before_1 == '-' || before_1 == '+') && next_2 == ' ') {
throw new ParserException("illegal state. " + info());
} else {
if (ch == '-') {
scanChar();
token = Token.SUB;
return;
} else if (ch == '+') {
scanChar();
token = Token.PLUS;
return;
}
}
} else if (ch != '/') {
throw new ParserException("illegal state. " + info());
}
mark = pos;
bufPos = 0;
scanChar();
// /*+ */
if (ch == '*') {
scanChar();
bufPos++;
while (ch == ' ') {
scanChar();
bufPos++;
}
boolean isHint = false;
int startHintSp = bufPos + 1;
if (ch == '!' //
|| ch == '+' // oceanbase hints
|| ((ch == 'T' && //TDDL hint
charAt(pos + 1) == 'D' //
&& charAt(pos + 2) == 'D' //
&& charAt(pos + 3) == 'L')
&& isEnabled(SQLParserFeature.TDDLHint))
) {
isHint = true;
scanChar();
bufPos++;
}
int starIndex = pos;
// Dealing with nesting hint.
int depth = 1;
while (true) {
char ch = charAt(starIndex);
if (ch == '/' && charAt(starIndex + 1) == '*') {
starIndex += 2;
ch = charAt(starIndex);
if (ch == '!' || ch == '+') {
++depth;
++starIndex;
continue;
}
} else if (ch == '*' && charAt(starIndex + 1) == '/') {
if (0 == --depth) {
break;
}
starIndex += 2;
continue;
}
if (ch == EOI) {
this.token = Token.ERROR;
return;
}
++starIndex;
}
if (isHint) {
stringVal = this.subString(mark + startHintSp, starIndex - startHintSp - mark);
token = Token.HINT;
} else {
if (!optimizedForParameterized) {
stringVal = this.subString(mark, starIndex + 2 - mark);
}
token = Token.MULTI_LINE_COMMENT;
commentCount++;
if (keepComments) {
stringVal = this.subString(mark, starIndex + 2 - mark);
addComment(stringVal);
}
}
pos = starIndex + 2;
ch = charAt(pos);
endOfComment = isEOF();
if (commentHandler != null
&& commentHandler.handle(lastToken, stringVal)) {
return;
}
if (!isHint && !isAllowComment() && !isSafeComment(stringVal)) {
throw new NotAllowCommentException();
}
return;
}
if (ch == '!' && isEnabled(SQLParserFeature.TDDLHint)) { // TDDL HINT
scanChar();
bufPos++;
while (ch == ' ') {
scanChar();
bufPos++;
}
int startHintSp = bufPos + 1;
int starIndex = pos;
for (; ; ) {
starIndex = text.indexOf('*', starIndex);
if (starIndex == -1 || starIndex == text.length() - 1) {
this.token = Token.ERROR;
return;
}
if (charAt(starIndex + 1) == '/') {
stringVal = this.subString(mark + startHintSp, starIndex - startHintSp - mark);
token = Token.HINT;
pos = starIndex + 2;
ch = charAt(pos);
break;
}
starIndex++;
}
endOfComment = isEOF();
if (commentHandler != null
&& commentHandler.handle(lastToken, stringVal)) {
return;
}
if (!isAllowComment() && !isSafeComment(stringVal)) {
throw new NotAllowCommentException();
}
return;
}
if (ch == '/' || ch == '-') {
bufPos++;
scanChar();
for (; ; ) {
if (ch == '\r') {
bufPos++;
scanChar();
if (ch == '\n') {
scanChar();
}
break;
} else if (ch == EOI) {
bufPos++;
break;
}
if (ch == '\n') {
bufPos++;
scanChar();
break;
}
bufPos++;
scanChar();
}
stringVal = subString(mark, bufPos);
token = Token.LINE_COMMENT;
commentCount++;
if (keepComments) {
addComment(stringVal);
}
if (commentHandler != null && commentHandler.handle(lastToken, stringVal)) {
return;
}
endOfComment = isEOF();
if (!isAllowComment() && (endOfComment || !isSafeComment(stringVal))) {
throw new NotAllowCommentException();
}
return;
}
}