Fix handling cases where only language is specified before parameters.

This commit is contained in:
Tom Alexander 2023-10-04 18:11:38 -04:00
parent f046b16c11
commit 8e70773b15
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -15,9 +15,9 @@ use nom::combinator::peek;
use nom::combinator::recognize;
use nom::combinator::verify;
use nom::multi::many_till;
use nom::multi::separated_list0;
use nom::multi::separated_list1;
use nom::sequence::tuple;
use nom::InputTake;
use super::org_source::OrgSource;
use crate::context::parser_with_context;
@ -425,13 +425,18 @@ fn _example_src_switches<'s>(
let (remaining, (source, words)) = if language.is_none() {
consumed(separated_list1(space1, switch_word(stop_at_parameters)))(remaining)?
} else {
map(
let (remain, maybe_words) = opt(map(
tuple((
space1,
consumed(separated_list0(space1, switch_word(stop_at_parameters))),
consumed(separated_list1(space1, switch_word(stop_at_parameters))),
)),
|(_, words)| words,
)(remaining)?
))(remaining)?;
if let Some((source, words)) = maybe_words {
(remain, (source, words))
} else {
(remain, (remaining.take(0), Vec::new()))
}
};
let mut state = SwitchState::Normal;