Merge remote-tracking branch 'origin/sub_laptop_1' into sub_laptop_2

This commit is contained in:
2026-09-19 16:21:08 +09:00
4 changed files with 1756 additions and 13 deletions
@@ -20,6 +20,7 @@ _NAME = re.compile(r"[\w가-힣]+")
_NUMBER = re.compile(r"\d+(?:\.\d+)?")
_HOLE = re.compile(r"\{([^{}]+)\}")
_OPS = ("<=", ">=", "==", "!=", "<", ">")
_ARITH = re.compile(r"[\d.\s+\-*/()]*\d[\d.\s+\-*/()]*") # 분수·식 값 칸(「1/1.30」)
class FormulaError(ValueError):
@@ -250,9 +251,12 @@ def _match(table: dict, row: dict, cond: str, want) -> bool:
have = row[cond]
if table.get("조건", {}).get(cond) == "범위":
low, high = have
if table.get("범위규칙", "초과·이하") != "초과·이하":
raise FormulaError(f"모르는 범위규칙 「{table.get('범위규칙')}")
return (low is None or want > low) and (high is None or want <= high)
rule = table.get("범위규칙", "초과·이하").split(" · ")[0]
if rule == "초과·이하":
return (low is None or want > low) and (high is None or want <= high)
if rule == "이상·미만":
return (low is None or want >= low) and (high is None or want < high)
raise FormulaError(f"모르는 범위규칙 「{table.get('범위규칙')}")
return have == want
@@ -286,6 +290,8 @@ def evaluate(node, env: dict, master: Master, depth: int = 0):
value = base[node[2]]
if isinstance(value, list):
raise FormulaError(f"칸 「{node[2]}」 값이 범위 — 입력으로 받아야 함")
if isinstance(value, str) and _ARITH.fullmatch(value):
return evaluate(parse(value), env, master, depth)
return value
if kind == "neg":
return -evaluate(node[1], env, master, depth)