MCPcopy Index your code
hub / github.com/aiscript-dev/aiscript / parseNamespace

Function parseNamespace

src/parser/syntaxes/toplevel.ts:64–124  ·  view source on GitHub ↗
(s: ITokenStream)

Source from the content-addressed store, hash-verified

62 * ```
63*/
64export function parseNamespace(s: ITokenStream): Ast.Namespace {
65 const startPos = s.getPos();
66
67 s.expect(TokenKind.Colon2);
68 s.next();
69
70 s.expect(TokenKind.Identifier);
71 const name = s.getTokenValue();
72 s.next();
73
74 const members: (Ast.Namespace | Ast.Definition)[] = [];
75 s.expect(TokenKind.OpenBrace);
76 s.next();
77
78 while (s.is(TokenKind.NewLine)) {
79 s.next();
80 }
81
82 while (!s.is(TokenKind.CloseBrace)) {
83 switch (s.getTokenKind()) {
84 case TokenKind.VarKeyword:
85 case TokenKind.LetKeyword:
86 case TokenKind.At: {
87 members.push(parseDefStatement(s));
88 break;
89 }
90 case TokenKind.Colon2: {
91 members.push(parseNamespace(s));
92 break;
93 }
94 case TokenKind.OpenSharpBracket: {
95 members.push(parseStatementWithAttr(s));
96 break;
97 }
98 }
99
100 // terminator
101 switch (s.getTokenKind()) {
102 case TokenKind.NewLine:
103 case TokenKind.SemiColon: {
104 while (s.is(TokenKind.NewLine) || s.is(TokenKind.SemiColon)) {
105 s.next();
106 }
107 break;
108 }
109 case TokenKind.CloseBrace: {
110 break;
111 }
112 case TokenKind.EOF: {
113 throw new AiScriptUnexpectedEOFError(s.getPos());
114 }
115 default: {
116 throw new AiScriptSyntaxError('Multiple statements cannot be placed on a single line.', s.getPos());
117 }
118 }
119 }
120 s.expect(TokenKind.CloseBrace);
121 s.next();

Callers 1

parseTopLevelFunction · 0.85

Calls 9

parseDefStatementFunction · 0.85
parseStatementWithAttrFunction · 0.85
NODEFunction · 0.85
getPosMethod · 0.65
expectMethod · 0.65
nextMethod · 0.65
getTokenValueMethod · 0.65
isMethod · 0.65
getTokenKindMethod · 0.65

Tested by

no test coverage detected