Implement the radio link parser.
The parser depends on the rematch_target parser which is not yet implemented.
This commit is contained in:
parent
f3592347c1
commit
0014dfc21f
@ -7,6 +7,8 @@ use nom::multi::many_till;
|
||||
|
||||
use super::Context;
|
||||
use super::Object;
|
||||
use crate::error::CustomError;
|
||||
use crate::error::MyError;
|
||||
use crate::error::Res;
|
||||
use crate::parser::exiting::ExitClass;
|
||||
use crate::parser::object_parser::minimal_set_object;
|
||||
@ -15,14 +17,43 @@ use crate::parser::parser_context::ExitMatcherNode;
|
||||
use crate::parser::parser_with_context::parser_with_context;
|
||||
use crate::parser::util::exit_matcher_parser;
|
||||
use crate::parser::util::get_consumed;
|
||||
use crate::parser::util::not_yet_implemented;
|
||||
use crate::parser::RadioLink;
|
||||
use crate::parser::RadioTarget;
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn radio_link<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, RadioLink<'s>> {
|
||||
not_yet_implemented()?;
|
||||
todo!();
|
||||
let radio_targets = context
|
||||
.iter()
|
||||
.filter_map(|context_element| match context_element.get_data() {
|
||||
ContextElement::RadioTarget(targets) => Some(targets),
|
||||
_ => None,
|
||||
})
|
||||
.flatten();
|
||||
for radio_target in radio_targets {
|
||||
let rematched_target = rematch_target(context, radio_target, input);
|
||||
if let Ok((remaining, rematched_target)) = rematched_target {
|
||||
let source = get_consumed(input, remaining);
|
||||
return Ok((
|
||||
remaining,
|
||||
RadioLink {
|
||||
source,
|
||||
children: rematched_target,
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
||||
Err(nom::Err::Error(CustomError::MyError(MyError(
|
||||
"NoRadioLink",
|
||||
))))
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
pub fn rematch_target<'r, 's>(
|
||||
context: Context<'r, 's>,
|
||||
target: &'r Vec<Object<'s>>,
|
||||
input: &'s str,
|
||||
) -> Res<&'s str, Vec<Object<'s>>> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[tracing::instrument(ret, level = "debug")]
|
||||
|
Loading…
Reference in New Issue
Block a user