Skip to content

Semantics

block_comment

This module contains the representation of a block or multi-line comment in an ASP document.

BlockComment dataclass

A block comment in an ASP document.

lines: list[str] instance-attribute

The lines of text of the block comment.

row: int instance-attribute

The row of the block comment.

from_node(node: Node) -> BlockComment staticmethod

Create a block comment from a node.

document_parser

This module contains the DocumentParser class, which is responsible for parsing ASP documents.

It extracts relevant information from the Tree-sitter parse tree and populates the Document object with statements, predicates, comments, and other elements.

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

line_comment

This module contains the LineComment class, which represents a single line comment in an ASP document.

LineComment dataclass

A line comment in an ASP document.

line: str instance-attribute

The line of text of the comment.

row: int instance-attribute

The row of the line comment.

from_node(node: Node) -> LineComment staticmethod

Create a line comment from a node.

predicate

This module contains the Predicate class, which holds information about a specific ASP predicate.

Predicate dataclass

A predicate in an ASP document.

arity: int instance-attribute

The arity of the predicate.

documentation: PredicateDocumentation | None = None class-attribute instance-attribute

The documentation of the predicate.

identifier: str instance-attribute

The identifier of the predicate.

is_input: bool = False class-attribute instance-attribute

If it is an input (Not defined by any rule).

show_status: ShowStatus = ShowStatus.DEFAULT class-attribute instance-attribute

The show status of the predicate.

signature: str property

Return the signature of the predicate.

The signature of a predicate is a string of the form identifier/arity.

Returns:

Type Description
str

The signature of the predicate.

__str__() -> str

Return the string representation of the predicate.

If the predicate has documentation, return the representation from the documentation. Otherwise, return the default representation.

The default representation is of the form identifier(A, B, C) where A, B, and C are the first three uppercase letters of the alphabet.

Returns:

Type Description
str

The string representation of the predicate.

from_node(node: Node) -> Predicate staticmethod

Create a predicate from a node.

Parameters:

Name Type Description Default
node Node

The node representing the predicate.

required

Returns:

Type Description
Predicate

The created predicate.

update_show_status(status: ShowStatus) -> None

Update the show status of the predicate.

Parameters:

Name Type Description Default
status ShowStatus

The new show status.

required

ShowStatus

Bases: IntEnum

Enum for predicate show status with bitwise-compatible values.

predicate_documentation

This module contains the 'PredicateDocumentation', which represents the documentation for a predicate.

PredicateDocumentation dataclass

Documentation for a predicate.

Example

%*#some_predicate(A,B,C). description

parameters

  • A : this is A
  • B : this is B
  • C : this is C *%

description: str instance-attribute

The description of the predicate.

node: Node | None = None class-attribute instance-attribute

The node representing the predicate.

parameter_descriptions: dict[str, str] = field(default_factory=dict) class-attribute instance-attribute

The descriptions of the parameters of the predicate.

signature: str instance-attribute

The signature of the predicate.

from_block_comment(comment: BlockComment) -> PredicateDocumentation | None staticmethod

Create a predicate documentation from a comment.

Parameters:

Name Type Description Default
comment BlockComment

The block comment.

required

Returns:

Type Description
PredicateDocumentation | None

The predicate documentation or None if the comment is not a predicate documentation.

statement

This module contains the Statement class, which represents a statement in an ASP program.

Statement dataclass

A statement in an ASP program.

needed_predicates: list[Tuple[Predicate, bool]] instance-attribute

The predicates needed by the statement.

provided_predicates: list[Tuple[Predicate, bool]] instance-attribute

The predicates provided by the statement.

row: int instance-attribute

The row in the source file where the statement is located.

text: str instance-attribute

The text of the statement.

add_needed(predicate: Predicate, negation: bool = False)

Add a predicate this statement needs.

add_provided(predicate: Predicate, negation: bool = False)

Add a predicate this statement provides.

from_node(node: Node) -> Statement staticmethod

Create a statement from a node. Args: node: The node representing the statement. Returns: The created statement.