Source code for pudding.tokens.functions.out.enter

"""Output function out.enter."""

import re

from ....datatypes import String
from ....processor import PAction
from ....processor.context import Context
from .out import Out


[docs] class Enter(Out): """Class for `out.enter` function. Creates the nodes in the given path if they do not already exist and selects the last node. Therefore the PATH of all subsequent function calls is relative to the selected node until the end of the match block is reached. """ match_re = re.compile(r"(out\.enter)\((.*)\)$") value_types = (String, String)
[docs] def execute(self, context: Context) -> PAction: """Enter a node and create it if it does not exist. :param context: Current context object. :returns: PAction.CONTINUE """ value = None if self.get_value(1): value = context.replace_string_vars(self.get_string(1)) context.writer.enter_path( context.replace_string_vars(self.get_string(0)), value, ) return PAction.CONTINUE