janus.language.block#
Attributes#
Classes#
A class that represents a functional block of code. |
|
A class that represents the translated functional block of code. |
Module Contents#
- janus.language.block.log#
- class janus.language.block.CodeBlock(id, name, node_type, language, text, start_point, end_point, start_byte, end_byte, tokens, children, embedding_id=None, affixes=('', ''), context_tags={})#
A class that represents a functional block of code.
- Parameters:
- id#
The id of the code block in the AST
- name#
Descriptive name of node
- node_type#
The type of the code block (‘function’, ‘module’, etc.). Defined in the language-specific modules.
- language#
The language of the code block.
- text#
The code block.
- start_point#
The line and column numbers of the first line of the code block.
- end_point#
The line and column numbers of the last line of the code block.
- start_byte#
starting byte offset into file
- end_byte#
ending byte offset into file
- tokens#
The number of tokens in the code block.
- children#
A tuple of child code blocks.
- embedding_id#
id of embedding
- affixes#
prefix and suffix text for node
- complete#
Rolls up self and children’s complete status, incomplete means a child is missing.
- property n_descendents: int#
The total number of descendents of this block
- Returns:
The total number of descendents of this block
- Return type:
- property height: int#
The number of edges between this node and a leaf
- Returns:
The number of edges between this node and a leaf
- Return type:
- property max_tokens: int#
The maximum number of tokens in this block or any of its descendents
- Returns:
The maximum number of tokens in this block or any of its descendents
- Return type:
- property total_tokens: int#
The total tokens represented by this block and all its descendents
- Returns:
The total number of tokens represented by this block and all its descendents
- Return type:
- pop_prefix()#
Get this block’s prefix and remove it from the block. This may be used to transfer the prefix from the first child of a node to its parent.
- Return type:
- pop_suffix()#
Get this block’s suffix and remove it from the block. This may be used to transfer the suffix from the first child of a node to its parent.
- Return type:
- rebuild_text_from_children()#
- class janus.language.block.TranslatedCodeBlock(original, language)#
Bases:
CodeBlock
A class that represents the translated functional block of code.
- original#
The original code block.
- cost#
The total cost to translate the original code block.
- retries#
The number of times translation had to be retried for this code
- translated#
Whether this block has been successfully translated
Create an “empty” TranslatedCodeBlock from the given original
- Parameters:
- Returns:
A TranslatedCodeBlock with the same attributes as the original, except for text, path, complete, language, tokens, and children
- property total_cost: float#
The total cost spent translating this block and all its descendents
- Returns:
The total cost spent translating this block and all its descendents
- Return type:
- property total_retries: int#
The total number of retries that were required to translate this block and all its descendents
- Returns:
The total number of retries that were required to translate this block and
- Return type: