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

Method readBlockMapping

yaml/_loader_state.ts:1166–1352  ·  view source on GitHub ↗
(
    tag: string | null,
    anchor: string | null,
    nodeIndent: number,
    flowIndent: number,
  )

Source from the content-addressed store, hash-verified

1164 return { tag, anchor, kind: "scalar", result };
1165 }
1166 readBlockMapping(
1167 tag: string | null,
1168 anchor: string | null,
1169 nodeIndent: number,
1170 flowIndent: number,
1171 ): State | void {
1172 const result = {};
1173 const overridableKeys = new Set<string>();
1174
1175 let allowCompact = false;
1176 let line: number;
1177 let pos: number;
1178 let keyTag = null;
1179 let keyNode = null;
1180 let valueNode = null;
1181 let atExplicitKey = false;
1182 let detected = false;
1183
1184 if (anchor !== null) this.anchorMap.set(anchor, result);
1185
1186 let ch = this.#scanner.peek();
1187
1188 while (ch !== 0) {
1189 const following = this.#scanner.peek(1);
1190 line = this.line; // Save the current line.
1191 pos = this.#scanner.position;
1192
1193 //
1194 // Explicit notation case. There are two separate blocks:
1195 // first for the key (denoted by "?") and second for the value (denoted by ":")
1196 //
1197 if ((ch === QUESTION || ch === COLON) && isWhiteSpaceOrEOL(following)) {
1198 if (ch === QUESTION) {
1199 if (atExplicitKey) {
1200 this.storeMappingPair(
1201 result,
1202 overridableKeys,
1203 keyTag as string,
1204 keyNode,
1205 null,
1206 );
1207 keyTag = null;
1208 keyNode = null;
1209 valueNode = null;
1210 }
1211
1212 detected = true;
1213 atExplicitKey = true;
1214 allowCompact = true;
1215 } else if (atExplicitKey) {
1216 // i.e. 0x3A/* : */ === character after the explicit key.
1217 atExplicitKey = false;
1218 allowCompact = true;
1219 } else {
1220 throw this.#createError(
1221 "Cannot read block as explicit mapping pair is incomplete: a key node is missed or followed by a non-tabulated empty line",
1222 );
1223 }

Callers 1

composeNodeMethod · 0.95

Calls 9

storeMappingPairMethod · 0.95
#createErrorMethod · 0.95
composeNodeMethod · 0.95
skipWhitespacesMethod · 0.95
skipSeparationSpaceMethod · 0.95
isWhiteSpaceOrEOLFunction · 0.90
setMethod · 0.65
peekMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected