Build a function 'f(...)' where '...' can be empty Also handles nested functions like f(...)(...) Start state: at '(' End state: after ')'
(
function_name: Element<'m>,
rules_with_context: &'r mut SpeechRulesWithContext<'c,'s,'m>,
lex_state: &mut LexState<'b>,
mathml: Element<'c>)
| 298 | /// |
| 299 | /// End state: after ')' |
| 300 | fn build_function<'b, 'r, 'c, 's:'c, 'm:'c>( |
| 301 | function_name: Element<'m>, |
| 302 | rules_with_context: &'r mut SpeechRulesWithContext<'c,'s,'m>, |
| 303 | lex_state: &mut LexState<'b>, |
| 304 | mathml: Element<'c>) -> Result<Element<'m>> { |
| 305 | // debug!(" start build_function: name: {}, state: {}", name(&function_name), lex_state); |
| 306 | // application := intent '(' arguments? S ')' where 'function_name' is 'intent' |
| 307 | assert!(lex_state.is_terminal("(")); |
| 308 | let mut function = function_name; |
| 309 | while lex_state.is_terminal("(") { |
| 310 | lex_state.get_next()?; |
| 311 | if lex_state.is_terminal(")") { |
| 312 | // grammar requires at least one argument |
| 313 | bail!("Illegal 'intent' syntax: missing argument for intent name '{}'", name(&function_name)); |
| 314 | } |
| 315 | let children = build_arguments(rules_with_context, lex_state, mathml)?; |
| 316 | function = lift_function_name(rules_with_context.get_document(), function, children); |
| 317 | |
| 318 | if !lex_state.is_terminal(")") { |
| 319 | bail!("Illegal 'intent' syntax: missing ')' for intent name '{}'", name(&function_name)); |
| 320 | } |
| 321 | lex_state.get_next()?; |
| 322 | } |
| 323 | // debug!(" end build_function/# children: {}, #state: {} ..[bfa] function name: {}", |
| 324 | // function.children().len(), lex_state, mml_to_string(&function)); |
| 325 | return Ok(function); |
| 326 | } |
| 327 | |
| 328 | // process all the args of a function |
| 329 | // Start state: after '(' |
no test coverage detected