(state: ParserState)
| 641 | } |
| 642 | |
| 643 | function parseDictionaryInternal(state: ParserState): Dictionary { |
| 644 | const dict: Map<string, Item | InnerList> = new Map(); |
| 645 | |
| 646 | while (!isEof(state)) { |
| 647 | const key = parseKey(state); |
| 648 | let member: Item | InnerList; |
| 649 | |
| 650 | if (peek(state) === "=") { |
| 651 | consume(state); // consume '=' |
| 652 | member = parseItemOrInnerList(state); |
| 653 | } else { |
| 654 | // Bare key means boolean true with parameters |
| 655 | const parameters = parseParameters(state); |
| 656 | member = { |
| 657 | value: { type: "boolean", value: true }, |
| 658 | parameters, |
| 659 | }; |
| 660 | } |
| 661 | |
| 662 | dict.set(key, member); |
| 663 | skipOWS(state); |
| 664 | if (isEof(state)) { |
| 665 | return dict; |
| 666 | } |
| 667 | if (peek(state) !== ",") { |
| 668 | throw new SyntaxError( |
| 669 | `Invalid structured field: expected ',' at position ${state.pos}`, |
| 670 | ); |
| 671 | } |
| 672 | consume(state); // consume ',' |
| 673 | skipOWS(state); |
| 674 | if (isEof(state)) { |
| 675 | throw new SyntaxError( |
| 676 | "Invalid structured field: trailing comma in dictionary", |
| 677 | ); |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | return dict; |
| 682 | } |
| 683 | |
| 684 | /** |
| 685 | * Parses an Item Structured Field value. |
no test coverage detected