MCPcopy
hub / github.com/nodeca/js-yaml / readFlowCollection

Function readFlowCollection

src/parser/parser.ts:859–954  ·  view source on GitHub ↗
(state: ParserState, nodeIndent: number, props: NodeProperties)

Source from the content-addressed store, hash-verified

857}
858
859function readFlowCollection (state: ParserState, nodeIndent: number, props: NodeProperties) {
860 const ch = state.input.charCodeAt(state.position)
861 const isMapping = ch === 0x7B/* { */
862 const start = state.position
863 let readNext = true
864
865 if (ch !== 0x5B/* [ */ && ch !== 0x7B/* { */) return false
866
867 const terminator = isMapping ? 0x7D/* } */ : 0x5D/* ] */
868
869 if (isMapping) {
870 addMappingEvent(state, start, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE_FLOW)
871 } else {
872 addSequenceEvent(state, start, props.anchorStart, props.anchorEnd, props.tagStart, props.tagEnd, COLLECTION_STYLE_FLOW)
873 }
874
875 state.position++
876
877 while (state.input.charCodeAt(state.position) !== 0) {
878 skipFlowSeparationSpace(state, nodeIndent)
879
880 let ch = state.input.charCodeAt(state.position)
881
882 if (ch === terminator) {
883 state.position++
884 addPopEvent(state)
885 return true
886 } else if (!readNext) {
887 throwError(state, 'missed comma between flow collection entries')
888 } else if (ch === 0x2C/* , */) {
889 throwError(state, "expected the node content, but found ','")
890 }
891
892 let isPair = false
893 let isExplicitPair = false
894
895 if (ch === 0x3F/* ? */ && isWsOrEol(state.input.charCodeAt(state.position + 1))) {
896 isPair = isExplicitPair = true
897 state.position += 1
898 skipFlowSeparationSpace(state, nodeIndent)
899 }
900
901 const entryLine = state.line
902 const entryStart = snapshotState(state)
903
904 const keyWasRead = parseNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true)
905 skipFlowSeparationSpace(state, nodeIndent)
906
907 ch = state.input.charCodeAt(state.position)
908
909 if ((isMapping || isExplicitPair || state.line === entryLine) && ch === 0x3A/* : */) {
910 isPair = true
911 state.position++
912 skipFlowSeparationSpace(state, nodeIndent)
913 if (!isMapping) {
914 restoreState(state, entryStart)
915 addMappingEvent(state, entryStart.position, NO_RANGE, NO_RANGE, NO_RANGE, NO_RANGE, COLLECTION_STYLE_FLOW)
916 if (!parseNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true)) {

Callers 1

parseNodeFunction · 0.85

Calls 10

addMappingEventFunction · 0.85
addSequenceEventFunction · 0.85
skipFlowSeparationSpaceFunction · 0.85
addPopEventFunction · 0.85
isWsOrEolFunction · 0.85
snapshotStateFunction · 0.85
parseNodeFunction · 0.85
restoreStateFunction · 0.85
addEmptyScalarEventFunction · 0.85
throwErrorFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…