MCPcopy Index your code
hub / github.com/ScrapeGraphAI/toonify / _parse_list_array

Function _parse_list_array

toon/decoder.py:309–380  ·  view source on GitHub ↗

Parse a list array.

(
    lines: List[str],
    start_idx: int,
    base_indent: int,
    count: int,
    opts: DecoderOptions,
    indent_size: int = 2
)

Source from the content-addressed store, hash-verified

307
308
309def _parse_list_array(
310 lines: List[str],
311 start_idx: int,
312 base_indent: int,
313 count: int,
314 opts: DecoderOptions,
315 indent_size: int = 2
316) -> Tuple[List[Any], int]:
317 """Parse a list array."""
318 result = []
319 i = start_idx
320 expected_indent = base_indent + indent_size
321
322 for _ in range(count):
323 if i >= len(lines):
324 break
325
326 line = lines[i]
327 indent = len(line) - len(line.lstrip())
328
329 if indent < expected_indent:
330 break
331
332 if indent == expected_indent:
333 # Check if it's a simple value or nested object
334 stripped = line.strip()
335
336 # Strip dash marker if present
337 if stripped.startswith('- '):
338 stripped = stripped[2:] # Remove "- " prefix
339
340 if COLON in stripped and not stripped.startswith(LEFT_BRACKET):
341 # Nested object - collect all lines for this object
342 obj_lines = [' ' * expected_indent + stripped] # First line without dash
343 i += 1
344
345 # Collect subsequent lines that are part of this object (indent > expected_indent)
346 while i < len(lines):
347 next_line = lines[i]
348 next_indent = len(next_line) - len(next_line.lstrip())
349
350 if next_indent <= expected_indent:
351 # Next item or end of array
352 break
353
354 # Normalize indentation: subtract indent_size spaces to align with first field
355 # Original: ' name: extra field' (4 spaces with indent_size=2)
356 # Becomes: ' name: extra field' (2 spaces)
357 normalized_line = ' ' * expected_indent + next_line.lstrip()[0:] if next_indent >= expected_indent + indent_size else next_line
358 if next_indent >= expected_indent + indent_size:
359 normalized_line = ' ' * expected_indent + next_line[expected_indent + indent_size:]
360 else:
361 normalized_line = next_line
362 obj_lines.append(normalized_line)
363 i += 1
364
365 # Parse collected lines as an object
366 # All lines now have fields at expected_indent

Callers 2

decodeFunction · 0.85
_parse_linesFunction · 0.85

Calls 2

_parse_linesFunction · 0.85
_parse_valueFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…