more custom regex functions
This commit is contained in:
parent
1f2331c00a
commit
e069afb8b8
3 changed files with 56 additions and 3 deletions
|
|
@ -41,7 +41,8 @@ CUSTOM_FUNCTION_SCRIPTS: Dict[str, str] = {
|
||||||
# $0 - input variable
|
# $0 - input variable
|
||||||
# $1 - regex array
|
# $1 - regex array
|
||||||
# $2 - defaults
|
# $2 - defaults
|
||||||
"%regex_capture": """{
|
# $3 - error message
|
||||||
|
"%regex_capture_inner": """{
|
||||||
%assert_then(
|
%assert_then(
|
||||||
%array_reduce(
|
%array_reduce(
|
||||||
%array_apply_fixed(
|
%array_apply_fixed(
|
||||||
|
|
@ -63,7 +64,35 @@ CUSTOM_FUNCTION_SCRIPTS: Dict[str, str] = {
|
||||||
%array_extend( ['using all defaults'], $2 ),
|
%array_extend( ['using all defaults'], $2 ),
|
||||||
True
|
True
|
||||||
),
|
),
|
||||||
'Number of regex capture groups must be less than or equal to the number of defaults'
|
$3
|
||||||
|
)
|
||||||
|
}""",
|
||||||
|
"%regex_capture_many_required": """{
|
||||||
|
%assert_ne(
|
||||||
|
%regex_capture_inner(
|
||||||
|
$0, $1, ['', '', '', '', '', '', '', '', '', ''],
|
||||||
|
'When using %regex_capture_many, number of regex capture groups must be less than or equal to the number of defaults'
|
||||||
|
),
|
||||||
|
['using all defaults', '', '', '', '', '', '', '', '', '', ''],
|
||||||
|
'When running %regex_capture_many_required, no regex strings captured'
|
||||||
|
)
|
||||||
|
}""",
|
||||||
|
"%regex_capture_many_with_defaults": """{
|
||||||
|
%regex_capture_inner(
|
||||||
|
$0, $1, $2,
|
||||||
|
'When using %regex_capture_with_defaults, number of regex capture groups must be less than or equal to the number of defaults'
|
||||||
|
)
|
||||||
|
}""",
|
||||||
|
"%regex_search_any": """{
|
||||||
|
%ne(
|
||||||
|
%array_at(
|
||||||
|
%regex_capture_inner(
|
||||||
|
$0, $1, [],
|
||||||
|
'When using %regex_search_many, all regex strings must contain no capture groups'
|
||||||
|
),
|
||||||
|
0
|
||||||
|
),
|
||||||
|
'using all defaults'
|
||||||
)
|
)
|
||||||
}""",
|
}""",
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,3 +33,27 @@ class ErrorFunctions:
|
||||||
if not bool(value.value):
|
if not bool(value.value):
|
||||||
raise UserThrownRuntimeError(assert_message)
|
raise UserThrownRuntimeError(assert_message)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def assert_eq(
|
||||||
|
value: ReturnableArgument, equals: AnyArgument, assert_message: String
|
||||||
|
) -> ReturnableArgument:
|
||||||
|
"""
|
||||||
|
Explicitly throw an error with the provided assert message if ``value`` does not equal
|
||||||
|
``equals``. If they do equal, then return ``value``.
|
||||||
|
"""
|
||||||
|
if not value.value == equals.value:
|
||||||
|
raise UserThrownRuntimeError(assert_message)
|
||||||
|
return value
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def assert_ne(
|
||||||
|
value: ReturnableArgument, equals: AnyArgument, assert_message: String
|
||||||
|
) -> ReturnableArgument:
|
||||||
|
"""
|
||||||
|
Explicitly throw an error with the provided assert message if ``value`` equals
|
||||||
|
``equals``. If they do equal, then return ``value``.
|
||||||
|
"""
|
||||||
|
if value.value == equals.value:
|
||||||
|
raise UserThrownRuntimeError(assert_message)
|
||||||
|
return value
|
||||||
|
|
@ -77,7 +77,7 @@ def regex_subscription_dict(regex_subscription_dict_base, output_directory):
|
||||||
},
|
},
|
||||||
"overrides": {
|
"overrides": {
|
||||||
"title_capture_list": f"""{{
|
"title_capture_list": f"""{{
|
||||||
%regex_capture(
|
%regex_capture_many_with_defaults(
|
||||||
title,
|
title,
|
||||||
[
|
[
|
||||||
"should not cap (.+) - (.+)",
|
"should not cap (.+) - (.+)",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue