Parse lines starting from start_idx with given base indentation. Args: lines: Lines to parse start_idx: Starting line index base_indent: Base indentation level opts: Decoder options indent_size: Size of one indentation level (default 2) Returns:
(lines: List[str], start_idx: int, base_indent: int, opts: DecoderOptions, indent_size: int = 2)
| 153 | |
| 154 | |
| 155 | def _parse_lines(lines: List[str], start_idx: int, base_indent: int, opts: DecoderOptions, indent_size: int = 2) -> Tuple[Any, int]: |
| 156 | """ |
| 157 | Parse lines starting from start_idx with given base indentation. |
| 158 | |
| 159 | Args: |
| 160 | lines: Lines to parse |
| 161 | start_idx: Starting line index |
| 162 | base_indent: Base indentation level |
| 163 | opts: Decoder options |
| 164 | indent_size: Size of one indentation level (default 2) |
| 165 | |
| 166 | Returns: |
| 167 | (parsed_value, next_line_index) |
| 168 | """ |
| 169 | if start_idx >= len(lines): |
| 170 | return {}, start_idx |
| 171 | |
| 172 | result = {} |
| 173 | i = start_idx |
| 174 | |
| 175 | while i < len(lines): |
| 176 | line = lines[i] |
| 177 | |
| 178 | # Skip empty lines |
| 179 | if not line.strip(): |
| 180 | i += 1 |
| 181 | continue |
| 182 | |
| 183 | # Calculate indentation |
| 184 | indent = len(line) - len(line.lstrip()) |
| 185 | |
| 186 | # If indentation is less than base, we're done with this block |
| 187 | if indent < base_indent: |
| 188 | break |
| 189 | |
| 190 | # If indentation is greater than expected, skip (part of previous value) |
| 191 | if indent > base_indent: |
| 192 | i += 1 |
| 193 | continue |
| 194 | |
| 195 | # Parse the line |
| 196 | stripped = line.strip() |
| 197 | |
| 198 | # Check for array header: name[N]{fields}: or name[N\t]{fields}: or name[N|]{fields}: |
| 199 | # Capture optional delimiter indicator after length |
| 200 | array_match = re.match(r'^([^:\[\]]+)\[(\d+)([\t|])?\](?:\{([^}]+)\})?' + COLON + r'\s*$', stripped) |
| 201 | if array_match: |
| 202 | key = array_match.group(1) |
| 203 | count = int(array_match.group(2)) |
| 204 | delimiter_indicator = array_match.group(3) |
| 205 | fields_str = array_match.group(4) |
| 206 | |
| 207 | # Determine delimiter from indicator if present |
| 208 | if delimiter_indicator == '\t': |
| 209 | detected_delimiter = TAB |
| 210 | elif delimiter_indicator == '|': |
| 211 | detected_delimiter = PIPE |
| 212 | else: |
no test coverage detected
searching dependent graphs…