From 2c1a9be38e14a75cada143a8305e4c9aab9a7bdf Mon Sep 17 00:00:00 2001 From: boris Date: Fri, 17 Jul 2026 08:33:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B5=8C=E5=A5=97=E4=B8=89?= =?UTF-8?q?=E5=85=83=E8=A1=A8=E8=BE=BE=E5=BC=8F=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fidc-core/src/platform_expr_strategy.rs | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/crates/fidc-core/src/platform_expr_strategy.rs b/crates/fidc-core/src/platform_expr_strategy.rs index d06ceee..ccf1bd6 100644 --- a/crates/fidc-core/src/platform_expr_strategy.rs +++ b/crates/fidc-core/src/platform_expr_strategy.rs @@ -5851,7 +5851,10 @@ impl PlatformExprStrategy { '}' => brace_depth -= 1, '[' => bracket_depth += 1, ']' => bracket_depth -= 1, - ',' if paren_depth == 0 && brace_depth == 0 && bracket_depth == 0 => { + ',' if paren_depth == ternary_paren_depth + && brace_depth == 0 + && bracket_depth == 0 => + { start = idx + ch.len_utf8(); } _ => {} @@ -10432,6 +10435,33 @@ mod tests { assert!(!rewritten.contains('?')); } + #[test] + fn platform_expr_rewrites_multiple_nested_ternaries_inside_function_calls() { + let expr = r#"min( + rolling_mean_current("signal_close", 10) > rolling_mean_current("signal_close", 30) + ? 1.0 + : 0.3, + min( + rolling_return_stddev_current("signal_close", 20) >= 0.025 + ? 0.3 + : 1.0, + 1.0 - safe_div( + day_factor("signal_close"), + rolling_max_current("signal_close", 60) + ) >= 0.08 + ? 0.2 + : 1.0 + ) + )"#; + let rewritten = PlatformExprStrategy::normalize_expr(expr); + + assert!(!rewritten.contains('?'), "{rewritten}"); + PlatformExprStrategy::new(PlatformExprStrategyConfig::microcap_rotation()) + .engine + .compile(&rewritten) + .unwrap_or_else(|error| panic!("rewritten expression must compile: {error}\n{rewritten}")); + } + #[test] fn platform_expr_safe_div_supports_two_and_three_arg_forms() { let strategy = PlatformExprStrategy::new(PlatformExprStrategyConfig::microcap_rotation());