def eval(self, text, supp_context=None): """ Evaluates *text* as a macro string in the units context. Args: text (str): The text to evaluate. supp_context (creator.macro.ContextProvider): A context that will be taken into account additionally to the stack frame and unit context or None. Returns: str: The result of the evaluation. """ if supp_context: context = creator.macro.ChainContext(self.context) context.contexts.insert(0, supp_context) else: context = self.context macro = creator.macro.parse(text, context) return macro.eval(context, [])
def eval(self, text, supp_context=None, stack_depth=0): """ Evaluates *text* as a macro string in the units context. Args: text (str): The text to evaluate. supp_context (creator.macro.ContextProvider): A context that will be taken into account additionally to the stack frame and unit context or None. stack_depth (int): The number of frames to go backwards from the calling frame to use the local and global variables from. Returns: str: The result of the evaluation. """ context = creator.macro.ChainContext(self.context) if stack_depth >= 0: sf_context = creator.macro.StackFrameContext(stack_depth + 1) context.contexts.insert(0, sf_context) if supp_context is not None: context.contexts.insert(0, supp_context) macro = creator.macro.parse(text, context) return macro.eval(context, [])