MCPcopy Create free account
hub / github.com/Effect-TS/effect / parse

Method parse

packages/effect/src/encoding/Xml.ts:1550–1607  ·  view source on GitHub ↗
(final: boolean)

Source from the content-addressed store, hash-verified

1548 }
1549
1550 private parse(final: boolean): void {
1551 const s = this.buf
1552 const n = s.length
1553 // Positions of the next "&", CR and "]]>", so that text runs are checked
1554 // without searching past them repeatedly
1555 let nextAmp = -1
1556 let nextCR = -1
1557 let nextCdataEnd = -1
1558 let i = 0
1559 while (i < n) {
1560 if (s.charCodeAt(i) !== LT) {
1561 let j = s.indexOf("<", i)
1562 if (j === -1) {
1563 if (!final) break
1564 j = n
1565 }
1566 if (this.state !== CONTENT) {
1567 this.checkSize(i, j)
1568 this.whitespace(s, i, j)
1569 } else {
1570 this.addText(i, j - i)
1571 if (nextCdataEnd < i) nextCdataEnd = indexOrEnd(s, "]]>", i)
1572 if (nextCdataEnd < j) throw this.syntax("\"]]>\" is not allowed in text", nextCdataEnd)
1573 if (nextAmp < i) nextAmp = indexOrEnd(s, "&", i)
1574 if (nextCR < i) nextCR = indexOrEnd(s, "\r", i)
1575 const raw = s.slice(i, j)
1576 this.text += nextAmp >= j
1577 ? (nextCR >= j ? raw : normalizeLines(raw))
1578 : this.decodeText(raw, i, false, nextCR < j)
1579 }
1580 i = j
1581 continue
1582 }
1583 // Markup is parsed from at most maxTokenSize + 1 characters, so that its
1584 // errors do not depend on how the input is chunked
1585 const long = n - i > this.maxTokenSize
1586 const end = this.markup(long ? s.slice(0, i + this.maxTokenSize + 1) : s, i)
1587 if (end === -1) {
1588 if (long) throw this.tokenLimit(this.base + i)
1589 if (final) throw this.syntax(`unterminated ${describeToken(s, i)}`, i)
1590 break
1591 }
1592 i = end
1593 }
1594 this.count(i)
1595 this.buf = ""
1596 if (i < n) {
1597 const rest = i === 0 ? s : s.slice(i)
1598 this.pending = [rest]
1599 this.pendingStart = this.base + i
1600 this.pendingLength = rest.length
1601 this.pendingAdded = 0
1602 // Brings the scanner to the end of the incomplete token
1603 this.scanner.reset(S_START)
1604 this.scanner.scan(rest, 0)
1605 this.checkPending()
1606 }
1607 }

Callers 15

endMethod · 0.95
consumeMethod · 0.95
parseFunction · 0.45
parseLineFunction · 0.45
unquoteFunction · 0.45
parseFunction · 0.45
failFunction · 0.45
parseUnsafeFunction · 0.45
scanMethod · 0.45
scanElementsMethod · 0.45
decodeValueUncheckedFunction · 0.45
decodePayloadFunction · 0.45

Calls 15

checkSizeMethod · 0.95
whitespaceMethod · 0.95
addTextMethod · 0.95
syntaxMethod · 0.95
decodeTextMethod · 0.95
markupMethod · 0.95
tokenLimitMethod · 0.95
countMethod · 0.95
checkPendingMethod · 0.95
indexOrEndFunction · 0.85
normalizeLinesFunction · 0.85
sliceMethod · 0.80

Tested by

no test coverage detected