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

Method readDocument

yaml/_loader_state.ts:1794–1853  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

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