Skip to content

Commit 35c63c5

Browse files
authored
名前空間下の変数定義に属性を付与できるように (#892)
1 parent c3d71b5 commit 35c63c5

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

src/parser/syntaxes/statements.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ function parseReturn(s: ITokenStream): Ast.Return {
379379
* StatementWithAttr = *Attr Statement
380380
* ```
381381
*/
382-
function parseStatementWithAttr(s: ITokenStream): Ast.Definition {
382+
export function parseStatementWithAttr(s: ITokenStream): Ast.Definition {
383383
const attrs: Ast.Attribute[] = [];
384384
while (s.is(TokenKind.OpenSharpBracket)) {
385385
attrs.push(parseAttr(s) as Ast.Attribute);

src/parser/syntaxes/toplevel.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NODE } from '../utils.js';
22
import { TokenKind } from '../token.js';
33
import { AiScriptSyntaxError, AiScriptUnexpectedEOFError } from '../../error.js';
4-
import { parseDefStatement, parseStatement } from './statements.js';
4+
import { parseDefStatement, parseStatement, parseStatementWithAttr } from './statements.js';
55
import { parseExpr } from './expressions.js';
66

77
import type * as Ast from '../../node.js';
@@ -91,6 +91,10 @@ export function parseNamespace(s: ITokenStream): Ast.Namespace {
9191
members.push(parseNamespace(s));
9292
break;
9393
}
94+
case TokenKind.OpenSharpBracket: {
95+
members.push(parseStatementWithAttr(s));
96+
break;
97+
}
9498
}
9599

96100
// terminator

test/index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,25 @@ describe('Attribute', () => {
929929
if (attr.value.type !== 'bool') assert.fail();
930930
assert.equal(attr.value.value, true);
931931
});
932+
933+
test.concurrent('attribute with statement under namespace', async () => {
934+
const parser = new Parser();
935+
const nodes = parser.parse(`
936+
:: Tests {
937+
#[test]
938+
@assert_success() {
939+
<: "Hello, world!"
940+
}
941+
}
942+
`);
943+
assert.equal(nodes.length, 1);
944+
const ns = nodes[0];
945+
assert.ok(ns.type === 'ns');
946+
const member = ns.members[0];
947+
assert.ok(member.type === 'def');
948+
const attr = member.attr[0];
949+
assert.equal(attr.name, 'test');
950+
});
932951
});
933952

934953
describe('Location', () => {

unreleased/attr-under-ns.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- 名前空間下の変数定義に属性を付与できるようになりました。

0 commit comments

Comments
 (0)