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

Function parseTopLevel

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

Source from the content-addressed store, hash-verified

13 * ```
14*/
15export function parseTopLevel(s: ITokenStream): Ast.Node[] {
16 const nodes: Ast.Node[] = [];
17
18 while (s.is(TokenKind.NewLine)) {
19 s.next();
20 }
21
22 while (!s.is(TokenKind.EOF)) {
23 switch (s.getTokenKind()) {
24 case TokenKind.Colon2: {
25 nodes.push(parseNamespace(s));
26 break;
27 }
28 case TokenKind.Sharp3: {
29 nodes.push(parseMeta(s));
30 break;
31 }
32 default: {
33 nodes.push(parseStatement(s));
34 break;
35 }
36 }
37
38 // terminator
39 switch (s.getTokenKind()) {
40 case TokenKind.NewLine:
41 case TokenKind.SemiColon: {
42 while (s.is(TokenKind.NewLine) || s.is(TokenKind.SemiColon)) {
43 s.next();
44 }
45 break;
46 }
47 case TokenKind.EOF: {
48 break;
49 }
50 default: {
51 throw new AiScriptSyntaxError('Multiple statements cannot be placed on a single line.', s.getPos());
52 }
53 }
54 }
55
56 return nodes;
57}
58
59/**
60 * ```abnf

Callers 1

parseMethod · 0.85

Calls 7

parseNamespaceFunction · 0.85
parseMetaFunction · 0.85
parseStatementFunction · 0.85
isMethod · 0.65
nextMethod · 0.65
getTokenKindMethod · 0.65
getPosMethod · 0.65

Tested by

no test coverage detected