fix: Lexer 支持 -- 行注释和块注释,修复演示页解析报错
CI / test (18.x) (push) Successful in 9m54s
CI / test (20.x) (push) Successful in 9m54s
CI / test (22.x) (push) Successful in 9m54s
CI / test (24.x) (push) Successful in 9m50s

This commit is contained in:
thzxx
2026-07-26 17:42:48 +08:00
parent b21cbfd544
commit 5068cd0409
8 changed files with 118 additions and 4 deletions
+28
View File
@@ -1940,6 +1940,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()];
@@ -1988,6 +1998,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 === '_') {