Fix: ADD SWITCHER keyword registration - Change from custom_syntax to register_fn to match multiword conversion pattern - Allows ADD SWITCHER "x" as "y" to convert to add_switcher("x", "y")

This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2026-04-24 16:42:08 -03:00
parent 9f250e7428
commit ab97e2da5d
2 changed files with 21 additions and 28 deletions

View file

@ -84,31 +84,24 @@ pub fn clear_switchers_keyword(
}
pub fn add_switcher_keyword(
state: Arc<AppState>,
user_session: UserSession,
engine: &mut Engine,
state: Arc<AppState>,
user_session: UserSession,
engine: &mut Engine,
) {
let cache = state.cache.clone();
let cache = state.cache.clone();
let user_session_clone = user_session.clone();
engine
.register_custom_syntax(
["ADD_SWITCHER", "$expr$", "as", "$expr$"],
true,
move |context, inputs| {
let first_param = context.eval_expression_tree(&inputs[0])?.to_string();
let button_text = context.eval_expression_tree(&inputs[1])?.to_string();
add_switcher(
cache.as_ref(),
&user_session,
&first_param,
&button_text,
)?;
Ok(Dynamic::UNIT)
},
)
.expect("valid syntax registration");
engine
.register_fn("add_switcher", move |switcher_id: &str, button_text: &str| {
let result = add_switcher(
cache.as_ref(),
&user_session_clone,
switcher_id,
button_text,
);
result.map_err(|e| e.to_string())
})
.expect("valid function registration");
}
fn add_switcher(

View file

@ -1320,11 +1320,11 @@ pub fn convert_keywords_to_lowercase(script: &str) -> String {
(r#"CLEAR\s+WEBSITES"#, 0, 0, vec![]),
// ADD family - single-token keywords to avoid ADD conflicts
(r#"ADD_SUGGESTION_TOOL"#, 2, 2, vec!["tool", "text"]),
(r#"ADD_SUGGESTION_TEXT"#, 2, 2, vec!["value", "text"]),
(r#"ADD_SUGGESTION(?!\\s+TOOL|\\s+TEXT|_)"#, 2, 2, vec!["context", "text"]),
(r#"ADD_SWITCHER"#, 2, 2, vec!["switcher", "text"]),
(r#"ADD\\s+MEMBER"#, 2, 2, vec!["name", "role"]),
(r#"ADD_SUGGESTION_TOOL"#, 2, 2, vec!["tool", "text"]),
(r#"ADD_SUGGESTION_TEXT"#, 2, 2, vec!["value", "text"]),
(r#"ADD_SUGGESTION(?!\\s+TOOL|\\s+TEXT|_)"#, 2, 2, vec!["context", "text"]),
(r#"ADD\s+SWITCHER"#, 2, 2, vec!["switcher", "text"]),
(r#"ADD\\s+MEMBER"#, 2, 2, vec!["name", "role"]),
// CREATE family
(r#"CREATE\s+TASK"#, 1, 1, vec!["task"]),