Brunobkr/llama.cpp_AlgMor24_github
ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.
03.1k
1'use strict'2 3const common = require('./common')4const YAMLException = require('./exception')5const makeSnippet = require('./snippet')6const DEFAULT_SCHEMA = require('./schema/default')7 8const _hasOwnProperty = Object.prototype.hasOwnProperty9 10const CONTEXT_FLOW_IN = 111const CONTEXT_FLOW_OUT = 212const CONTEXT_BLOCK_IN = 313const CONTEXT_BLOCK_OUT = 414 15const CHOMPING_CLIP = 116const CHOMPING_STRIP = 217const CHOMPING_KEEP = 318 19// eslint-disable-next-line no-control-regex20const PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/21const PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/22// eslint-disable-next-line no-useless-escape23const PATTERN_FLOW_INDICATORS = /[,\[\]{}]/24// eslint-disable-next-line no-useless-escape25const PATTERN_TAG_HANDLE = /^(?:!|!!|![0-9A-Za-z-]+!)$/26// eslint-disable-next-line no-useless-escape27const PATTERN_TAG_URI = /^(?:!|[^,\[\]{}])(?:%[0-9a-f]{2}|[0-9a-z\-#;/?:@&=+$,_.!~*'()\[\]])*$/i28 29function _class (obj) { return Object.prototype.toString.call(obj) }30 31function isEol (c) {32 return (c === 0x0A/* LF */) || (c === 0x0D/* CR */)33}34 35function isWhiteSpace (c) {36 return (c === 0x09/* Tab */) || (c === 0x20/* Space */)37}38 39function isWsOrEol (c) {40 return (c === 0x09/* Tab */) ||41 (c === 0x20/* Space */) ||42 (c === 0x0A/* LF */) ||43 (c === 0x0D/* CR */)44}45 46function isFlowIndicator (c) {47 return c === 0x2C/* , */ ||48 c === 0x5B/* [ */ ||49 c === 0x5D/* ] */ ||50 c === 0x7B/* { */ ||51 c === 0x7D/* } */52}53 54function fromHexCode (c) {55 if ((c >= 0x30/* 0 */) && (c <= 0x39/* 9 */)) {56 return c - 0x3057 }58 59 const lc = c | 0x2060 61 if ((lc >= 0x61/* a */) && (lc <= 0x66/* f */)) {62 return lc - 0x61 + 1063 }64 65 return -166}67 68function escapedHexLen (c) {69 if (c === 0x78/* x */) { return 2 }70 if (c === 0x75/* u */) { return 4 }71 if (c === 0x55/* U */) { return 8 }72 return 073}74 75function fromDecimalCode (c) {76 if ((c >= 0x30/* 0 */) && (c <= 0x39/* 9 */)) {77 return c - 0x3078 }79 80 return -181}82 83function simpleEscapeSequence (c) {84 switch (c) {85 case 0x30/* 0 */: return '\x00'86 case 0x61/* a */: return '\x07'87 case 0x62/* b */: return '\x08'88 case 0x74/* t */: return '\x09'89 case 0x09/* Tab */: return '\x09'90 case 0x6E/* n */: return '\x0A'91 case 0x76/* v */: return '\x0B'92 case 0x66/* f */: return '\x0C'93 case 0x72/* r */: return '\x0D'94 case 0x65/* e */: return '\x1B'95 case 0x20/* Space */: return ' '96 case 0x22/* " */: return '\x22'97 case 0x2F/* / */: return '/'98 case 0x5C/* \ */: return '\x5C'99 case 0x4E/* N */: return '\x85'100 case 0x5F/* _ */: return '\xA0'101 case 0x4C/* L */: return '\u2028'102 case 0x50/* P */: return '\u2029'103 default: return ''104 }105}106 107function charFromCodepoint (c) {108 if (c <= 0xFFFF) {109 return String.fromCharCode(c)110 }111 // Encode UTF-16 surrogate pair112 // https://en.wikipedia.org/wiki/UTF-16#Code_points_U.2B010000_to_U.2B10FFFF113 return String.fromCharCode(114 ((c - 0x010000) >> 10) + 0xD800,115 ((c - 0x010000) & 0x03FF) + 0xDC00116 )117}118 119// set a property of a literal object, while protecting against prototype pollution,120// see https://github.com/nodeca/js-yaml/issues/164 for more details121function setProperty (object, key, value) {122 // used for this specific key only because Object.defineProperty is slow123 if (key === '__proto__') {124 Object.defineProperty(object, key, {125 configurable: true,126 enumerable: true,127 writable: true,128 value: value129 })130 } else {131 object[key] = value132 }133}134 135const simpleEscapeCheck = new Array(256) // integer, for fast access136const simpleEscapeMap = new Array(256)137for (let i = 0; i < 256; i++) {138 simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0139 simpleEscapeMap[i] = simpleEscapeSequence(i)140}141 142function State (input, options) {143 this.input = input144 145 this.filename = options['filename'] || null146 this.schema = options['schema'] || DEFAULT_SCHEMA147 this.onWarning = options['onWarning'] || null148 // (Hidden) Remove? makes the loader to expect YAML 1.1 documents149 // if such documents have no explicit %YAML directive150 this.legacy = options['legacy'] || false151 152 this.json = options['json'] || false153 this.listener = options['listener'] || null154 this.maxDepth = typeof options['maxDepth'] === 'number' ? options['maxDepth'] : 100155 this.maxTotalMergeKeys = typeof options['maxTotalMergeKeys'] === 'number' ? options['maxTotalMergeKeys'] : 10000156 157 this.implicitTypes = this.schema.compiledImplicit158 this.typeMap = this.schema.compiledTypeMap159 160 this.length = input.length161 this.position = 0162 this.line = 0163 this.lineStart = 0164 this.lineIndent = 0165 this.depth = 0166 this.totalMergeKeys = 0167 168 // position of first leading tab in the current line,169 // used to make sure there are no tabs in the indentation170 this.firstTabInLine = -1171 172 this.documents = []173 this.anchorMapTransactions = []174 175 /*176 this.version;177 this.checkLineBreaks;178 this.tagMap;179 this.anchorMap;180 this.tag;181 this.anchor;182 this.kind;183 this.result; */184}185 186function generateError (state, message) {187 const mark = {188 name: state.filename,189 buffer: state.input.slice(0, -1), // omit trailing \0190 position: state.position,191 line: state.line,192 column: state.position - state.lineStart193 }194 195 mark.snippet = makeSnippet(mark)196 197 return new YAMLException(message, mark)198}199 200function throwError (state, message) {201 throw generateError(state, message)202}203 204function throwWarning (state, message) {205 if (state.onWarning) {206 state.onWarning.call(null, generateError(state, message))207 }208}209 210function storeAnchor (state, name, value) {211 const transactions = state.anchorMapTransactions212 213 if (transactions.length !== 0) {214 const transaction = transactions[transactions.length - 1]215 216 if (!_hasOwnProperty.call(transaction, name)) {217 transaction[name] = {218 existed: _hasOwnProperty.call(state.anchorMap, name),219 value: state.anchorMap[name]220 }221 }222 }223 224 state.anchorMap[name] = value225}226 227function beginAnchorTransaction (state) {228 state.anchorMapTransactions.push(Object.create(null))229}230 231function commitAnchorTransaction (state) {232 const transaction = state.anchorMapTransactions.pop()233 const transactions = state.anchorMapTransactions234 235 if (transactions.length === 0) return236 237 const parent = transactions[transactions.length - 1]238 const names = Object.keys(transaction)239 240 for (let index = 0, length = names.length; index < length; index += 1) {241 const name = names[index]242 243 if (!_hasOwnProperty.call(parent, name)) {244 parent[name] = transaction[name]245 }246 }247}248 249function rollbackAnchorTransaction (state) {250 const transaction = state.anchorMapTransactions.pop()251 const names = Object.keys(transaction)252 253 for (let index = names.length - 1; index >= 0; index -= 1) {254 const entry = transaction[names[index]]255 256 if (entry.existed) {257 state.anchorMap[names[index]] = entry.value258 } else {259 delete state.anchorMap[names[index]]260 }261 }262}263 264function snapshotState (state) {265 return {266 position: state.position,267 line: state.line,268 lineStart: state.lineStart,269 lineIndent: state.lineIndent,270 firstTabInLine: state.firstTabInLine,271 tag: state.tag,272 anchor: state.anchor,273 kind: state.kind,274 result: state.result275 }276}277 278function restoreState (state, snapshot) {279 state.position = snapshot.position280 state.line = snapshot.line281 state.lineStart = snapshot.lineStart282 state.lineIndent = snapshot.lineIndent283 state.firstTabInLine = snapshot.firstTabInLine284 state.tag = snapshot.tag285 state.anchor = snapshot.anchor286 state.kind = snapshot.kind287 state.result = snapshot.result288}289 290const directiveHandlers = {291 292 YAML: function handleYamlDirective (state, name, args) {293 if (state.version !== null) {294 throwError(state, 'duplication of %YAML directive')295 }296 297 if (args.length !== 1) {298 throwError(state, 'YAML directive accepts exactly one argument')299 }300 301 const match = /^([0-9]+)\.([0-9]+)$/.exec(args[0])302 303 if (match === null) {304 throwError(state, 'ill-formed argument of the YAML directive')305 }306 307 const major = parseInt(match[1], 10)308 const minor = parseInt(match[2], 10)309 310 if (major !== 1) {311 throwError(state, 'unacceptable YAML version of the document')312 }313 314 state.version = args[0]315 state.checkLineBreaks = (minor < 2)316 317 if (minor !== 1 && minor !== 2) {318 throwWarning(state, 'unsupported YAML version of the document')319 }320 },321 322 TAG: function handleTagDirective (state, name, args) {323 let prefix324 325 if (args.length !== 2) {326 throwError(state, 'TAG directive accepts exactly two arguments')327 }328 329 const handle = args[0]330 prefix = args[1]331 332 if (!PATTERN_TAG_HANDLE.test(handle)) {333 throwError(state, 'ill-formed tag handle (first argument) of the TAG directive')334 }335 336 if (_hasOwnProperty.call(state.tagMap, handle)) {337 throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle')338 }339 340 if (!PATTERN_TAG_URI.test(prefix)) {341 throwError(state, 'ill-formed tag prefix (second argument) of the TAG directive')342 }343 344 try {345 prefix = decodeURIComponent(prefix)346 } catch (err) {347 throwError(state, 'tag prefix is malformed: ' + prefix)348 }349 350 state.tagMap[handle] = prefix351 }352}353 354function captureSegment (state, start, end, checkJson) {355 if (start < end) {356 const _result = state.input.slice(start, end)357 358 if (checkJson) {359 for (let _position = 0, _length = _result.length; _position < _length; _position += 1) {360 const _character = _result.charCodeAt(_position)361 if (!(_character === 0x09 ||362 (_character >= 0x20 && _character <= 0x10FFFF))) {363 throwError(state, 'expected valid JSON character')364 }365 }366 } else if (PATTERN_NON_PRINTABLE.test(_result)) {367 throwError(state, 'the stream contains non-printable characters')368 }369 370 state.result += _result371 }372}373 374function mergeMappings (state, destination, source, overridableKeys) {375 if (!common.isObject(source)) {376 throwError(state, 'cannot merge mappings; the provided source object is unacceptable')377 }378 379 const sourceKeys = Object.keys(source)380 381 for (let index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {382 const key = sourceKeys[index]383 384 if (state.maxTotalMergeKeys !== -1 && ++state.totalMergeKeys > state.maxTotalMergeKeys) {385 throwError(state, 'merge keys exceeded maxTotalMergeKeys (' + state.maxTotalMergeKeys + ')')386 }387 388 if (!_hasOwnProperty.call(destination, key)) {389 setProperty(destination, key, source[key])390 overridableKeys[key] = true391 }392 }393}394 395function storeMappingPair (state, _result, overridableKeys, keyTag, keyNode, valueNode,396 startLine, startLineStart, startPos) {397 // The output is a plain object here, so keys can only be strings.398 // We need to convert keyNode to a string, but doing so can hang the process399 // (deeply nested arrays that explode exponentially using aliases).400 if (Array.isArray(keyNode)) {401 keyNode = Array.prototype.slice.call(keyNode)402 403 for (let index = 0, quantity = keyNode.length; index < quantity; index += 1) {404 if (Array.isArray(keyNode[index])) {405 throwError(state, 'nested arrays are not supported inside keys')406 }407 408 if (typeof keyNode === 'object' && _class(keyNode[index]) === '[object Object]') {409 keyNode[index] = '[object Object]'410 }411 }412 }413 414 // Avoid code execution in load() via toString property415 // (still use its own toString for arrays, timestamps,416 // and whatever user schema extensions happen to have @@toStringTag)417 if (typeof keyNode === 'object' && _class(keyNode) === '[object Object]') {418 keyNode = '[object Object]'419 }420 421 keyNode = String(keyNode)422 423 if (_result === null) {424 _result = {}425 }426 427 if (keyTag === 'tag:yaml.org,2002:merge') {428 if (Array.isArray(valueNode)) {429 for (let index = 0, quantity = valueNode.length; index < quantity; index += 1) {430 mergeMappings(state, _result, valueNode[index], overridableKeys)431 }432 } else {433 mergeMappings(state, _result, valueNode, overridableKeys)434 }435 } else {436 if (!state.json &&437 !_hasOwnProperty.call(overridableKeys, keyNode) &&438 _hasOwnProperty.call(_result, keyNode)) {439 state.line = startLine || state.line440 state.lineStart = startLineStart || state.lineStart441 state.position = startPos || state.position442 throwError(state, 'duplicated mapping key')443 }444 445 setProperty(_result, keyNode, valueNode)446 delete overridableKeys[keyNode]447 }448 449 return _result450}451 452function readLineBreak (state) {453 const ch = state.input.charCodeAt(state.position)454 455 if (ch === 0x0A/* LF */) {456 state.position++457 } else if (ch === 0x0D/* CR */) {458 state.position++459 if (state.input.charCodeAt(state.position) === 0x0A/* LF */) {460 state.position++461 }462 } else {463 throwError(state, 'a line break is expected')464 }465 466 state.line += 1467 state.lineStart = state.position468 state.firstTabInLine = -1469}470 471function skipSeparationSpace (state, allowComments, checkIndent) {472 let lineBreaks = 0473 let ch = state.input.charCodeAt(state.position)474 475 while (ch !== 0) {476 while (isWhiteSpace(ch)) {477 if (ch === 0x09/* Tab */ && state.firstTabInLine === -1) {478 state.firstTabInLine = state.position479 }480 ch = state.input.charCodeAt(++state.position)481 }482 483 if (allowComments && ch === 0x23/* # */) {484 do {485 ch = state.input.charCodeAt(++state.position)486 } while (ch !== 0x0A/* LF */ && ch !== 0x0D/* CR */ && ch !== 0)487 }488 489 if (isEol(ch)) {490 readLineBreak(state)491 492 ch = state.input.charCodeAt(state.position)493 lineBreaks++494 state.lineIndent = 0495 496 while (ch === 0x20/* Space */) {497 state.lineIndent++498 ch = state.input.charCodeAt(++state.position)499 }500 } else {501 break502 }503 }504 505 if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {506 throwWarning(state, 'deficient indentation')507 }508 509 return lineBreaks510}511 512function testDocumentSeparator (state) {513 let _position = state.position514 let ch = state.input.charCodeAt(_position)515 516 // Condition state.position === state.lineStart is tested517 // in parent on each call, for efficiency. No needs to test here again.518 if ((ch === 0x2D/* - */ || ch === 0x2E/* . */) &&519 ch === state.input.charCodeAt(_position + 1) &&520 ch === state.input.charCodeAt(_position + 2)) {521 _position += 3522 523 ch = state.input.charCodeAt(_position)524 525 if (ch === 0 || isWsOrEol(ch)) {526 return true527 }528 }529 530 return false531}532 533function writeFoldedLines (state, count) {534 if (count === 1) {535 state.result += ' '536 } else if (count > 1) {537 state.result += common.repeat('\n', count - 1)538 }539}540 541function readPlainScalar (state, nodeIndent, withinFlowCollection) {542 let captureStart543 let captureEnd544 let hasPendingContent545 let _line546 let _lineStart547 let _lineIndent548 const _kind = state.kind549 const _result = state.result550 551 let ch = state.input.charCodeAt(state.position)552 553 if (isWsOrEol(ch) ||554 isFlowIndicator(ch) ||555 ch === 0x23/* # */ ||556 ch === 0x26/* & */ ||557 ch === 0x2A/* * */ ||558 ch === 0x21/* ! */ ||559 ch === 0x7C/* | */ ||560 ch === 0x3E/* > */ ||561 ch === 0x27/* ' */ ||562 ch === 0x22/* " */ ||563 ch === 0x25/* % */ ||564 ch === 0x40/* @ */ ||565 ch === 0x60/* ` */) {566 return false567 }568 569 if (ch === 0x3F/* ? */ || ch === 0x2D/* - */) {570 const following = state.input.charCodeAt(state.position + 1)571 572 if (isWsOrEol(following) ||573 (withinFlowCollection && isFlowIndicator(following))) {574 return false575 }576 }577 578 state.kind = 'scalar'579 state.result = ''580 captureStart = captureEnd = state.position581 hasPendingContent = false582 583 while (ch !== 0) {584 if (ch === 0x3A/* : */) {585 const following = state.input.charCodeAt(state.position + 1)586 587 if (isWsOrEol(following) ||588 (withinFlowCollection && isFlowIndicator(following))) {589 break590 }591 } else if (ch === 0x23/* # */) {592 const preceding = state.input.charCodeAt(state.position - 1)593 594 if (isWsOrEol(preceding)) {595 break596 }597 } else if ((state.position === state.lineStart && testDocumentSeparator(state)) ||598 (withinFlowCollection && isFlowIndicator(ch))) {599 break600 } else if (isEol(ch)) {601 _line = state.line602 _lineStart = state.lineStart603 _lineIndent = state.lineIndent604 skipSeparationSpace(state, false, -1)605 606 if (state.lineIndent >= nodeIndent) {607 hasPendingContent = true608 ch = state.input.charCodeAt(state.position)609 continue610 } else {611 state.position = captureEnd612 state.line = _line613 state.lineStart = _lineStart614 state.lineIndent = _lineIndent615 break616 }617 }618 619 if (hasPendingContent) {620 captureSegment(state, captureStart, captureEnd, false)621 writeFoldedLines(state, state.line - _line)622 captureStart = captureEnd = state.position623 hasPendingContent = false624 }625 626 if (!isWhiteSpace(ch)) {627 captureEnd = state.position + 1628 }629 630 ch = state.input.charCodeAt(++state.position)631 }632 633 captureSegment(state, captureStart, captureEnd, false)634 635 if (state.result) {636 return true637 }638 639 state.kind = _kind640 state.result = _result641 return false642}643 644function readSingleQuotedScalar (state, nodeIndent) {645 let captureStart646 let captureEnd647 648 let ch = state.input.charCodeAt(state.position)649 650 if (ch !== 0x27/* ' */) {651 return false652 }653 654 state.kind = 'scalar'655 state.result = ''656 state.position++657 captureStart = captureEnd = state.position658 659 while ((ch = state.input.charCodeAt(state.position)) !== 0) {660 if (ch === 0x27/* ' */) {661 captureSegment(state, captureStart, state.position, true)662 ch = state.input.charCodeAt(++state.position)663 664 if (ch === 0x27/* ' */) {665 captureStart = state.position666 state.position++667 captureEnd = state.position668 } else {669 return true670 }671 } else if (isEol(ch)) {672 captureSegment(state, captureStart, captureEnd, true)673 writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent))674 captureStart = captureEnd = state.position675 } else if (state.position === state.lineStart && testDocumentSeparator(state)) {676 throwError(state, 'unexpected end of the document within a single quoted scalar')677 } else {678 state.position++679 if (!isWhiteSpace(ch)) {680 captureEnd = state.position681 }682 }683 }684 685 throwError(state, 'unexpected end of the stream within a single quoted scalar')686}687 688function readDoubleQuotedScalar (state, nodeIndent) {689 let captureStart690 let captureEnd691 let tmp692 693 let ch = state.input.charCodeAt(state.position)694 695 if (ch !== 0x22/* " */) {696 return false697 }698 699 state.kind = 'scalar'700 state.result = ''701 state.position++702 captureStart = captureEnd = state.position703 704 while ((ch = state.input.charCodeAt(state.position)) !== 0) {705 if (ch === 0x22/* " */) {706 captureSegment(state, captureStart, state.position, true)707 state.position++708 return true709 } else if (ch === 0x5C/* \ */) {710 captureSegment(state, captureStart, state.position, true)711 ch = state.input.charCodeAt(++state.position)712 713 if (isEol(ch)) {714 skipSeparationSpace(state, false, nodeIndent)715 716 // TODO: rework to inline fn with no type cast?717 } else if (ch < 256 && simpleEscapeCheck[ch]) {718 state.result += simpleEscapeMap[ch]719 state.position++720 } else if ((tmp = escapedHexLen(ch)) > 0) {721 let hexLength = tmp722 let hexResult = 0723 724 for (; hexLength > 0; hexLength--) {725 ch = state.input.charCodeAt(++state.position)726 727 if ((tmp = fromHexCode(ch)) >= 0) {728 hexResult = (hexResult << 4) + tmp729 } else {730 throwError(state, 'expected hexadecimal character')731 }732 }733 734 state.result += charFromCodepoint(hexResult)735 736 state.position++737 } else {738 throwError(state, 'unknown escape sequence')739 }740 741 captureStart = captureEnd = state.position742 } else if (isEol(ch)) {743 captureSegment(state, captureStart, captureEnd, true)744 writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent))745 captureStart = captureEnd = state.position746 } else if (state.position === state.lineStart && testDocumentSeparator(state)) {747 throwError(state, 'unexpected end of the document within a double quoted scalar')748 } else {749 state.position++750 if (!isWhiteSpace(ch)) {751 captureEnd = state.position752 }753 }754 }755 756 throwError(state, 'unexpected end of the stream within a double quoted scalar')757}758 759function readFlowCollection (state, nodeIndent) {760 let readNext = true761 let _line762 let _lineStart763 let _pos764 const _tag = state.tag765 let _result766 const _anchor = state.anchor767 let terminator768 let isPair769 let isExplicitPair770 let isMapping771 const overridableKeys = Object.create(null)772 let keyNode773 let keyTag774 let valueNode775 776 let ch = state.input.charCodeAt(state.position)777 778 if (ch === 0x5B/* [ */) {779 terminator = 0x5D/* ] */780 isMapping = false781 _result = []782 } else if (ch === 0x7B/* { */) {783 terminator = 0x7D/* } */784 isMapping = true785 _result = {}786 } else {787 return false788 }789 790 if (state.anchor !== null) {791 storeAnchor(state, state.anchor, _result)792 }793 794 ch = state.input.charCodeAt(++state.position)795 796 while (ch !== 0) {797 skipSeparationSpace(state, true, nodeIndent)798 799 ch = state.input.charCodeAt(state.position)800 801 if (ch === terminator) {802 state.position++803 state.tag = _tag804 state.anchor = _anchor805 state.kind = isMapping ? 'mapping' : 'sequence'806 state.result = _result807 return true808 } else if (!readNext) {809 throwError(state, 'missed comma between flow collection entries')810 } else if (ch === 0x2C/* , */) {811 // "flow collection entries can never be completely empty", as per YAML 1.2, section 7.4812 throwError(state, "expected the node content, but found ','")813 }814 815 keyTag = keyNode = valueNode = null816 isPair = isExplicitPair = false817 818 if (ch === 0x3F/* ? */) {819 const following = state.input.charCodeAt(state.position + 1)820 821 if (isWsOrEol(following)) {822 isPair = isExplicitPair = true823 state.position++824 skipSeparationSpace(state, true, nodeIndent)825 }826 }827 828 _line = state.line // Save the current line.829 _lineStart = state.lineStart830 _pos = state.position831 composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true)832 keyTag = state.tag833 keyNode = state.result834 skipSeparationSpace(state, true, nodeIndent)835 836 ch = state.input.charCodeAt(state.position)837 838 if ((isExplicitPair || state.line === _line) && ch === 0x3A/* : */) {839 isPair = true840 ch = state.input.charCodeAt(++state.position)841 skipSeparationSpace(state, true, nodeIndent)842 composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true)843 valueNode = state.result844 }845 846 if (isMapping) {847 storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos)848 } else if (isPair) {849 _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos))850 } else {851 _result.push(keyNode)852 }853 854 skipSeparationSpace(state, true, nodeIndent)855 856 ch = state.input.charCodeAt(state.position)857 858 if (ch === 0x2C/* , */) {859 readNext = true860 ch = state.input.charCodeAt(++state.position)861 } else {862 readNext = false863 }864 }865 866 throwError(state, 'unexpected end of the stream within a flow collection')867}868 869function readBlockScalar (state, nodeIndent) {870 let folding871 let chomping = CHOMPING_CLIP872 let didReadContent = false873 let detectedIndent = false874 let textIndent = nodeIndent875 let emptyLines = 0876 let atMoreIndented = false877 let tmp878 879 let ch = state.input.charCodeAt(state.position)880 881 if (ch === 0x7C/* | */) {882 folding = false883 } else if (ch === 0x3E/* > */) {884 folding = true885 } else {886 return false887 }888 889 state.kind = 'scalar'890 state.result = ''891 892 while (ch !== 0) {893 ch = state.input.charCodeAt(++state.position)894 895 if (ch === 0x2B/* + */ || ch === 0x2D/* - */) {896 if (CHOMPING_CLIP === chomping) {897 chomping = (ch === 0x2B/* + */) ? CHOMPING_KEEP : CHOMPING_STRIP898 } else {899 throwError(state, 'repeat of a chomping mode identifier')900 }901 } else if ((tmp = fromDecimalCode(ch)) >= 0) {902 if (tmp === 0) {903 throwError(state, 'bad explicit indentation width of a block scalar; it cannot be less than one')904 } else if (!detectedIndent) {905 textIndent = nodeIndent + tmp - 1906 detectedIndent = true907 } else {908 throwError(state, 'repeat of an indentation width identifier')909 }910 } else {911 break912 }913 }914 915 if (isWhiteSpace(ch)) {916 do { ch = state.input.charCodeAt(++state.position) }917 while (isWhiteSpace(ch))918 919 if (ch === 0x23/* # */) {920 do { ch = state.input.charCodeAt(++state.position) }921 while (!isEol(ch) && (ch !== 0))922 }923 }924 925 while (ch !== 0) {926 readLineBreak(state)927 state.lineIndent = 0928 929 ch = state.input.charCodeAt(state.position)930 931 // eslint-disable-next-line no-unmodified-loop-condition932 while ((!detectedIndent || state.lineIndent < textIndent) &&933 (ch === 0x20/* Space */)) {934 state.lineIndent++935 ch = state.input.charCodeAt(++state.position)936 }937 938 if (!detectedIndent && state.lineIndent > textIndent) {939 textIndent = state.lineIndent940 }941 942 if (isEol(ch)) {943 emptyLines++944 continue945 }946 947 if (!detectedIndent && textIndent === 0) {948 throwError(state, 'missing indentation for block scalar')949 }950 951 // End of the scalar.952 if (state.lineIndent < textIndent) {953 // Perform the chomping.954 if (chomping === CHOMPING_KEEP) {955 state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines)956 } else if (chomping === CHOMPING_CLIP) {957 if (didReadContent) { // i.e. only if the scalar is not empty.958 state.result += '\n'959 }960 }961 962 // Break this `while` cycle and go to the funciton's epilogue.963 break964 }965 966 // Folded style: use fancy rules to handle line breaks.967 if (folding) {968 // Lines starting with white space characters (more-indented lines) are not folded.969 if (isWhiteSpace(ch)) {970 atMoreIndented = true971 // except for the first content line (cf. Example 8.1)972 state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines)973 974 // End of more-indented block.975 } else if (atMoreIndented) {976 atMoreIndented = false977 state.result += common.repeat('\n', emptyLines + 1)978 979 // Just one line break - perceive as the same line.980 } else if (emptyLines === 0) {981 if (didReadContent) { // i.e. only if we have already read some scalar content.982 state.result += ' '983 }984 985 // Several line breaks - perceive as different lines.986 } else {987 state.result += common.repeat('\n', emptyLines)988 }989 990 // Literal style: just add exact number of line breaks between content lines.991 } else {992 // Keep all line breaks except the header line break.993 state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines)994 }995 996 didReadContent = true997 detectedIndent = true998 emptyLines = 0999 const captureStart = state.position1000 1001 while (!isEol(ch) && (ch !== 0)) {1002 ch = state.input.charCodeAt(++state.position)1003 }1004 1005 captureSegment(state, captureStart, state.position, false)1006 }1007 1008 return true1009}1010 1011function readBlockSequence (state, nodeIndent) {1012 const _tag = state.tag1013 const _anchor = state.anchor1014 const _result = []1015 let detected = false1016 1017 // there is a leading tab before this token, so it can't be a block sequence/mapping;1018 // it can still be flow sequence/mapping or a scalar1019 if (state.firstTabInLine !== -1) return false1020 1021 if (state.anchor !== null) {1022 storeAnchor(state, state.anchor, _result)1023 }1024 1025 let ch = state.input.charCodeAt(state.position)1026 1027 while (ch !== 0) {1028 if (state.firstTabInLine !== -1) {1029 state.position = state.firstTabInLine1030 throwError(state, 'tab characters must not be used in indentation')1031 }1032 1033 if (ch !== 0x2D/* - */) {1034 break1035 }1036 1037 const following = state.input.charCodeAt(state.position + 1)1038 1039 if (!isWsOrEol(following)) {1040 break1041 }1042 1043 detected = true1044 state.position++1045 1046 if (skipSeparationSpace(state, true, -1)) {1047 if (state.lineIndent <= nodeIndent) {1048 _result.push(null)1049 ch = state.input.charCodeAt(state.position)1050 continue1051 }1052 }1053 1054 const _line = state.line1055 composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true)1056 _result.push(state.result)1057 skipSeparationSpace(state, true, -1)1058 1059 ch = state.input.charCodeAt(state.position)1060 1061 if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) {1062 throwError(state, 'bad indentation of a sequence entry')1063 } else if (state.lineIndent < nodeIndent) {1064 break1065 }1066 }1067 1068 if (detected) {1069 state.tag = _tag1070 state.anchor = _anchor1071 state.kind = 'sequence'1072 state.result = _result1073 return true1074 }1075 return false1076}1077 1078function readBlockMapping (state, nodeIndent, flowIndent) {1079 let allowCompact1080 let _keyLine1081 let _keyLineStart1082 let _keyPos1083 const _tag = state.tag1084 const _anchor = state.anchor1085 const _result = {}1086 const overridableKeys = Object.create(null)1087 let keyTag = null1088 let keyNode = null1089 let valueNode = null1090 let atExplicitKey = false1091 let detected = false1092 1093 // there is a leading tab before this token, so it can't be a block sequence/mapping;1094 // it can still be flow sequence/mapping or a scalar1095 if (state.firstTabInLine !== -1) return false1096 1097 if (state.anchor !== null) {1098 storeAnchor(state, state.anchor, _result)1099 }1100 1101 let ch = state.input.charCodeAt(state.position)1102 1103 while (ch !== 0) {1104 if (!atExplicitKey && state.firstTabInLine !== -1) {1105 state.position = state.firstTabInLine1106 throwError(state, 'tab characters must not be used in indentation')1107 }1108 1109 const following = state.input.charCodeAt(state.position + 1)1110 const _line = state.line // Save the current line.1111 1112 //1113 // Explicit notation case. There are two separate blocks:1114 // first for the key (denoted by "?") and second for the value (denoted by ":")1115 //1116 if ((ch === 0x3F/* ? */ || ch === 0x3A/* : */) && isWsOrEol(following)) {1117 if (ch === 0x3F/* ? */) {1118 if (atExplicitKey) {1119 storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos)1120 keyTag = keyNode = valueNode = null1121 }1122 1123 detected = true1124 atExplicitKey = true1125 allowCompact = true1126 } else if (atExplicitKey) {1127 // i.e. 0x3A/* : */ === character after the explicit key.1128 atExplicitKey = false1129 allowCompact = true1130 } else {1131 throwError(state, 'incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line')1132 }1133 1134 state.position += 11135 ch = following1136 1137 //1138 // Implicit notation case. Flow-style node as the key first, then ":", and the value.1139 //1140 } else {1141 _keyLine = state.line1142 _keyLineStart = state.lineStart1143 _keyPos = state.position1144 1145 if (!composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {1146 // Neither implicit nor explicit notation.1147 // Reading is done. Go to the epilogue.1148 break1149 }1150 1151 if (state.line === _line) {1152 ch = state.input.charCodeAt(state.position)1153 1154 while (isWhiteSpace(ch)) {1155 ch = state.input.charCodeAt(++state.position)1156 }1157 1158 if (ch === 0x3A/* : */) {1159 ch = state.input.charCodeAt(++state.position)1160 1161 if (!isWsOrEol(ch)) {1162 throwError(state, 'a whitespace character is expected after the key-value separator within a block mapping')1163 }1164 1165 if (atExplicitKey) {1166 storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos)1167 keyTag = keyNode = valueNode = null1168 }1169 1170 detected = true1171 atExplicitKey = false1172 allowCompact = false1173 keyTag = state.tag1174 keyNode = state.result1175 } else if (detected) {1176 throwError(state, 'can not read an implicit mapping pair; a colon is missed')1177 } else {1178 state.tag = _tag1179 state.anchor = _anchor1180 return true // Keep the result of `composeNode`.1181 }1182 } else if (detected) {1183 throwError(state, 'can not read a block mapping entry; a multiline key may not be an implicit key')1184 } else {1185 state.tag = _tag1186 state.anchor = _anchor1187 return true // Keep the result of `composeNode`.1188 }1189 }1190 1191 //1192 // Common reading code for both explicit and implicit notations.1193 //1194 if (state.line === _line || state.lineIndent > nodeIndent) {1195 if (atExplicitKey) {1196 _keyLine = state.line1197 _keyLineStart = state.lineStart1198 _keyPos = state.position1199 }1200 