* ```abnf * Match = "match" Expr "{" [(MatchCase *(SEP MatchCase) [SEP DefaultCase] [SEP]) / DefaultCase [SEP]] "}" * ```
(s: ITokenStream)
| 444 | * ``` |
| 445 | */ |
| 446 | function parseMatch(s: ITokenStream): Ast.Match { |
| 447 | const startPos = s.getPos(); |
| 448 | |
| 449 | s.expect(TokenKind.MatchKeyword); |
| 450 | s.next(); |
| 451 | const about = parseExpr(s, false); |
| 452 | |
| 453 | s.expect(TokenKind.OpenBrace); |
| 454 | s.next(); |
| 455 | |
| 456 | if (s.is(TokenKind.NewLine)) { |
| 457 | s.next(); |
| 458 | } |
| 459 | |
| 460 | const qs: Ast.Match['qs'] = []; |
| 461 | let x: Ast.Match['default']; |
| 462 | if (s.is(TokenKind.CaseKeyword)) { |
| 463 | qs.push(parseMatchCase(s)); |
| 464 | let sep = parseOptionalSeparator(s); |
| 465 | while (s.is(TokenKind.CaseKeyword)) { |
| 466 | if (!sep) { |
| 467 | throw new AiScriptSyntaxError('separator expected', s.getPos()); |
| 468 | } |
| 469 | qs.push(parseMatchCase(s)); |
| 470 | sep = parseOptionalSeparator(s); |
| 471 | } |
| 472 | if (s.is(TokenKind.DefaultKeyword)) { |
| 473 | if (!sep) { |
| 474 | throw new AiScriptSyntaxError('separator expected', s.getPos()); |
| 475 | } |
| 476 | x = parseDefaultCase(s); |
| 477 | parseOptionalSeparator(s); |
| 478 | } |
| 479 | } else if (s.is(TokenKind.DefaultKeyword)) { |
| 480 | x = parseDefaultCase(s); |
| 481 | parseOptionalSeparator(s); |
| 482 | } |
| 483 | |
| 484 | s.expect(TokenKind.CloseBrace); |
| 485 | s.next(); |
| 486 | |
| 487 | return NODE('match', { about, qs, default: x }, startPos, s.getPos()); |
| 488 | } |
| 489 | |
| 490 | /** |
| 491 | * ```abnf |
no test coverage detected