Parse YAML list lines (lines starting with "- ") at the given indent level. Returns the list of values and the next unconsumed line index.
(
lines: &[&str],
start: usize,
base_indent: usize,
)
| 1030 | /// Parse YAML list lines (lines starting with "- ") at the given indent level. |
| 1031 | /// Returns the list of values and the next unconsumed line index. |
| 1032 | fn parse_yaml_list_lines( |
| 1033 | lines: &[&str], |
| 1034 | start: usize, |
| 1035 | base_indent: usize, |
| 1036 | ) -> (Vec<serde_json::Value>, usize) { |
| 1037 | let mut list = Vec::new(); |
| 1038 | let mut i = start; |
| 1039 | |
| 1040 | while i < lines.len() { |
| 1041 | let line = lines[i]; |
| 1042 | let trimmed = line.trim(); |
| 1043 | |
| 1044 | if trimmed.is_empty() || trimmed.starts_with('#') { |
| 1045 | i += 1; |
| 1046 | continue; |
| 1047 | } |
| 1048 | |
| 1049 | let current_indent = indent_level(line); |
| 1050 | if current_indent < base_indent { |
| 1051 | break; |
| 1052 | } |
| 1053 | if current_indent > base_indent { |
| 1054 | // Continuation of previous item, skip |
| 1055 | i += 1; |
| 1056 | continue; |
| 1057 | } |
| 1058 | |
| 1059 | if let Some(item_str) = trimmed.strip_prefix("- ") { |
| 1060 | let item_str = item_str.trim(); |
| 1061 | // Check if item itself is a key: value (nested object in list) |
| 1062 | if item_str.contains(": ") { |
| 1063 | // Could be an inline object item like "- key: value" |
| 1064 | // For simplicity, treat as scalar string |
| 1065 | list.push(yaml_scalar_to_json(item_str)); |
| 1066 | } else if let Some(inline_list) = parse_inline_list(item_str) { |
| 1067 | list.push(inline_list); |
| 1068 | } else { |
| 1069 | list.push(yaml_scalar_to_json(item_str)); |
| 1070 | } |
| 1071 | i += 1; |
| 1072 | } else { |
| 1073 | break; |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | (list, i) |
| 1078 | } |
| 1079 | |
| 1080 | /// Collect indented block text lines (for block scalars or multi-line values). |
| 1081 | /// Stops when a line at or below `parent_indent` is encountered. |
no test coverage detected