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

Method readDocument

yaml/_loader_state.ts:1783–1842  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1781 }
1782
1783 readDocument() {
1784 const documentStart = this.#scanner.position;
1785
1786 this.checkLineBreaks = false;
1787 this.tagMap = new Map();
1788 this.anchorMap = new Map();
1789
1790 const hasDirectives = this.readDirectives();
1791
1792 this.skipSeparationSpace(true, -1);
1793
1794 let result = null;
1795
1796 if (
1797 this.lineIndent === 0 &&
1798 this.#scanner.peek() === MINUS &&
1799 this.#scanner.peek(1) === MINUS &&
1800 this.#scanner.peek(2) === MINUS
1801 ) {
1802 this.#scanner.position += 3;
1803 this.skipSeparationSpace(true, -1);
1804 } else if (hasDirectives) {
1805 throw this.#createError(
1806 "Cannot read document: directives end mark is expected",
1807 );
1808 }
1809
1810 const newState = this.composeNode({
1811 parentIndent: this.lineIndent - 1,
1812 nodeContext: CONTEXT_BLOCK_OUT,
1813 allowToSeek: false,
1814 allowCompact: true,
1815 });
1816 if (newState) result = newState.result;
1817 this.skipSeparationSpace(true, -1);
1818
1819 if (
1820 this.checkLineBreaks &&
1821 PATTERN_NON_ASCII_LINE_BREAKS_REGEXP.test(
1822 this.#scanner.source.slice(documentStart, this.#scanner.position),
1823 )
1824 ) {
1825 this.dispatchWarning("non-ASCII line breaks are interpreted as content");
1826 }
1827
1828 if (
1829 this.#scanner.position === this.lineStart && this.testDocumentSeparator()
1830 ) {
1831 if (this.#scanner.peek() === DOT) {
1832 this.#scanner.position += 3;
1833 this.skipSeparationSpace(true, -1);
1834 }
1835 } else if (!this.#scanner.eof()) {
1836 throw this.#createError(
1837 "Cannot read document: end of the stream or a document separator is expected",
1838 );
1839 }
1840

Callers 1

readDocumentsMethod · 0.95

Calls 9

readDirectivesMethod · 0.95
skipSeparationSpaceMethod · 0.95
#createErrorMethod · 0.95
composeNodeMethod · 0.95
dispatchWarningMethod · 0.95
testDocumentSeparatorMethod · 0.95
peekMethod · 0.45
sliceMethod · 0.45
eofMethod · 0.45

Tested by

no test coverage detected