Parse `sshd_config` to map. # Arguments `input` - The `sshd_config` text to parse, from sshd -T. # Errors This function will return an error if the parser fails to initalize or the input fails to parse.
(&mut self, input: &str)
| 46 | /// |
| 47 | /// This function will return an error if the parser fails to initalize or the input fails to parse. |
| 48 | pub fn parse_text(&mut self, input: &str) -> Result<(), SshdConfigError> { |
| 49 | let mut parser = Parser::new(); |
| 50 | parser.set_language(&tree_sitter_ssh_server_config::LANGUAGE.into())?; |
| 51 | |
| 52 | let Some(tree) = &mut parser.parse(input, None) else { |
| 53 | return Err(SshdConfigError::ParserError(t!("parser.failedToParse", input = input).to_string())); |
| 54 | }; |
| 55 | let root_node = tree.root_node(); |
| 56 | if root_node.is_error() { |
| 57 | return Err(SshdConfigError::ParserError(t!("parser.failedToParseRoot", input = input).to_string())); |
| 58 | } |
| 59 | if root_node.kind() != "server_config" { |
| 60 | return Err(SshdConfigError::ParserError(t!("parser.invalidConfig", input = input).to_string())); |
| 61 | } |
| 62 | let input_bytes = input.as_bytes(); |
| 63 | let mut cursor = root_node.walk(); |
| 64 | for child_node in root_node.named_children(&mut cursor) { |
| 65 | self.parse_child_node(child_node, input, input_bytes)?; |
| 66 | } |
| 67 | Ok(()) |
| 68 | } |
| 69 | |
| 70 | fn parse_child_node(&mut self, node: tree_sitter::Node, input: &str, input_bytes: &[u8]) -> Result<(), SshdConfigError> { |
| 71 | if node.is_error() { |
no test coverage detected