Skip to main content

parse_code

Function parse_code 

Source
pub fn parse_code(
    source: &str,
    lang: CodeLanguage,
) -> Result<Vec<Section>, Error>
Expand description

Parse source code into structural sections.

Each top-level function / class / struct / impl becomes a Section whose heading is "<kind>:<name>" (e.g. "fn:main", "class:Foo") and whose text is the verbatim source span.

ยงErrors

Returns Error::ParseFailed if the grammar cannot be initialised or if the source is not valid UTF-8 (the caller should validate before passing). A source with syntax errors is still parsed - tree-sitter produces a best-effort tree for recovery.