MCPcopy Create free account
hub / github.com/Noumena-Network/code / findIfBlocks

Function findIfBlocks

scripts/generate_slash_command_appendix.mjs:532–551  ·  view source on GitHub ↗
(source)

Source from the content-addressed store, hash-verified

530}
531
532function findIfBlocks(source) {
533 const blocks = []
534 const regex = /\bif\s*\(/g
535 let match
536 while ((match = regex.exec(source)) !== null) {
537 const parenStart = source.indexOf('(', match.index)
538 const parenEnd = findMatchingDelimiter(source, parenStart, '(', ')')
539 const braceStart = source.indexOf('{', parenEnd)
540 if (braceStart === -1) continue
541 const bodySource = extractBalancedSegment(source, braceStart, '{', '}')
542 blocks.push({
543 gate: source.slice(parenStart + 1, parenEnd).replace(/\s+/g, ' ').trim(),
544 start: match.index,
545 end: braceStart + bodySource.length,
546 body: bodySource.slice(1, -1),
547 })
548 regex.lastIndex = braceStart + bodySource.length
549 }
550 return blocks
551}
552
553function stripRanges(source, ranges) {
554 if (ranges.length === 0) return source

Callers 1

collectBundledSkillRowsFunction · 0.85

Calls 2

findMatchingDelimiterFunction · 0.85
extractBalancedSegmentFunction · 0.85

Tested by

no test coverage detected