Skip to content

Commit

Permalink
fix: 複数行コメントの*/がないと文法エラーが出るように (#887)
Browse files Browse the repository at this point in the history
* Fix: 複数行コメントの*/がないと文法エラーが出るように

* CHANGELOG削除
  • Loading branch information
takejohn authored Jan 3, 2025
1 parent 5b3e5e7 commit 97b9d15
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/parser/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,10 +628,13 @@ export class Scanner implements ITokenStream {
private skipCommentRange(): void {
while (true) {
if (this.stream.eof) {
break;
throw new AiScriptUnexpectedEOFError(this.stream.getPos());
}
if (this.stream.char === '*') {
this.stream.next();
if (this.stream.eof) {
throw new AiScriptUnexpectedEOFError(this.stream.getPos());
}
if ((this.stream.char as string) === '/') {
this.stream.next();
break;
Expand Down
12 changes: 11 additions & 1 deletion test/syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as assert from 'assert';
import { describe, test } from 'vitest';
import { utils } from '../src';
import { NUM, STR, NULL, ARR, OBJ, BOOL, TRUE, FALSE, ERROR ,FN_NATIVE } from '../src/interpreter/value';
import { AiScriptRuntimeError } from '../src/error';
import { AiScriptRuntimeError, AiScriptUnexpectedEOFError } from '../src/error';
import { exe, getMeta, eq } from './testutils';

/*
Expand Down Expand Up @@ -514,6 +514,16 @@ describe('Comment', () => {
`);
eq(res, STR('a'));
});

test.concurrent('invalid EOF in multi line comment', async () => {
await assert.rejects(() => exe(`
/* comment
`), AiScriptUnexpectedEOFError);
});

test.concurrent('invalid EOF in multi line comment 2', async () => {
await assert.rejects(() => exe('/* comment *'), AiScriptUnexpectedEOFError);
});
});

describe('lang version', () => {
Expand Down

0 comments on commit 97b9d15

Please sign in to comment.