fix: Lexer 支持 -- 行注释和块注释,修复演示页解析报错
This commit is contained in:
Vendored
+28
@@ -1944,6 +1944,16 @@ class Lexer {
|
||||
tok = { type: TokenType.EOF, value: '', position: this.position };
|
||||
break;
|
||||
default:
|
||||
// SQL 注释: -- 行注释
|
||||
if (this.ch === '-' && this.peekChar() === '-') {
|
||||
this.skipLineComment();
|
||||
return this.nextToken();
|
||||
}
|
||||
// SQL 注释: /* 块注释 */
|
||||
if (this.ch === '/' && this.peekChar() === '*') {
|
||||
this.skipBlockComment();
|
||||
return this.nextToken();
|
||||
}
|
||||
if (this.isLetter(this.ch)) {
|
||||
const ident = this.readIdentifier();
|
||||
const keyword = KEYWORDS[ident.toUpperCase()];
|
||||
@@ -1992,6 +2002,24 @@ class Lexer {
|
||||
this.readChar();
|
||||
}
|
||||
}
|
||||
/** 跳过 -- 行注释到行尾 */
|
||||
skipLineComment() {
|
||||
while (this.ch !== '\n' && this.ch !== '\r' && this.ch !== '') {
|
||||
this.readChar();
|
||||
}
|
||||
}
|
||||
/** 跳过块注释 slash-star ... star-slash */
|
||||
skipBlockComment() {
|
||||
this.readChar(); // skip *
|
||||
this.readChar(); // move past *
|
||||
while (this.ch !== '' && !(this.ch === '*' && this.peekChar() === '/')) {
|
||||
this.readChar();
|
||||
}
|
||||
if (this.ch !== '') {
|
||||
this.readChar(); // skip *
|
||||
this.readChar(); // skip /
|
||||
}
|
||||
}
|
||||
readIdentifier() {
|
||||
const start = this.position;
|
||||
while (this.isLetter(this.ch) || this.isDigit(this.ch) || this.ch === '_') {
|
||||
|
||||
Reference in New Issue
Block a user