use super::*;
use df_ls_diagnostics::DiagnosticsInfo;
pub(crate) fn tokenize_token_arguments(
tok_help: &mut TokenizerHelper,
regex_list: &RegexList,
diagnostics: &mut DiagnosticsInfo,
token_id: u64,
) -> TokenizerResult {
let token_arguments = tok_help.create_start_tsnode("token_arguments", Some("token_arguments"));
let token_arguments_id = token_arguments.id;
let mut token_arguments_added = false;
loop {
if tok_help.check_if_next_char_matches_any_of(&[']', '\n', '\r']) {
break;
}
let separator = tok_help.get_next_match(®ex_list.token_separator, ":", None, true, true);
match separator {
TokenMatchStatus::Ok(result) => {
if !token_arguments_added {
token_arguments_added = true;
tok_help.add_node_to_tree(token_arguments.clone(), token_id);
}
tok_help.add_node_to_tree(result, token_arguments_id);
}
TokenMatchStatus::OkWithPrefixFound(_prefix, _result) => {
unreachable!("Match is optional");
}
TokenMatchStatus::NoMatch => break, TokenMatchStatus::EoF => {
if token_arguments_added {
tok_help.set_end_point_for(token_arguments_id);
}
return TokenizerResult::Err(TokenizerEnd::UnexpectedEoF);
}
}
if tok_help.check_if_next_char_matches_any_of(&['[', ']', '\n', '\r']) {
let token_argument_empty =
tok_help.create_start_tsnode("token_argument_empty", Some("token_argument_empty"));
tok_help.add_node_to_tree(token_argument_empty, token_arguments_id);
break;
}
if tok_help.check_if_next_char_match(':') {
let token_argument_empty =
tok_help.create_start_tsnode("token_argument_empty", Some("token_argument_empty"));
tok_help.add_node_to_tree(token_argument_empty, token_arguments_id);
continue;
}
let found_token_argument = token_argument::tokenize_token_argument(
tok_help,
regex_list,
diagnostics,
token_arguments_id,
true,
);
if found_token_argument.is_err() {
let token_argument_empty =
tok_help.create_start_tsnode("token_argument_empty", Some("token_argument_empty"));
tok_help.add_node_to_tree(token_argument_empty, token_arguments_id);
tok_help.set_end_point_for(token_arguments_id);
return TokenizerResult::Err(TokenizerEnd::UnexpectedEoF);
}
}
tok_help.set_end_point_for(token_arguments_id);
Ok(())
}