MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / parseLines

Function parseLines

src/integrations/misc/indentation-reader.ts:110–139  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

108 * Parse a file's lines into LineRecord objects with indentation information.
109 */
110export function parseLines(content: string): LineRecord[] {
111 const lines = content.split("\n")
112 return lines.map((line, index) => {
113 const trimmed = line.trimStart()
114 const leadingWhitespace = line.length - trimmed.length
115
116 // Calculate indent in spaces (tabs = TAB_WIDTH spaces each)
117 let indentSpaces = 0
118 for (let i = 0; i < leadingWhitespace; i++) {
119 if (line[i] === "\t") {
120 indentSpaces += TAB_WIDTH
121 } else {
122 indentSpaces += 1
123 }
124 }
125 // Convert to indent level (number of INDENT_SIZE units)
126 const indentLevel = Math.floor(indentSpaces / INDENT_SIZE)
127
128 const isBlank = trimmed.length === 0
129 const isBlockStart = !isBlank && BLOCK_START_PATTERNS.some((pattern) => pattern.test(line))
130
131 return {
132 lineNumber: index + 1,
133 content: line,
134 indentLevel,
135 isBlank,
136 isBlockStart,
137 }
138 })
139}
140
141/**
142 * Compute effective indents where blank lines inherit the previous non-blank line's indent.

Callers 3

readWithIndentationFunction · 0.85
readWithSliceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected