Parsing

Functions related to SourceKitten file parsing. This is used internally for document generation.

swift_rst_docs.parse(body: dict, context: GenerationContext) Structure

Parses a symbol from the documentation JSON file and returns it.

Parameters:
  • body – The dictionary value of the symbol.

  • context – The generation context to write to.

Return type:

Symbol

swift_rst_docs.fetch_fullnames(body: dict, context: GenerationContext, parent_names: list[str] = [])

Fetches a symbol’s full name (including their module) and all their sub declarations recursively, mapped to their USR value and writes them to GenerationContext.fullnames.

Parameters:

body – The dictionary value of the symbol.

Para context:

The generation context to write to.

Parent_names:

List of parents containing the fetched declaration.

Replaces symbol references with a link to their html page and returns the result. swift_rst_docs.fetch_documents() should have been called for links to be correctly generated.

Parameters:
  • text – The documentation text to parse.

  • module_name – The current module name (can be None). Finds the symbol in the current module first, then in the global scope if the module name is specified in the symbol’s name.

  • context – The generation context.

Return type:

str

swift_rst_docs.highlight_statement(statement: AnnotatedDeclaration, prettify: bool, remove_type: bool, context: GenerationContext) str

Highlights a statement’s declaration with pygments and returns it as a raw:: html block. Also replaces any USR in the statement’s declaration with links to the corresponding documentation pages if symbols are already fetched into the generation context.

Parameters:
  • statement – The statement to highlight.

  • prettify – Whether to prettify the code.

  • remove_type – Whether to remove the type.

  • context – The generation context.

Return type:

str

swift_rst_docs.prettify_swift_declaration(decl: str, indent: str = '    ') str

Splits and returns a Swift declaration into multiple lines.

Decl:

A Swift declaration.

Indent:

Indentation to use.

Return type:

str