"""Control function do.fail."""
import re
import warnings
from typing import NoReturn
from ....datatypes.string import String
from ....processor.context import Context
from .do import Do
[docs]
class Fail(Do):
"""Class for `do.fail` function.
Takes exactly one argument with a string printed to stdout on execution.
"""
min_args = 1
max_args = 1
match_re = re.compile(r"(do\.fail)\((.*)\)$")
value_types = (String,)
[docs]
def execute(self, context: Context) -> NoReturn:
"""Immediately terminate parsing with an error.
:param context: Current context object.
:raises RuntimeError: Error with given message.
"""
warnings.warn(
"The function 'do.fail()' will be deprecated."
" Use statement 'fail' instead.",
DeprecationWarning,
)
raise RuntimeError(context.replace_string_vars(self.get_string(0)))