MCPcopy Create free account
hub / github.com/dprint/jsonc-parser / parse

Method parse

src/cst/mod.rs:1107–1124  ·  view source on GitHub ↗

Parses the text into a CST. WARNING: You MUST not drop the root node for the duration of using the CST or a panic could occur in certain scenarios. This is because the CST uses weak references for ancestors and if the root node is dropped then the weak reference will be lost and the CST will panic to prevent bugs when a descendant node attempts to access an ancestor that was dropped. ``` use jso

(text: &str, parse_options: &ParseOptions)

Source from the content-addressed store, hash-verified

1105 /// }"#);
1106 /// ```
1107 pub fn parse(text: &str, parse_options: &ParseOptions) -> Result<Self, ParseError> {
1108 let parse_result = parse_to_ast(
1109 text,
1110 &crate::CollectOptions {
1111 comments: crate::CommentCollectionStrategy::AsTokens,
1112 tokens: true,
1113 },
1114 parse_options,
1115 )?;
1116
1117 Ok(
1118 CstBuilder {
1119 text,
1120 tokens: parse_result.tokens.unwrap().into_iter().collect(),
1121 }
1122 .build(parse_result.value),
1123 )
1124 }
1125
1126 /// Computes the single indentation text of the file.
1127 pub fn single_indent_text(&self) -> Option<String> {

Callers

nothing calls this directly

Calls 3

parse_to_astFunction · 0.85
buildMethod · 0.80
into_iterMethod · 0.80

Tested by

no test coverage detected