class documentation

class ContextManager:

View In Hierarchy

Class in charge of piling all the parsed elements and then encapsulating them inside one another.

Method __call__ Interprets the list of tokens provided and deduces context, encapsulating them to their closest neighbour and containing all tokens inbetween. :rtype: list[BaseContainer] :return: Returns the pile entirely processed as a list of containers...
Method __init__ Takes a list of parsed tokens. :type parsed_list : list[syntax.SemanticType] :param parsed_list: List of parsed tokens output by our parser. :type name: str :param name: Name of the file being parsed. ...
Method __iter__ Iterator over the pile. :ytype: BaseContainer
Method encapsulate Method to encapsulate a number of tokens together as a final container object and replace all elements in the pile with None, except the first one which becomes the container. :type start : int :param start: Index of the pile where the encapsulation must begin...
Method finalize_pile Function for cleaning up of the pile after full contextualisation. Removes Nones and checks for any errors or illogical containers. :return: list[BaseContainer]
Method get_last_container_in_pile Returns the last element in the pile if it is a Container, raises an error otherwise. :type index : int :param index: Index of the element to check. :return: Last element in the pile if it is a Container, raises an error otherwise...
Method lookahead Iterates the pile beginning from index and looks for all tokens matching labels with token. :type token : syntax.BaseContainer :param token: Token to look for. :type index : int :param index: Index of the token in the pile...
Method print_all Prints the pile.
Method recontext Function to recontextualise the content of a token. :param token: Token to recontextualise. :type token: syntax.SemanticType :return: Token to recontextualise. :rtype: syntax.SemanticType
Instance Variable contextualised Undocumented
Instance Variable dict_lookahead Undocumented
Instance Variable ident Undocumented
Instance Variable matched_elements Undocumented
Instance Variable name Undocumented
Instance Variable output Undocumented
Instance Variable parsed_list Undocumented
Instance Variable pile Undocumented
Method _add_matched Method to add a matched element to the dictionary of matched elements. :type label : str :param label: Label of the matched element. :type index: int :param index: Index of the matched element in the pile.
Method _get_matched Method to get the index of the last matched element of a given label. :type label: str :param label: Label of the matched element. :rtype: int :return: Index of the last matched element
def __call__(self):

Interprets the list of tokens provided and deduces context, encapsulating them to their closest neighbour and containing all tokens inbetween. :rtype: list[BaseContainer] :return: Returns the pile entirely processed as a list of containers. :raises: MismatchedContainerError if a container is not matched to its corresponding token.

def __init__(self, parsed_list, name=None, ident=0):

Takes a list of parsed tokens. :type parsed_list : list[syntax.SemanticType] :param parsed_list: List of parsed tokens output by our parser. :type name: str :param name: Name of the file being parsed. :type ident: int :param ident: Number of spaces to indent the output.

def __iter__(self):

Iterator over the pile. :ytype: BaseContainer

def encapsulate(self, start, end):

Method to encapsulate a number of tokens together as a final container object and replace all elements in the pile with None, except the first one which becomes the container. :type start : int :param start: Index of the pile where the encapsulation must begin. :type end: int :param end: Index of the pile where the encapsulation must end. :rtype: list[(BaseContainer|None)] :return: List of containers and None objects.

def finalize_pile(self):

Function for cleaning up of the pile after full contextualisation. Removes Nones and checks for any errors or illogical containers. :return: list[BaseContainer]

def get_last_container_in_pile(self, index):

Returns the last element in the pile if it is a Container, raises an error otherwise. :type index : int :param index: Index of the element to check. :return: Last element in the pile if it is a Container, raises an error otherwise. :rtype: BaseContainer :raise: error_mngr.LonelyOptionalError when an element is found in the pile that is not encapsulated in a container.

def lookahead(self, token, index):

Iterates the pile beginning from index and looks for all tokens matching labels with token. :type token : syntax.BaseContainer :param token: Token to look for. :type index : int :param index: Index of the token in the pile. :return: (number of tokens matched, number of linebreaks) :rtype: (int, int)

def print_all(self):

Prints the pile.

def recontext(self, token):

Function to recontextualise the content of a token. :param token: Token to recontextualise. :type token: syntax.SemanticType :return: Token to recontextualise. :rtype: syntax.SemanticType

contextualised: bool =

Undocumented

dict_lookahead: dict =

Undocumented

ident =

Undocumented

matched_elements: dict =

Undocumented

name =

Undocumented

output: list =

Undocumented

parsed_list =

Undocumented

pile =

Undocumented

def _add_matched(self, label, index):

Method to add a matched element to the dictionary of matched elements. :type label : str :param label: Label of the matched element. :type index: int :param index: Index of the matched element in the pile.

def _get_matched(self, label):

Method to get the index of the last matched element of a given label. :type label: str :param label: Label of the matched element. :rtype: int :return: Index of the last matched element