Skip to content

Commit 71d8b2d

Browse files
committed
小数点の直後にドットが続くとエラーになるように
1 parent 8ab13f8 commit 71d8b2d

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/parser/scanner.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,9 @@ export class Scanner implements ITokenStream {
507507
}
508508
const decimalPoint = this.tryReadDecimalPoint(hasLeadingDot);
509509
if (decimalPoint) {
510+
if (this.stream.char === '.') {
511+
throw new AiScriptSyntaxError('dot cannot follow a decimal point', this.stream.getPos());
512+
}
510513
while (!this.stream.eof as boolean && digit.test(this.stream.char as string)) {
511514
fractional += this.stream.char;
512515
this.stream.next();

test/syntax.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as assert from 'assert';
2-
import { describe, test } from 'vitest';
2+
import { describe, expect, 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, AiScriptUnexpectedEOFError } from '../src/error';
5+
import { AiScriptRuntimeError, AiScriptSyntaxError, AiScriptUnexpectedEOFError } from '../src/error';
66
import { exe, getMeta, eq } from './testutils';
77

88
/*
@@ -1485,6 +1485,18 @@ describe('Infix expression', () => {
14851485
NUM(3)
14861486
);
14871487
});
1488+
1489+
test.concurrent('dot cannot follow a decimal point', async () => {
1490+
await expect(() => exe(`
1491+
<: 1..to_str()
1492+
`)).rejects.toThrow(AiScriptSyntaxError);
1493+
});
1494+
1495+
test.concurrent('dot following parenthesis after decimal point', async () => {
1496+
eq(await exe(`
1497+
<: (1.).to_str()
1498+
`), STR('1'));
1499+
});
14881500
});
14891501

14901502
describe('if', () => {

0 commit comments

Comments
 (0)