AST (pyndoc.ast package)

This package contains the definitions related to the Pyndoc Abstract Syntax Tree, including blocks, helpers, and read handlers

Submodules

pyndoc.ast.ast_tree module

class pyndoc.ast.ast_tree.ASTTree(initlist=None)[source]

Bases: UserList

pyndoc.ast.basic_blocks module

Basic AST blocks that are used as a base for more complex AST Blocks

class pyndoc.ast.basic_blocks.ASTBlock[source]

Bases: ABC

Definition of a base AST block

class pyndoc.ast.basic_blocks.ASTAtomBlock(contents: str = '')[source]

Bases: ASTBlock, AtomReadHandler

Definition of an AST Atom Block. An AST Atom block is a block that cannot hold any other blocks inside of it.

Parameters:

contents (str, optional) – the contents of the Atom Block, empty by default

class pyndoc.ast.basic_blocks.ASTCompositeContents(metadata: list, contents: list[ASTBlock])[source]

Bases: object

The representation of a composite block’s contents

Parameters:
  • metadata (list) – The block’s special metadata

  • contents (list[ASTBlock]) – The contents of the class

class pyndoc.ast.basic_blocks.ASTCompositeBlock(metadata: list | None = None, contents: list | None = None)[source]

Bases: ASTBlock, CompositeReadHandler

The definition of an AST Composite block. This block can hold both atom, and other composite blocks inside of it.

Parameters:
  • metadata (list | None) – List of block’s metadata

  • contents (list | None) – A list of other ASTBlocks representing the block’s contents, defaults to a None object

insert(block: ASTBlock) None[source]

Insert another AST Block into this one :param block: the other block object :type block: ASTBlock

pyndoc.ast.blocks module

Defualt block definitions

class pyndoc.ast.blocks.Space[source]

Bases: ASTAtomBlock

AST Atom block representing whitespace

class pyndoc.ast.blocks.Str(contents: str = '')[source]

Bases: ASTAtomBlock

special AST block representing string without whitespace characters

class pyndoc.ast.blocks.SoftBreak[source]

Bases: ASTAtomBlock

class pyndoc.ast.blocks.Header[source]

Bases: ASTCompositeBlock

AST block representing a heading

class pyndoc.ast.blocks.Para[source]

Bases: ASTCompositeBlock

AST block representing a paragraph.

class pyndoc.ast.blocks.Emph[source]

Bases: ASTCompositeBlock

Basic Italic AST block

class pyndoc.ast.blocks.Strong[source]

Bases: ASTCompositeBlock

Basic Bold AST block

class pyndoc.ast.blocks.Code[source]

Bases: ASTAtomBlock

Basic Code AST block

class pyndoc.ast.blocks.BulletList[source]

Bases: ASTCompositeBlock

class pyndoc.ast.blocks.OrderedList[source]

Bases: ASTCompositeBlock

Ordered List AST block

class pyndoc.ast.blocks.Plain[source]

Bases: ASTCompositeBlock

class pyndoc.ast.blocks.Table[source]

Bases: ASTCompositeBlock

Table AST block

class pyndoc.ast.blocks.TableHead[source]

Bases: ASTCompositeBlock

Table Head AST block

class pyndoc.ast.blocks.TableBody[source]

Bases: ASTCompositeBlock

Table Body AST block

class pyndoc.ast.blocks.Row[source]

Bases: ASTCompositeBlock

Table Row AST block

class pyndoc.ast.blocks.Cell[source]

Bases: ASTCompositeBlock

Table Cell AST block

class pyndoc.ast.blocks.CodeBlock[source]

Bases: ASTAtomBlock

Code block AST block

pyndoc.ast.helpers module

class pyndoc.ast.helpers.StartParams[source]

Bases: TypedDict

context: list
token: str
class pyndoc.ast.helpers.EndParams[source]

Bases: TypedDict

context: list
token: str
class pyndoc.ast.helpers.ProcessParams[source]

Bases: TypedDict

context: list
match: Match
class pyndoc.ast.helpers.AtomMatchParams[source]

Bases: TypedDict

context: list
text: str
class pyndoc.ast.helpers.NumberingType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

DECIMAL = 1
ALPHABETIC = 2
ROMAN_NUMERALS = 3
class pyndoc.ast.helpers.Separator(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

PERIOD = 1
CLOSING_PAREN = 2
class pyndoc.ast.helpers.Alignment(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

ALIGN_DEFAULT = 1
ALIGN_CENTER = 2
ALIGN_LEFT = 3
ALIGN_RIGHT = 4
class pyndoc.ast.helpers.AlignmentList(initlist=None)[source]

Bases: UserList

pyndoc.ast.read_handler module

Read handlers, that define class attributes for read patterns for certain blocks

class pyndoc.ast.read_handler.CompositeReadHandler[source]

Bases: object

Class that is meant as a handler for reading logic for an AST Composite child. methods implemented here are defaults for

start_pattern = ''

str, The start pattern of a block, defaults to an empty string

end_pattern = ''

str, The end pattern of a block, defaults to an empty string

inline = False

bool, decides if the block is an inline

process_read(**_: Unpack[ProcessParams]) None[source]

Process additional keyword arguments after block initialization. Not used here, the function is meant to be used inside of blocks inherited from basic AST blocks. Otherwise no processing will be done

classmethod start(**kwargs: Unpack[StartParams]) tuple[Match | None, str][source]

Check if a block has started. Returns a match if matched, otherwise None

Parameters:

**kwargs – See below

Keyword Arguments:
  • token (str) – the current token

classmethod end(**kwargs: Unpack[EndParams]) tuple[Match | None, str][source]

Check if a block has ended. Returns a match if matched, otherwise None

Parameters:

**kwargs – See below

Keyword Arguments:
  • token (str) – string representing current token to be matched against pattern

classmethod override_start(pattern: str) None[source]

Override the start pattern of an ASTCompositeBlock

Parameters:

pattern (str) – The new pattern of a block

classmethod override_end(pattern: str) None[source]

Override the end pattern of an ASTCompositeBlock

Parameters:

pattern (str) – The new pattern of a block

classmethod override_inline(value: bool) None[source]

Override the inline boolean value of an ASTBlock

Parameters:

value (bool) – The new value of the attribute

classmethod is_inline() bool[source]

Check if a given block type is inline, default: False

classmethod handle_premature_closure(**kwargs: Unpack[EndParams]) str[source]

Used when when the file has ended, but context has not been closed Potentially modify recieved token end return it

Parameters:

token (str) – The current token to be modified

class pyndoc.ast.read_handler.AtomReadHandler[source]

Bases: object

pattern = ''
start_pattern = ''
has_content = True
classmethod match_pattern(**kwargs: Unpack[AtomMatchParams]) tuple[Match | None, str][source]

Check if the block matches a given token. Returns a regex match (or None if match failed)

Parameters:

**kwargs – See below

Keyword Arguments:
  • text (str) – the token to be matched against the pattern attribute

classmethod override_match_pattern(pattern: str) None[source]

Set the match pattern to a new value

Parameters:

pattern (str) – The new pattern to be set

classmethod block_has_content() bool[source]

Check if a block can have contents

Returns:

True if the block can have contents

Return type:

bool

classmethod override_has_content(value: bool) None[source]

Change if a block can have contents, usually set at runstart

Parameters:

value (bool) – If the block can have contents

Module contents