use super::*;
use df_ls_diagnostics::DiagnosticsInfo;
pub(crate) fn tokenize_token_argument_pipe_arguments(
tok_help: &mut TokenizerHelper,
regex_list: &RegexList,
diagnostics: &mut DiagnosticsInfo,
token_arguments_id: u64,
) -> TokenizerResult {
let token_pipe_arguments = tok_help.create_start_tsnode(
"token_argument_pipe_arguments",
Some("token_argument_pipe_arguments"),
);
let token_pipe_arguments_id = token_pipe_arguments.id;
tok_help.add_node_to_tree(token_pipe_arguments, token_arguments_id);
let mut allow_add_empty = true;
loop {
if tok_help.check_if_next_char_matches_any_of(&[':', ']', '\n', '\r']) {
break;
}
let separator =
tok_help.get_next_match(®ex_list.token_pipe_separator, "|", None, true, true);
match separator {
TokenMatchStatus::Ok(result) => {
if allow_add_empty {
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_pipe_arguments_id);
}
tok_help.add_node_to_tree(result, token_pipe_arguments_id);
allow_add_empty = true;
}
TokenMatchStatus::OkWithPrefixFound(_prefix, _result) => {
unreachable!("Match is optional");
}
TokenMatchStatus::NoMatch => {
}
TokenMatchStatus::EoF => {
tok_help.set_end_point_for(token_pipe_arguments_id);
return TokenizerResult::Err(TokenizerEnd::UnexpectedEoF);
}
}
if tok_help.check_if_next_char_matches_any_of(&[':', '[', ']', '\n', '\r']) {
if allow_add_empty {
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_pipe_arguments_id);
}
break;
}
if tok_help.check_if_next_char_match('|') {
continue;
}
let found_token_argument = token_argument::tokenize_token_argument(
tok_help,
regex_list,
diagnostics,
token_pipe_arguments_id,
false,
);
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_pipe_arguments_id);
tok_help.set_end_point_for(token_pipe_arguments_id);
return TokenizerResult::Err(TokenizerEnd::UnexpectedEoF);
}
allow_add_empty = false;
}
tok_help.set_end_point_for(token_pipe_arguments_id);
Ok(())
}