MCPcopy Create free account
hub / github.com/denoland/std / parseDictionaryInternal

Function parseDictionaryInternal

http/unstable_structured_fields.ts:643–682  ·  view source on GitHub ↗
(state: ParserState)

Source from the content-addressed store, hash-verified

641}
642
643function 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.

Callers 1

parseDictionaryFunction · 0.85

Calls 8

isEofFunction · 0.85
parseKeyFunction · 0.85
peekFunction · 0.85
consumeFunction · 0.85
parseItemOrInnerListFunction · 0.85
parseParametersFunction · 0.85
skipOWSFunction · 0.85
setMethod · 0.65

Tested by

no test coverage detected