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

Function convert_args_node

lib/dsc-lib/src/parser/functions.rs:152–184  ·  view source on GitHub ↗
(statement_bytes: &[u8], args: Option<&Node>)

Source from the content-addressed store, hash-verified

150}
151
152fn convert_args_node(statement_bytes: &[u8], args: Option<&Node>) -> Result<Option<Vec<FunctionArg>>, DscError> {
153 let Some(args) = args else {
154 return Ok(None);
155 };
156 let mut result = vec![];
157 let mut cursor = args.walk();
158 for arg in args.named_children(&mut cursor) {
159 match arg.kind() {
160 "string" => {
161 let value = arg.utf8_text(statement_bytes)?;
162 // Resolve escaped single quotes
163 result.push(FunctionArg::Value(Value::String(value.to_string().replace("''", "'"))));
164 },
165 "number" => {
166 let value = arg.utf8_text(statement_bytes)?;
167 result.push(FunctionArg::Value(Value::Number(Number::from(value.parse::<i32>()?))));
168 },
169 "boolean" => {
170 let value = arg.utf8_text(statement_bytes)?;
171 result.push(FunctionArg::Value(Value::Bool(value.parse::<bool>()?)));
172 },
173 "expression" => {
174 // TODO: this is recursive, we may want to stop at a specific depth
175 let expression = Expression::new(statement_bytes, &arg)?;
176 result.push(FunctionArg::Expression(expression));
177 },
178 _ => {
179 return Err(DscError::Parser(t!("parser.functions.unknownArgType", kind = arg.kind()).to_string()));
180 }
181 }
182 }
183 Ok(Some(result))
184}

Callers 1

newMethod · 0.85

Calls 3

BoolClass · 0.85
ExpressionClass · 0.85
newFunction · 0.50

Tested by

no test coverage detected