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

Method parse_text

resources/sshdconfig/src/parser.rs:48–68  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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() {

Callers 1

parse_text_to_mapFunction · 0.80

Calls 3

parse_child_nodeMethod · 0.80
newFunction · 0.50
parseMethod · 0.45

Tested by

no test coverage detected