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

Function parseBlock

src/parser/syntaxes/common.ts:99–136  ·  view source on GitHub ↗
(s: ITokenStream)

Source from the content-addressed store, hash-verified

97 * ```
98*/
99export function parseBlock(s: ITokenStream): (Ast.Statement | Ast.Expression)[] {
100 s.expect(TokenKind.OpenBrace);
101 s.next();
102
103 while (s.is(TokenKind.NewLine)) {
104 s.next();
105 }
106
107 const steps: (Ast.Statement | Ast.Expression)[] = [];
108 while (!s.is(TokenKind.CloseBrace)) {
109 steps.push(parseStatement(s));
110
111 // terminator
112 switch (s.getTokenKind()) {
113 case TokenKind.NewLine:
114 case TokenKind.SemiColon: {
115 while (s.is(TokenKind.NewLine) || s.is(TokenKind.SemiColon)) {
116 s.next();
117 }
118 break;
119 }
120 case TokenKind.CloseBrace: {
121 break;
122 }
123 case TokenKind.EOF: {
124 throw new AiScriptUnexpectedEOFError(s.getPos());
125 }
126 default: {
127 throw new AiScriptSyntaxError('Multiple statements cannot be placed on a single line.', s.getPos());
128 }
129 }
130 }
131
132 s.expect(TokenKind.CloseBrace);
133 s.next();
134
135 return steps;
136}
137
138/**
139 * ```abnf

Callers 5

parseBlockOrStatementFunction · 0.85
parseFnDefFunction · 0.85
parseLoopFunction · 0.85
parseFnExprFunction · 0.85
parseEvalFunction · 0.85

Calls 6

parseStatementFunction · 0.85
expectMethod · 0.65
nextMethod · 0.65
isMethod · 0.65
getTokenKindMethod · 0.65
getPosMethod · 0.65

Tested by

no test coverage detected