Lines Matching refs:state
1262 function generateError(state, message) { argument
1264 name: state.filename,
1265 buffer: state.input.slice(0, -1), // omit trailing \0
1266 position: state.position,
1267 line: state.line,
1268 column: state.position - state.lineStart
1276 function throwError(state, message) { argument
1277 throw generateError(state, message);
1280 function throwWarning(state, message) { argument
1281 if (state.onWarning) {
1282 state.onWarning.call(null, generateError(state, message));
1289 YAML: function handleYamlDirective(state, name, args) {
1293 if (state.version !== null) {
1294 throwError(state, 'duplication of %YAML directive');
1298 throwError(state, 'YAML directive accepts exactly one argument');
1304 throwError(state, 'ill-formed argument of the YAML directive');
1311 throwError(state, 'unacceptable YAML version of the document');
1314 state.version = args[0];
1315 state.checkLineBreaks = (minor < 2);
1318 throwWarning(state, 'unsupported YAML version of the document');
1322 TAG: function handleTagDirective(state, name, args) {
1327 throwError(state, 'TAG directive accepts exactly two arguments');
1334 throwError(state, 'ill-formed tag handle (first argument) of the TAG directive');
1337 if (_hasOwnProperty$1.call(state.tagMap, handle)) {
1338 throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
1342 throwError(state, 'ill-formed tag prefix (second argument) of the TAG directive');
1348 throwError(state, 'tag prefix is malformed: ' + prefix);
1351 state.tagMap[handle] = prefix;
1356 function captureSegment(state, start, end, checkJson) { argument
1360 _result = state.input.slice(start, end);
1367 throwError(state, 'expected valid JSON character');
1371 throwError(state, 'the stream contains non-printable characters');
1374 state.result += _result;
1378 function mergeMappings(state, destination, source, overridableKeys) { argument
1382 throwError(state, 'cannot merge mappings; the provided source object is unacceptable');
1397 function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, argument
1410 throwError(state, 'nested arrays are not supported inside keys');
1436 mergeMappings(state, _result, valueNode[index], overridableKeys);
1439 mergeMappings(state, _result, valueNode, overridableKeys);
1442 if (!state.json &&
1445 state.line = startLine || state.line;
1446 state.lineStart = startLineStart || state.lineStart;
1447 state.position = startPos || state.position;
1448 throwError(state, 'duplicated mapping key');
1468 function readLineBreak(state) { argument
1471 ch = state.input.charCodeAt(state.position);
1474 state.position++;
1476 state.position++;
1477 if (state.input.charCodeAt(state.position) === 0x0A/* LF */) {
1478 state.position++;
1481 throwError(state, 'a line break is expected');
1484 state.line += 1;
1485 state.lineStart = state.position;
1486 state.firstTabInLine = -1;
1489 function skipSeparationSpace(state, allowComments, checkIndent) { argument
1491 ch = state.input.charCodeAt(state.position);
1495 if (ch === 0x09/* Tab */ && state.firstTabInLine === -1) {
1496 state.firstTabInLine = state.position;
1498 ch = state.input.charCodeAt(++state.position);
1503 ch = state.input.charCodeAt(++state.position);
1508 readLineBreak(state);
1510 ch = state.input.charCodeAt(state.position);
1512 state.lineIndent = 0;
1515 state.lineIndent++;
1516 ch = state.input.charCodeAt(++state.position);
1523 if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
1524 throwWarning(state, 'deficient indentation');
1530 function testDocumentSeparator(state) { argument
1531 var _position = state.position,
1534 ch = state.input.charCodeAt(_position);
1536 // Condition state.position === state.lineStart is tested
1539 ch === state.input.charCodeAt(_position + 1) &&
1540 ch === state.input.charCodeAt(_position + 2)) {
1544 ch = state.input.charCodeAt(_position);
1554 function writeFoldedLines(state, count) { argument
1556 state.result += ' ';
1558 state.result += common.repeat('\n', count - 1);
1563 function readPlainScalar(state, nodeIndent, withinFlowCollection) { argument
1572 _kind = state.kind,
1573 _result = state.result,
1576 ch = state.input.charCodeAt(state.position);
1595 following = state.input.charCodeAt(state.position + 1);
1603 state.kind = 'scalar';
1604 state.result = '';
1605 captureStart = captureEnd = state.position;
1610 following = state.input.charCodeAt(state.position + 1);
1618 preceding = state.input.charCodeAt(state.position - 1);
1624 } else if ((state.position === state.lineStart && testDocumentSeparator(state)) ||
1629 _line = state.line;
1630 _lineStart = state.lineStart;
1631 _lineIndent = state.lineIndent;
1632 skipSeparationSpace(state, false, -1);
1634 if (state.lineIndent >= nodeIndent) {
1636 ch = state.input.charCodeAt(state.position);
1639 state.position = captureEnd;
1640 state.line = _line;
1641 state.lineStart = _lineStart;
1642 state.lineIndent = _lineIndent;
1648 captureSegment(state, captureStart, captureEnd, false);
1649 writeFoldedLines(state, state.line - _line);
1650 captureStart = captureEnd = state.position;
1655 captureEnd = state.position + 1;
1658 ch = state.input.charCodeAt(++state.position);
1661 captureSegment(state, captureStart, captureEnd, false);
1663 if (state.result) {
1667 state.kind = _kind;
1668 state.result = _result;
1672 function readSingleQuotedScalar(state, nodeIndent) { argument
1676 ch = state.input.charCodeAt(state.position);
1682 state.kind = 'scalar';
1683 state.result = '';
1684 state.position++;
1685 captureStart = captureEnd = state.position;
1687 while ((ch = state.input.charCodeAt(state.position)) !== 0) {
1689 captureSegment(state, captureStart, state.position, true);
1690 ch = state.input.charCodeAt(++state.position);
1693 captureStart = state.position;
1694 state.position++;
1695 captureEnd = state.position;
1701 captureSegment(state, captureStart, captureEnd, true);
1702 writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
1703 captureStart = captureEnd = state.position;
1705 } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
1706 throwError(state, 'unexpected end of the document within a single quoted scalar');
1709 state.position++;
1710 captureEnd = state.position;
1714 throwError(state, 'unexpected end of the stream within a single quoted scalar');
1717 function readDoubleQuotedScalar(state, nodeIndent) { argument
1725 ch = state.input.charCodeAt(state.position);
1731 state.kind = 'scalar';
1732 state.result = '';
1733 state.position++;
1734 captureStart = captureEnd = state.position;
1736 while ((ch = state.input.charCodeAt(state.position)) !== 0) {
1738 captureSegment(state, captureStart, state.position, true);
1739 state.position++;
1743 captureSegment(state, captureStart, state.position, true);
1744 ch = state.input.charCodeAt(++state.position);
1747 skipSeparationSpace(state, false, nodeIndent);
1751 state.result += simpleEscapeMap[ch];
1752 state.position++;
1759 ch = state.input.charCodeAt(++state.position);
1765 throwError(state, 'expected hexadecimal character');
1769 state.result += charFromCodepoint(hexResult);
1771 state.position++;
1774 throwError(state, 'unknown escape sequence');
1777 captureStart = captureEnd = state.position;
1780 captureSegment(state, captureStart, captureEnd, true);
1781 writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
1782 captureStart = captureEnd = state.position;
1784 } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
1785 throwError(state, 'unexpected end of the document within a double quoted scalar');
1788 state.position++;
1789 captureEnd = state.position;
1793 throwError(state, 'unexpected end of the stream within a double quoted scalar');
1796 function readFlowCollection(state, nodeIndent) { argument
1801 _tag = state.tag,
1803 _anchor = state.anchor,
1815 ch = state.input.charCodeAt(state.position);
1829 if (state.anchor !== null) {
1830 state.anchorMap[state.anchor] = _result;
1833 ch = state.input.charCodeAt(++state.position);
1836 skipSeparationSpace(state, true, nodeIndent);
1838 ch = state.input.charCodeAt(state.position);
1841 state.position++;
1842 state.tag = _tag;
1843 state.anchor = _anchor;
1844 state.kind = isMapping ? 'mapping' : 'sequence';
1845 state.result = _result;
1848 throwError(state, 'missed comma between flow collection entries');
1851 throwError(state, "expected the node content, but found ','");
1858 following = state.input.charCodeAt(state.position + 1);
1862 state.position++;
1863 skipSeparationSpace(state, true, nodeIndent);
1867 _line = state.line; // Save the current line.
1868 _lineStart = state.lineStart;
1869 _pos = state.position;
1870 composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
1871 keyTag = state.tag;
1872 keyNode = state.result;
1873 skipSeparationSpace(state, true, nodeIndent);
1875 ch = state.input.charCodeAt(state.position);
1877 if ((isExplicitPair || state.line === _line) && ch === 0x3A/* : */) {
1879 ch = state.input.charCodeAt(++state.position);
1880 skipSeparationSpace(state, true, nodeIndent);
1881 composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
1882 valueNode = state.result;
1886 …storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _…
1888 …_result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode, _line, _li…
1893 skipSeparationSpace(state, true, nodeIndent);
1895 ch = state.input.charCodeAt(state.position);
1899 ch = state.input.charCodeAt(++state.position);
1905 throwError(state, 'unexpected end of the stream within a flow collection');
1908 function readBlockScalar(state, nodeIndent) { argument
1920 ch = state.input.charCodeAt(state.position);
1930 state.kind = 'scalar';
1931 state.result = '';
1934 ch = state.input.charCodeAt(++state.position);
1940 throwError(state, 'repeat of a chomping mode identifier');
1945 … throwError(state, 'bad explicit indentation width of a block scalar; it cannot be less than one');
1950 throwError(state, 'repeat of an indentation width identifier');
1959 do { ch = state.input.charCodeAt(++state.position); }
1963 do { ch = state.input.charCodeAt(++state.position); }
1969 readLineBreak(state);
1970 state.lineIndent = 0;
1972 ch = state.input.charCodeAt(state.position);
1974 while ((!detectedIndent || state.lineIndent < textIndent) &&
1976 state.lineIndent++;
1977 ch = state.input.charCodeAt(++state.position);
1980 if (!detectedIndent && state.lineIndent > textIndent) {
1981 textIndent = state.lineIndent;
1990 if (state.lineIndent < textIndent) {
1994 state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
1997 state.result += '\n';
2012 state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
2017 state.result += common.repeat('\n', emptyLines + 1);
2022 state.result += ' ';
2027 state.result += common.repeat('\n', emptyLines);
2033 state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
2039 captureStart = state.position;
2042 ch = state.input.charCodeAt(++state.position);
2045 captureSegment(state, captureStart, state.position, false);
2051 function readBlockSequence(state, nodeIndent) { argument
2053 _tag = state.tag,
2054 _anchor = state.anchor,
2062 if (state.firstTabInLine !== -1) return false;
2064 if (state.anchor !== null) {
2065 state.anchorMap[state.anchor] = _result;
2068 ch = state.input.charCodeAt(state.position);
2071 if (state.firstTabInLine !== -1) {
2072 state.position = state.firstTabInLine;
2073 throwError(state, 'tab characters must not be used in indentation');
2080 following = state.input.charCodeAt(state.position + 1);
2087 state.position++;
2089 if (skipSeparationSpace(state, true, -1)) {
2090 if (state.lineIndent <= nodeIndent) {
2092 ch = state.input.charCodeAt(state.position);
2097 _line = state.line;
2098 composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
2099 _result.push(state.result);
2100 skipSeparationSpace(state, true, -1);
2102 ch = state.input.charCodeAt(state.position);
2104 if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) {
2105 throwError(state, 'bad indentation of a sequence entry');
2106 } else if (state.lineIndent < nodeIndent) {
2112 state.tag = _tag;
2113 state.anchor = _anchor;
2114 state.kind = 'sequence';
2115 state.result = _result;
2121 function readBlockMapping(state, nodeIndent, flowIndent) { argument
2128 _tag = state.tag,
2129 _anchor = state.anchor,
2141 if (state.firstTabInLine !== -1) return false;
2143 if (state.anchor !== null) {
2144 state.anchorMap[state.anchor] = _result;
2147 ch = state.input.charCodeAt(state.position);
2150 if (!atExplicitKey && state.firstTabInLine !== -1) {
2151 state.position = state.firstTabInLine;
2152 throwError(state, 'tab characters must not be used in indentation');
2155 following = state.input.charCodeAt(state.position + 1);
2156 _line = state.line; // Save the current line.
2166 …storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, …
2180 …throwError(state, 'incomplete explicit mapping pair; a key node is missed; or followed by a non-ta…
2183 state.position += 1;
2190 _keyLine = state.line;
2191 _keyLineStart = state.lineStart;
2192 _keyPos = state.position;
2194 if (!composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
2200 if (state.line === _line) {
2201 ch = state.input.charCodeAt(state.position);
2204 ch = state.input.charCodeAt(++state.position);
2208 ch = state.input.charCodeAt(++state.position);
2211 …throwError(state, 'a whitespace character is expected after the key-value separator within a block…
2215 …storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, …
2222 keyTag = state.tag;
2223 keyNode = state.result;
2226 throwError(state, 'can not read an implicit mapping pair; a colon is missed');
2229 state.tag = _tag;
2230 state.anchor = _anchor;
2235 …throwError(state, 'can not read a block mapping entry; a multiline key may not be an implicit key'…
2238 state.tag = _tag;
2239 state.anchor = _anchor;
2247 if (state.line === _line || state.lineIndent > nodeIndent) {
2249 _keyLine = state.line;
2250 _keyLineStart = state.lineStart;
2251 _keyPos = state.position;
2254 if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
2256 keyNode = state.result;
2258 valueNode = state.result;
2263 …storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _keyLine, _keyLineSt…
2267 skipSeparationSpace(state, true, -1);
2268 ch = state.input.charCodeAt(state.position);
2271 if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) {
2272 throwError(state, 'bad indentation of a mapping entry');
2273 } else if (state.lineIndent < nodeIndent) {
2284 …storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, …
2289 state.tag = _tag;
2290 state.anchor = _anchor;
2291 state.kind = 'mapping';
2292 state.result = _result;
2298 function readTagProperty(state) { argument
2306 ch = state.input.charCodeAt(state.position);
2310 if (state.tag !== null) {
2311 throwError(state, 'duplication of a tag property');
2314 ch = state.input.charCodeAt(++state.position);
2318 ch = state.input.charCodeAt(++state.position);
2323 ch = state.input.charCodeAt(++state.position);
2329 _position = state.position;
2332 do { ch = state.input.charCodeAt(++state.position); }
2335 if (state.position < state.length) {
2336 tagName = state.input.slice(_position, state.position);
2337 ch = state.input.charCodeAt(++state.position);
2339 throwError(state, 'unexpected end of the stream within a verbatim tag');
2346 tagHandle = state.input.slice(_position - 1, state.position + 1);
2349 throwError(state, 'named tag handle cannot contain such characters');
2353 _position = state.position + 1;
2355 throwError(state, 'tag suffix cannot contain exclamation marks');
2359 ch = state.input.charCodeAt(++state.position);
2362 tagName = state.input.slice(_position, state.position);
2365 throwError(state, 'tag suffix cannot contain flow indicator characters');
2370 throwError(state, 'tag name cannot contain such characters: ' + tagName);
2376 throwError(state, 'tag name is malformed: ' + tagName);
2380 state.tag = tagName;
2382 } else if (_hasOwnProperty$1.call(state.tagMap, tagHandle)) {
2383 state.tag = state.tagMap[tagHandle] + tagName;
2386 state.tag = '!' + tagName;
2389 state.tag = 'tag:yaml.org,2002:' + tagName;
2392 throwError(state, 'undeclared tag handle "' + tagHandle + '"');
2398 function readAnchorProperty(state) { argument
2402 ch = state.input.charCodeAt(state.position);
2406 if (state.anchor !== null) {
2407 throwError(state, 'duplication of an anchor property');
2410 ch = state.input.charCodeAt(++state.position);
2411 _position = state.position;
2414 ch = state.input.charCodeAt(++state.position);
2417 if (state.position === _position) {
2418 throwError(state, 'name of an anchor node must contain at least one character');
2421 state.anchor = state.input.slice(_position, state.position);
2425 function readAlias(state) { argument
2429 ch = state.input.charCodeAt(state.position);
2433 ch = state.input.charCodeAt(++state.position);
2434 _position = state.position;
2437 ch = state.input.charCodeAt(++state.position);
2440 if (state.position === _position) {
2441 throwError(state, 'name of an alias node must contain at least one character');
2444 alias = state.input.slice(_position, state.position);
2446 if (!_hasOwnProperty$1.call(state.anchorMap, alias)) {
2447 throwError(state, 'unidentified alias "' + alias + '"');
2450 state.result = state.anchorMap[alias];
2451 skipSeparationSpace(state, true, -1);
2455 function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) { argument
2469 if (state.listener !== null) {
2470 state.listener('open', state);
2473 state.tag = null;
2474 state.anchor = null;
2475 state.kind = null;
2476 state.result = null;
2483 if (skipSeparationSpace(state, true, -1)) {
2486 if (state.lineIndent > parentIndent) {
2488 } else if (state.lineIndent === parentIndent) {
2490 } else if (state.lineIndent < parentIndent) {
2497 while (readTagProperty(state) || readAnchorProperty(state)) {
2498 if (skipSeparationSpace(state, true, -1)) {
2502 if (state.lineIndent > parentIndent) {
2504 } else if (state.lineIndent === parentIndent) {
2506 } else if (state.lineIndent < parentIndent) {
2526 blockIndent = state.position - state.lineStart;
2530 (readBlockSequence(state, blockIndent) ||
2531 readBlockMapping(state, blockIndent, flowIndent)) ||
2532 readFlowCollection(state, flowIndent)) {
2535 if ((allowBlockScalars && readBlockScalar(state, flowIndent)) ||
2536 readSingleQuotedScalar(state, flowIndent) ||
2537 readDoubleQuotedScalar(state, flowIndent)) {
2540 } else if (readAlias(state)) {
2543 if (state.tag !== null || state.anchor !== null) {
2544 throwError(state, 'alias node should not have any properties');
2547 } else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
2550 if (state.tag === null) {
2551 state.tag = '?';
2555 if (state.anchor !== null) {
2556 state.anchorMap[state.anchor] = state.result;
2562 hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
2566 if (state.tag === null) {
2567 if (state.anchor !== null) {
2568 state.anchorMap[state.anchor] = state.result;
2571 } else if (state.tag === '?') {
2578 if (state.result !== null && state.kind !== 'scalar') {
2579 …throwError(state, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state.kind…
2582 …for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex…
2583 type = state.implicitTypes[typeIndex];
2585 if (type.resolve(state.result)) { // `state.result` updated in resolver if matched
2586 state.result = type.construct(state.result);
2587 state.tag = type.tag;
2588 if (state.anchor !== null) {
2589 state.anchorMap[state.anchor] = state.result;
2594 } else if (state.tag !== '!') {
2595 if (_hasOwnProperty$1.call(state.typeMap[state.kind || 'fallback'], state.tag)) {
2596 type = state.typeMap[state.kind || 'fallback'][state.tag];
2600 typeList = state.typeMap.multi[state.kind || 'fallback'];
2603 if (state.tag.slice(0, typeList[typeIndex].tag.length) === typeList[typeIndex].tag) {
2611 throwError(state, 'unknown tag !<' + state.tag + '>');
2614 if (state.result !== null && type.kind !== state.kind) {
2615 …throwError(state, 'unacceptable node kind for !<' + state.tag + '> tag; it should be "' + type.kin…
2618 if (!type.resolve(state.result, state.tag)) { // `state.result` updated in resolver if matched
2619 throwError(state, 'cannot resolve a node with !<' + state.tag + '> explicit tag');
2621 state.result = type.construct(state.result, state.tag);
2622 if (state.anchor !== null) {
2623 state.anchorMap[state.anchor] = state.result;
2628 if (state.listener !== null) {
2629 state.listener('close', state);
2631 return state.tag !== null || state.anchor !== null || hasContent;
2634 function readDocument(state) { argument
2635 var documentStart = state.position,
2642 state.version = null;
2643 state.checkLineBreaks = state.legacy;
2644 state.tagMap = Object.create(null);
2645 state.anchorMap = Object.create(null);
2647 while ((ch = state.input.charCodeAt(state.position)) !== 0) {
2648 skipSeparationSpace(state, true, -1);
2650 ch = state.input.charCodeAt(state.position);
2652 if (state.lineIndent > 0 || ch !== 0x25/* % */) {
2657 ch = state.input.charCodeAt(++state.position);
2658 _position = state.position;
2661 ch = state.input.charCodeAt(++state.position);
2664 directiveName = state.input.slice(_position, state.position);
2668 throwError(state, 'directive name must not be less than one character in length');
2673 ch = state.input.charCodeAt(++state.position);
2677 do { ch = state.input.charCodeAt(++state.position); }
2684 _position = state.position;
2687 ch = state.input.charCodeAt(++state.position);
2690 directiveArgs.push(state.input.slice(_position, state.position));
2693 if (ch !== 0) readLineBreak(state);
2696 directiveHandlers[directiveName](state, directiveName, directiveArgs);
2698 throwWarning(state, 'unknown document directive "' + directiveName + '"');
2702 skipSeparationSpace(state, true, -1);
2704 if (state.lineIndent === 0 &&
2705 state.input.charCodeAt(state.position) === 0x2D/* - */ &&
2706 state.input.charCodeAt(state.position + 1) === 0x2D/* - */ &&
2707 state.input.charCodeAt(state.position + 2) === 0x2D/* - */) {
2708 state.position += 3;
2709 skipSeparationSpace(state, true, -1);
2712 throwError(state, 'directives end mark is expected');
2715 composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
2716 skipSeparationSpace(state, true, -1);
2718 if (state.checkLineBreaks &&
2719 PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
2720 throwWarning(state, 'non-ASCII line breaks are interpreted as content');
2723 state.documents.push(state.result);
2725 if (state.position === state.lineStart && testDocumentSeparator(state)) {
2727 if (state.input.charCodeAt(state.position) === 0x2E/* . */) {
2728 state.position += 3;
2729 skipSeparationSpace(state, true, -1);
2734 if (state.position < (state.length - 1)) {
2735 throwError(state, 'end of the stream or a document separator is expected');
2760 var state = new State$1(input, options);
2765 state.position = nullpos;
2766 throwError(state, 'null byte is not allowed in input');
2770 state.input += '\0';
2772 while (state.input.charCodeAt(state.position) === 0x20/* Space */) {
2773 state.lineIndent += 1;
2774 state.position += 1;
2777 while (state.position < (state.length - 1)) {
2778 readDocument(state);
2781 return state.documents;
2989 function generateNextLine(state, level) { argument
2990 return '\n' + common.repeat(' ', state.indent * level);
2993 function testImplicitResolving(state, str) { argument
2996 for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
2997 type = state.implicitTypes[index];
3216 function writeScalar(state, string, level, iskey, inblock) { argument
3217 state.dump = (function () {
3219 return state.quotingType === QUOTING_TYPE_DOUBLE ? '""' : "''";
3221 if (!state.noCompatMode) {
3223 … return state.quotingType === QUOTING_TYPE_DOUBLE ? ('"' + string + '"') : ("'" + string + "'");
3227 var indent = state.indent * Math.max(1, level); // no 0-indent scalars
3229 // to the lower bound min(state.lineWidth, 40).
3231 // state.lineWidth ≤ 40 + state.indent: width is fixed at the lower bound.
3232 // state.lineWidth > 40 + state.indent: width decreases until the lower bound.
3235 var lineWidth = state.lineWidth === -1
3236 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
3241 || (state.flowLevel > -1 && level >= state.flowLevel);
3243 return testImplicitResolving(state, string);
3246 switch (chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth,
3247 testAmbiguity, state.quotingType, state.forceQuotes && !iskey, inblock)) {
3254 return '|' + blockHeader(string, state.indent)
3257 return '>' + blockHeader(string, state.indent)
3383 function writeFlowSequence(state, level, object) { argument
3385 _tag = state.tag,
3393 if (state.replacer) {
3394 value = state.replacer.call(object, String(index), value);
3398 if (writeNode(state, level, value, false, false) ||
3400 writeNode(state, level, null, false, false))) {
3402 if (_result !== '') _result += ',' + (!state.condenseFlow ? ' ' : '');
3403 _result += state.dump;
3407 state.tag = _tag;
3408 state.dump = '[' + _result + ']';
3411 function writeBlockSequence(state, level, object, compact) { argument
3413 _tag = state.tag,
3421 if (state.replacer) {
3422 value = state.replacer.call(object, String(index), value);
3426 if (writeNode(state, level + 1, value, true, true, false, true) ||
3428 writeNode(state, level + 1, null, true, true, false, true))) {
3431 _result += generateNextLine(state, level);
3434 if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
3440 _result += state.dump;
3444 state.tag = _tag;
3445 state.dump = _result || '[]'; // Empty sequence if no valid values.
3448 function writeFlowMapping(state, level, object) { argument
3450 _tag = state.tag,
3463 if (state.condenseFlow) pairBuffer += '"';
3468 if (state.replacer) {
3469 objectValue = state.replacer.call(object, objectKey, objectValue);
3472 if (!writeNode(state, level, objectKey, false, false)) {
3476 if (state.dump.length > 1024) pairBuffer += '? ';
3478 …pairBuffer += state.dump + (state.condenseFlow ? '"' : '') + ':' + (state.condenseFlow ? '' : ' ');
3480 if (!writeNode(state, level, objectValue, false, false)) {
3484 pairBuffer += state.dump;
3490 state.tag = _tag;
3491 state.dump = '{' + _result + '}';
3494 function writeBlockMapping(state, level, object, compact) { argument
3496 _tag = state.tag,
3506 if (state.sortKeys === true) {
3509 } else if (typeof state.sortKeys === 'function') {
3511 objectKeyList.sort(state.sortKeys);
3512 } else if (state.sortKeys) {
3521 pairBuffer += generateNextLine(state, level);
3527 if (state.replacer) {
3528 objectValue = state.replacer.call(object, objectKey, objectValue);
3531 if (!writeNode(state, level + 1, objectKey, true, true, true)) {
3535 explicitPair = (state.tag !== null && state.tag !== '?') ||
3536 (state.dump && state.dump.length > 1024);
3539 if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
3546 pairBuffer += state.dump;
3549 pairBuffer += generateNextLine(state, level);
3552 if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
3556 if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
3562 pairBuffer += state.dump;
3568 state.tag = _tag;
3569 state.dump = _result || '{}'; // Empty mapping if no valid pairs.
3572 function detectType(state, object, explicit) { argument
3575 typeList = explicit ? state.explicitTypes : state.implicitTypes;
3586 state.tag = type.representName(object);
3588 state.tag = type.tag;
3591 state.tag = '?';
3595 style = state.styleMap[type.tag] || type.defaultStyle;
3605 state.dump = _result;
3618 function writeNode(state, level, object, block, compact, iskey, isblockseq) { argument
3619 state.tag = null;
3620 state.dump = object;
3622 if (!detectType(state, object, false)) {
3623 detectType(state, object, true);
3626 var type = _toString.call(state.dump);
3631 block = (state.flowLevel < 0 || state.flowLevel > level);
3639 duplicateIndex = state.duplicates.indexOf(object);
3643 if ((state.tag !== null && state.tag !== '?') || duplicate || (state.indent !== 2 && level > 0)) {
3647 if (duplicate && state.usedDuplicates[duplicateIndex]) {
3648 state.dump = '*ref_' + duplicateIndex;
3650 if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
3651 state.usedDuplicates[duplicateIndex] = true;
3654 if (block && (Object.keys(state.dump).length !== 0)) {
3655 writeBlockMapping(state, level, state.dump, compact);
3657 state.dump = '&ref_' + duplicateIndex + state.dump;
3660 writeFlowMapping(state, level, state.dump);
3662 state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
3666 if (block && (state.dump.length !== 0)) {
3667 if (state.noArrayIndent && !isblockseq && level > 0) {
3668 writeBlockSequence(state, level - 1, state.dump, compact);
3670 writeBlockSequence(state, level, state.dump, compact);
3673 state.dump = '&ref_' + duplicateIndex + state.dump;
3676 writeFlowSequence(state, level, state.dump);
3678 state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
3682 if (state.tag !== '?') {
3683 writeScalar(state, state.dump, level, iskey, inblock);
3688 if (state.skipInvalid) return false;
3692 if (state.tag !== null && state.tag !== '?') {
3707 state.tag[0] === '!' ? state.tag.slice(1) : state.tag
3710 if (state.tag[0] === '!') {
3718 state.dump = tagStr + ' ' + state.dump;
3725 function getDuplicateReferences(object, state) { argument
3734 state.duplicates.push(objects[duplicatesIndexes[index]]);
3736 state.usedDuplicates = new Array(length);
3771 var state = new State(options);
3773 if (!state.noRefs) getDuplicateReferences(input, state);
3777 if (state.replacer) {
3778 value = state.replacer.call({ '': value }, '', value);
3781 if (writeNode(state, 0, value, true, true)) return state.dump + '\n';