Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/parser/syntaxes/statements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ function parseReturn(s: ITokenStream): Ast.Return {
* StatementWithAttr = *Attr Statement
* ```
*/
function parseStatementWithAttr(s: ITokenStream): Ast.Definition {
export function parseStatementWithAttr(s: ITokenStream): Ast.Definition {
const attrs: Ast.Attribute[] = [];
while (s.is(TokenKind.OpenSharpBracket)) {
attrs.push(parseAttr(s) as Ast.Attribute);
Expand Down
6 changes: 5 additions & 1 deletion src/parser/syntaxes/toplevel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NODE } from '../utils.js';
import { TokenKind } from '../token.js';
import { AiScriptSyntaxError, AiScriptUnexpectedEOFError } from '../../error.js';
import { parseDefStatement, parseStatement } from './statements.js';
import { parseDefStatement, parseStatement, parseStatementWithAttr } from './statements.js';
import { parseExpr } from './expressions.js';

import type * as Ast from '../../node.js';
Expand Down Expand Up @@ -91,6 +91,10 @@ export function parseNamespace(s: ITokenStream): Ast.Namespace {
members.push(parseNamespace(s));
break;
}
case TokenKind.OpenSharpBracket: {
members.push(parseStatementWithAttr(s));
break;
}
}

// terminator
Expand Down
19 changes: 19 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,25 @@ describe('Attribute', () => {
if (attr.value.type !== 'bool') assert.fail();
assert.equal(attr.value.value, true);
});

test.concurrent('attribute with statement under namespace', async () => {
const parser = new Parser();
const nodes = parser.parse(`
:: Tests {
#[test]
@assert_success() {
<: "Hello, world!"
}
}
`);
assert.equal(nodes.length, 1);
const ns = nodes[0];
assert.ok(ns.type === 'ns');
const member = ns.members[0];
assert.ok(member.type === 'def');
const attr = member.attr[0];
assert.equal(attr.name, 'test');
});
});

describe('Location', () => {
Expand Down
1 change: 1 addition & 0 deletions unreleased/attr-under-ns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- 名前空間下の変数定義に属性を付与できるようになりました。
Loading