summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2022-01-24 19:48:19 +0200
committerLars Wirzenius <liw@liw.fi>2022-01-26 19:08:00 +0200
commitf285f652c39db1b8e51eee9a499fadec7b0bec91 (patch)
tree554a73ac2f112c8a34f58b3f8bae8dcfb1000345 /src
parent43f72bf660ade91c08e09d62923c2d4635fb8e16 (diff)
downloadsubplot-f285f652c39db1b8e51eee9a499fadec7b0bec91.tar.gz
feat: automatically use "and" on output
This changes typesetting of scenarios so that when two adjacent scenario steps have the same keyword, "and" is used on the second one. This means that when input has when I do foo when I do bar the output will have when I do foo and I do bar I didn't bother to make this configurable. I don't feel that level of configuration is good. The "keyword aliases" scenario is repurposed to verify this. Sponsored-by: author
Diffstat (limited to 'src')
-rw-r--r--src/typeset.rs26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/typeset.rs b/src/typeset.rs
index 2bd1fd2..c6301e4 100644
--- a/src/typeset.rs
+++ b/src/typeset.rs
@@ -70,13 +70,13 @@ pub fn scenario_snippet(bindings: &Bindings, snippet: &str) -> Block {
fn step(
bindings: &Bindings,
text: &str,
- defkind: Option<StepKind>,
+ prevkind: Option<StepKind>,
) -> (Vec<Inline>, Option<StepKind>) {
- let step = ScenarioStep::new_from_str(text, defkind);
+ let step = ScenarioStep::new_from_str(text, prevkind);
if step.is_err() {
return (
error_msg(&format!("Could not parse step: {}", text)),
- defkind,
+ prevkind,
);
}
let step = step.unwrap();
@@ -87,12 +87,12 @@ fn step(
eprintln!("Could not select binding: {:?}", e);
return (
error_msg(&format!("Could not select binding for: {}", text)),
- defkind,
+ prevkind,
);
}
};
- let mut inlines = vec![keyword(&step), space()];
+ let mut inlines = vec![keyword(&step, prevkind), space()];
for part in m.parts() {
match part {
@@ -106,9 +106,19 @@ fn step(
// Typeset first word, which is assumed to be a keyword, of a scenario
// step.
-fn keyword(step: &ScenarioStep) -> Inline {
- let word = inlinestr(step.keyword());
- Inline::Emph(vec![word])
+fn keyword(step: &ScenarioStep, prevkind: Option<StepKind>) -> Inline {
+ let actual = inlinestr(&format!("{}", step.kind()));
+ let and = inlinestr("and");
+ let keyword = if let Some(prevkind) = prevkind {
+ if prevkind == step.kind() {
+ and
+ } else {
+ actual
+ }
+ } else {
+ actual
+ };
+ Inline::Emph(vec![keyword])
}
// Typeset a space between words.