This commit is contained in:
anhduy-tech
2026-01-06 11:40:03 +07:00
parent 661bb2ba7a
commit fd10218cca
4 changed files with 31 additions and 0 deletions

View File

@@ -54,6 +54,37 @@ def resolve_value(expr, context):
except (ValueError, TypeError):
print(f" [ERROR] Math function {func_name} failed with values: {arg1_val}, {arg2_val}")
return 0
# =============================================
# 2.1. Hàm xử lý list: $append(list, element)
# =============================================
append_match = re.match(r"^\$append\(([^,]+),\s*(.+)\)$", expr, re.DOTALL)
if append_match:
list_expr = append_match.group(1).strip()
element_expr = append_match.group(2).strip()
# 1. Resolve the list
target_list = resolve_value(list_expr, context)
if target_list is None:
target_list = []
# Ensure it's a copy so we don't modify the original context variable directly
target_list = list(target_list)
# 2. Resolve the element
resolved_element = resolve_value(element_expr, context)
if isinstance(resolved_element, str):
try:
import json
element_to_append = json.loads(resolved_element)
except json.JSONDecodeError:
element_to_append = resolved_element
else:
element_to_append = resolved_element
target_list.append(element_to_append)
return target_list
# =============================================
# 3. Helper: Lấy giá trị từ context theo đường dẫn dotted