Skip to content

Handler

Module containing the handler for ASP files.

log = logging.getLogger(__name__) module-attribute

project_data = tomllib.load(f) module-attribute

ASPHandler

Bases: BaseHandler

MKDocStrings handler for ASP files.

__init__(theme: str = 'material', **_kwargs: Any) -> None

Initialize the handler.

Parameters:

Name Type Description Default
theme str

The theme to use for the handler.

'material'
config_file_path

The path to the configuration file.

required
paths

A list of paths to search for ASP files.

required
locale

The locale to use for the handler.

required
load_external_modules

Whether to load external modules.

required
**kwargs

Keyword arguments.

required

collect(identifier: str, config: dict) -> dict | None

Collect data from ASP files.

This function will be called for all markdown files annotated with '::: some/path/to/file.lp'.

Parameters:

Name Type Description Default
identifier str

The identifier used in the annotation.

required
config dict

The configuration dictionary.

required

Returns:

Type Description
dict | None

The collected data as a dictionary.

do_convert_markdown_simple(text: str, heading_level: int) -> Markup

Render Markdown text without adding headers to the TOC

Parameters:

Name Type Description Default
text str

The text to convert.

required
heading_level int

The base heading level to start all Markdown headings from.

required

Returns:

Type Description
Markup

An HTML string.

parse_files(asp_parser: ASPParser, document_parser: DocumentParser, paths: list[Path]) -> dict[Path, Document]

Parse the files at the given paths and return a dictionary of documents.

This also handles the inclusion of other files.

Parameters:

Name Type Description Default
asp_parser ASPParser

The ASP parser.

required
document_parser DocumentParser

The document parser.

required
paths list[Path]

The paths to parse.

required

Returns:

Type Description
dict[Path, Document]

A dictionary of documents.

render(data: dict, config: dict)

Render the collected data to html.

This function will be called for all data collected by the collect function.

Parameters:

Name Type Description Default
data dict

The data collected by the collect function.

required
config dict

The configuration dictionary.

required

Returns:

Type Description

The rendered data as a string

ASPParser

A tree-sitter parser for ASP text.

__init__() -> None

Create a new ASP parser.

parse(text: str) -> Tree

Parse the given text.

Parameters:

Name Type Description Default
text str

The text to parse.

required

Returns:

Type Description
Tree

The parsed tree.

DependencyGraph dataclass

Dependency graph of an ASP document.

nodes: list[DependencyGraphNode] instance-attribute

The nodes of the dependency graph.

from_document(documents: list[Document]) -> 'DependencyGraph' staticmethod

Create a dependency graph from a list of ASP documents.

Parameters:

Name Type Description Default
documents list[Document]

The list of documents to create the graph from.

required

Returns:

Type Description
'DependencyGraph'

The dependency graph.

Document dataclass

A document representing the content of a particular ASP file.

DocumentParser

A parser for ASP documents.

__init__()

Initialize the parser.

parse(document: Document, tree: Tree) -> Document

Parse the given tree.

Parameters:

Name Type Description Default
tree Tree

The tree to parse.

required

EncodingInfo dataclass

Content of the encoding including statements and lines.

from_documents(documents: list[Document]) -> EncodingInfo staticmethod

Create a encoding content from an ASP document.

Parameters:

Name Type Description Default
document

The ASP document.

required

Returns:

Type Description
EncodingInfo

The encoding content.

PredicateInfo dataclass

predicates: Dict[str, Predicate] = field(default_factory=OrderedDict) class-attribute instance-attribute

Dictionary of predicates with their signatures as keys.

from_documents(documents: dict[Document]) -> PredicateInfo staticmethod

Create a predicate list from a list of documents.

Parameters:

Name Type Description Default
documents dict[Document]

The documents to create the predicate list from.

required

Returns:

Type Description
PredicateInfo

The predicate list.