Create a new `Function` instance. # Arguments `function_dispatcher` - The function dispatcher to use. `statement` - The statement that the function is part of. `function` - The function node. # Errors This function will return an error if the function node is not valid.
(statement_bytes: &[u8], function: &Node)
| 80 | /// |
| 81 | /// This function will return an error if the function node is not valid. |
| 82 | pub fn new(statement_bytes: &[u8], function: &Node) -> Result<Self, DscError> { |
| 83 | let mut function_name = None; |
| 84 | let mut function_args = None; |
| 85 | let mut cursor = function.walk(); |
| 86 | for member in function.named_children(&mut cursor) { |
| 87 | match member.kind() { |
| 88 | "arguments" => function_args = Some(member), |
| 89 | "functionName" => function_name = Some(member), |
| 90 | "ERROR" => return Err(DscError::Parser(t!("parser.functions.foundErrorNode").to_string())), |
| 91 | _ => {} |
| 92 | } |
| 93 | } |
| 94 | let Some(name) = function_name else { |
| 95 | return Err(DscError::Parser(t!("parser.functions.nameNodeNotFound").to_string())); |
| 96 | }; |
| 97 | let args = convert_args_node(statement_bytes, function_args.as_ref())?; |
| 98 | let name = name.utf8_text(statement_bytes)?; |
| 99 | debug!("{}", t!("parser.functions.functionName", name = name)); |
| 100 | Ok(Function{ |
| 101 | name: name.to_string(), |
| 102 | args}) |
| 103 | } |
| 104 | |
| 105 | /// Invoke the function. |
| 106 | /// |
nothing calls this directly
no test coverage detected