fix: Lexer 支持 -- 行注释和块注释,修复演示页解析报错
This commit is contained in:
@@ -85,6 +85,16 @@ export 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()];
|
||||
@@ -135,6 +145,26 @@ export class Lexer {
|
||||
}
|
||||
}
|
||||
|
||||
/** 跳过 -- 行注释到行尾 */
|
||||
private skipLineComment(): void {
|
||||
while (this.ch !== '\n' && this.ch !== '\r' && this.ch !== '') {
|
||||
this.readChar();
|
||||
}
|
||||
}
|
||||
|
||||
/** 跳过块注释 slash-star ... star-slash */
|
||||
private skipBlockComment(): void {
|
||||
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 /
|
||||
}
|
||||
}
|
||||
|
||||
private readIdentifier(): string {
|
||||
const start = this.position;
|
||||
while (this.isLetter(this.ch) || this.isDigit(this.ch) || this.ch === '_') {
|
||||
|
||||
Reference in New Issue
Block a user