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

Method readBlockScalar

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

Source from the content-addressed store, hash-verified

1004 // Handles block scaler styles: e.g. '|', '>', '|-' and '>-'.
1005 // https://yaml.org/spec/1.2.2/#81-block-scalar-styles
1006 readBlockScalar(
1007 tag: string | null,
1008 anchor: string | null,
1009 nodeIndent: number,
1010 ): State | void {
1011 let chomping = CHOMPING_CLIP;
1012 let didReadContent = false;
1013 let detectedIndent = false;
1014 let textIndent = nodeIndent;
1015 let emptyLines = 0;
1016 let atMoreIndented = false;
1017
1018 let ch = this.#scanner.peek();
1019
1020 let folding = false;
1021 if (ch === VERTICAL_LINE) {
1022 folding = false;
1023 } else if (ch === GREATER_THAN) {
1024 folding = true;
1025 } else {
1026 return;
1027 }
1028
1029 let result = "";
1030
1031 let tmp = 0;
1032 while (ch !== 0) {
1033 this.#scanner.next();
1034 ch = this.#scanner.peek();
1035
1036 if (ch === PLUS || ch === MINUS) {
1037 if (CHOMPING_CLIP === chomping) {
1038 chomping = ch === PLUS ? CHOMPING_KEEP : CHOMPING_STRIP;
1039 } else {
1040 throw this.#createError(
1041 "Cannot read block: chomping mode identifier repeated",
1042 );
1043 }
1044 } else if ((tmp = decimalCharCodeToNumber(ch)) >= 0) {
1045 if (tmp === 0) {
1046 throw this.#createError(
1047 "Cannot read block: indentation width must be greater than 0",
1048 );
1049 } else if (!detectedIndent) {
1050 textIndent = nodeIndent + tmp - 1;
1051 detectedIndent = true;
1052 } else {
1053 throw this.#createError(
1054 "Cannot read block: indentation width identifier repeated",
1055 );
1056 }
1057 } else {
1058 break;
1059 }
1060 }
1061
1062 if (isWhiteSpace(ch)) {
1063 this.skipWhitespaces();

Callers 1

composeNodeMethod · 0.95

Calls 11

#createErrorMethod · 0.95
skipWhitespacesMethod · 0.95
skipCommentMethod · 0.95
readLineBreakMethod · 0.95
captureSegmentMethod · 0.95
isWhiteSpaceFunction · 0.90
isEOLFunction · 0.90
decimalCharCodeToNumberFunction · 0.85
setMethod · 0.65
peekMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected