Insert a key-value pair into a map with repeatability handling. If the key is repeatable and already exists, append to the array. If the key is not repeatable and already exists, return an error.
(map: &mut Map<String, Value>, key: &str, value: Value, is_repeatable: bool)
| 224 | /// If the key is repeatable and already exists, append to the array. |
| 225 | /// If the key is not repeatable and already exists, return an error. |
| 226 | fn insert_into_map(map: &mut Map<String, Value>, key: &str, value: Value, is_repeatable: bool) -> Result<(), SshdConfigError> { |
| 227 | if map.contains_key(key) { |
| 228 | if is_repeatable { |
| 229 | let existing_value = map.get_mut(key); |
| 230 | if let Some(existing_value) = existing_value { |
| 231 | if let Value::Array(arr) = existing_value { |
| 232 | if let Value::Array(vector) = value { |
| 233 | for v in vector { |
| 234 | arr.push(v); |
| 235 | } |
| 236 | } else { |
| 237 | arr.push(value); |
| 238 | } |
| 239 | } else { |
| 240 | return Err(SshdConfigError::ParserError( |
| 241 | t!("parser.failedToParseAsArray").to_string() |
| 242 | )); |
| 243 | } |
| 244 | } else { |
| 245 | return Err(SshdConfigError::ParserError(t!("parser.keyNotFound", key = key).to_string())); |
| 246 | } |
| 247 | } else { |
| 248 | return Err(SshdConfigError::ParserError(t!("parser.keyNotRepeatable", key = key).to_string())); |
| 249 | } |
| 250 | } else if is_repeatable { |
| 251 | // Initialize repeatable keywords as arrays |
| 252 | if value.is_array() { |
| 253 | map.insert(key.to_string(), value); |
| 254 | } else { |
| 255 | map.insert(key.to_string(), Value::Array(vec![value])); |
| 256 | } |
| 257 | } else { |
| 258 | map.insert(key.to_string(), value); |
| 259 | } |
| 260 | Ok(()) |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | fn parse_arguments_node(arg_node: tree_sitter::Node, input: &str, input_bytes: &[u8], keyword_info: &KeywordInfo) -> Result<Value, SshdConfigError> { |