修复嵌套三元表达式解析
This commit is contained in:
@@ -5851,7 +5851,10 @@ impl PlatformExprStrategy {
|
|||||||
'}' => brace_depth -= 1,
|
'}' => brace_depth -= 1,
|
||||||
'[' => bracket_depth += 1,
|
'[' => bracket_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();
|
start = idx + ch.len_utf8();
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@@ -10432,6 +10435,33 @@ mod tests {
|
|||||||
assert!(!rewritten.contains('?'));
|
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]
|
#[test]
|
||||||
fn platform_expr_safe_div_supports_two_and_three_arg_forms() {
|
fn platform_expr_safe_div_supports_two_and_three_arg_forms() {
|
||||||
let strategy = PlatformExprStrategy::new(PlatformExprStrategyConfig::microcap_rotation());
|
let strategy = PlatformExprStrategy::new(PlatformExprStrategyConfig::microcap_rotation());
|
||||||
|
|||||||
Reference in New Issue
Block a user