Skip to content

Commit 97b9d15

Browse files
authored
fix: 複数行コメントの*/がないと文法エラーが出るように (#887)
* Fix: 複数行コメントの*/がないと文法エラーが出るように * CHANGELOG削除
1 parent 5b3e5e7 commit 97b9d15

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/parser/scanner.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,10 +628,13 @@ export class Scanner implements ITokenStream {
628628
private skipCommentRange(): void {
629629
while (true) {
630630
if (this.stream.eof) {
631-
break;
631+
throw new AiScriptUnexpectedEOFError(this.stream.getPos());
632632
}
633633
if (this.stream.char === '*') {
634634
this.stream.next();
635+
if (this.stream.eof) {
636+
throw new AiScriptUnexpectedEOFError(this.stream.getPos());
637+
}
635638
if ((this.stream.char as string) === '/') {
636639
this.stream.next();
637640
break;

test/syntax.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as assert from 'assert';
22
import { describe, test } from 'vitest';
33
import { utils } from '../src';
44
import { NUM, STR, NULL, ARR, OBJ, BOOL, TRUE, FALSE, ERROR ,FN_NATIVE } from '../src/interpreter/value';
5-
import { AiScriptRuntimeError } from '../src/error';
5+
import { AiScriptRuntimeError, AiScriptUnexpectedEOFError } from '../src/error';
66
import { exe, getMeta, eq } from './testutils';
77

88
/*
@@ -514,6 +514,16 @@ describe('Comment', () => {
514514
`);
515515
eq(res, STR('a'));
516516
});
517+
518+
test.concurrent('invalid EOF in multi line comment', async () => {
519+
await assert.rejects(() => exe(`
520+
/* comment
521+
`), AiScriptUnexpectedEOFError);
522+
});
523+
524+
test.concurrent('invalid EOF in multi line comment 2', async () => {
525+
await assert.rejects(() => exe('/* comment *'), AiScriptUnexpectedEOFError);
526+
});
517527
});
518528

519529
describe('lang version', () => {

0 commit comments

Comments
 (0)