Retain labels is actually either a boolean or a number.

This commit is contained in:
Tom Alexander
2023-10-04 15:43:09 -04:00
parent 301a6db83e
commit bcade66e68
4 changed files with 61 additions and 12 deletions

View File

@@ -38,6 +38,7 @@ use crate::types::ExportBlock;
use crate::types::LineNumber;
use crate::types::Object;
use crate::types::PlainText;
use crate::types::RetainLabels;
use crate::types::SrcBlock;
use crate::types::SwitchNumberLines;
use crate::types::VerseBlock;
@@ -168,7 +169,7 @@ pub(crate) fn example_block<'b, 'g, 'r, 's>(
parameters.label_format,
)
} else {
(None, None, None, true, None)
(None, None, RetainLabels::Yes, true, None)
}
};
Ok((
@@ -331,7 +332,7 @@ fn _lesser_block_begin<'b, 'g, 'r, 's, 'c>(
struct ExampleSwitches<'s> {
source: &'s str,
number_lines: Option<SwitchNumberLines>,
retain_labels: Option<CharOffsetInLine>,
retain_labels: RetainLabels,
use_labels: bool,
label_format: Option<&'s str>,
}
@@ -347,7 +348,7 @@ enum SwitchState {
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
fn example_switches<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, ExampleSwitches<'s>> {
let mut number_lines = None;
let mut retain_labels = None;
let mut retain_labels = RetainLabels::Yes;
let mut use_labels = true;
let mut label_format = None;
let (remaining, (source, (words, _))) =
@@ -366,6 +367,12 @@ fn example_switches<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, ExampleSwitc
}
(SwitchState::Normal, "-r") => {
use_labels = false;
match retain_labels {
RetainLabels::Yes => {
retain_labels = RetainLabels::No;
}
_ => {}
}
}
(SwitchState::Normal, "-l") => {
state = SwitchState::LabelFormat;
@@ -375,7 +382,7 @@ fn example_switches<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, ExampleSwitc
let character_offset = Into::<&str>::into(text_until_flag).chars().count();
let character_offset = CharOffsetInLine::try_from(character_offset)
.expect("Character offset should fit in CharOffsetInLine");
retain_labels = Some(character_offset);
retain_labels = RetainLabels::Keep(character_offset);
}
(SwitchState::NewLineNumber, _) => {
let val = normalized_word.parse::<LineNumber>();