MCPcopy Create free account
hub / github.com/PowerShell/DSC / parse_arguments_node_as_array

Function parse_arguments_node_as_array

resources/sshdconfig/src/parser.rs:338–369  ·  view source on GitHub ↗

Parse arguments node for match criteria, always returning an array. Match criteria are always comma-separated and should be arrays.

(arg_node: tree_sitter::Node, input: &str, input_bytes: &[u8], _keyword_info: &KeywordInfo)

Source from the content-addressed store, hash-verified

336/// Parse arguments node for match criteria, always returning an array.
337/// Match criteria are always comma-separated and should be arrays.
338fn parse_arguments_node_as_array(arg_node: tree_sitter::Node, input: &str, input_bytes: &[u8], _keyword_info: &KeywordInfo) -> Result<Value, SshdConfigError> {
339 let mut cursor = arg_node.walk();
340 let mut vec: Vec<Value> = Vec::new();
341
342 let children: Vec<_> = arg_node.named_children(&mut cursor).collect();
343
344 for node in &children {
345 if node.is_error() {
346 return Err(SshdConfigError::ParserError(t!("parser.failedToParseNode", input = input).to_string()));
347 }
348 let arg = node.utf8_text(input_bytes)?;
349 match node.kind() {
350 "boolean" => {
351 let arg_str = arg.trim();
352 vec.push(Value::Bool(arg_str.eq_ignore_ascii_case("yes")));
353 }
354 "string" => {
355 let arg_str = arg.trim();
356 // Unescape backslashes (sshd -T escapes them on Windows)
357 let unescaped = unescape_backslashes(arg_str);
358 vec.push(Value::String(unescaped));
359 },
360 "number" => {
361 vec.push(Value::Number(arg.parse::<u64>()?.into()));
362 },
363 _ => return Err(SshdConfigError::ParserError(t!("parser.unknownNode", kind = node.kind()).to_string()))
364 }
365 }
366
367 // Always return array for match criteria
368 Ok(Value::Array(vec))
369}
370
371/// Parse `sshd_config` to map.
372///

Callers 1

parse_match_criteriaMethod · 0.85

Calls 4

BoolClass · 0.85
unescape_backslashesFunction · 0.85
ArrayClass · 0.85
newFunction · 0.50

Tested by

no test coverage detected