Skip to content

Commit bb5862e

Browse files
committed
Some minor cleanup
Just some stylistic changes.
1 parent 5c3183e commit bb5862e

File tree

5 files changed

+15
-22
lines changed

5 files changed

+15
-22
lines changed

mdbook-spec/src/grammar.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,13 @@ impl Expression {
106106
| ExpressionKind::RepeatPlus(e)
107107
| ExpressionKind::RepeatPlusNonGreedy(e)
108108
| ExpressionKind::RepeatRange(e, _, _)
109-
| ExpressionKind::NegExpression(e) => {
110-
e.visit_nt(callback);
111-
}
109+
| ExpressionKind::NegExpression(e) => e.visit_nt(callback),
112110
ExpressionKind::Alt(es) | ExpressionKind::Sequence(es) => {
113111
for e in es {
114112
e.visit_nt(callback);
115113
}
116114
}
117-
ExpressionKind::Nt(nt) => {
118-
callback(&nt);
119-
}
115+
ExpressionKind::Nt(nt) => callback(nt),
120116
ExpressionKind::Terminal(_)
121117
| ExpressionKind::Prose(_)
122118
| ExpressionKind::Break(_)
@@ -314,7 +310,7 @@ fn render_names(
314310
let railroad_link_map = updated_link_map(render_railroad::railroad_id);
315311

316312
if let Err(e) = grammar.render_markdown(
317-
&names,
313+
names,
318314
&markdown_link_map,
319315
&railroad_link_map,
320316
&mut output,
@@ -340,7 +336,7 @@ fn render_names(
340336
);
341337

342338
if let Err(e) = grammar.render_railroad(
343-
&names,
339+
names,
344340
&railroad_link_map,
345341
&markdown_link_map,
346342
&mut output,

mdbook-spec/src/grammar/parser.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ impl Parser<'_> {
6565
fn take_while(&mut self, f: &dyn Fn(char) -> bool) -> &str {
6666
let mut upper = 0;
6767
let i = self.index;
68-
let mut ci = self.input[i..].chars();
69-
while let Some(ch) = ci.next() {
68+
for ch in self.input[i..].chars() {
7069
if !f(ch) {
7170
break;
7271
}

mdbook-spec/src/grammar/render_markdown.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ impl Grammar {
1818
output: &mut String,
1919
for_summary: bool,
2020
) -> anyhow::Result<()> {
21-
let mut iter = names.into_iter().peekable();
21+
let mut iter = names.iter().peekable();
2222
while let Some(name) = iter.next() {
2323
let Some(prod) = self.productions.get(*name) else {
2424
bail!("could not find grammar production named `{name}`");
2525
};
2626
prod.render_markdown(link_map, rr_link_map, output, for_summary);
2727
if iter.peek().is_some() {
28-
output.push_str("\n");
28+
output.push('\n');
2929
}
3030
}
3131
Ok(())
@@ -52,7 +52,7 @@ impl Production {
5252
let dest = rr_link_map
5353
.get(&self.name)
5454
.map(|path| path.to_string())
55-
.unwrap_or_else(|| format!("missing"));
55+
.unwrap_or_else(|| "missing".to_string());
5656
write!(
5757
output,
5858
"<span class=\"grammar-text grammar-production\" id=\"{id}\" \

mdbook-spec/src/grammar/render_railroad.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Production {
7575
let dest = md_link_map
7676
.get(&self.name)
7777
.map(|path| path.to_string())
78-
.unwrap_or_else(|| format!("missing"));
78+
.unwrap_or_else(|| "missing".to_string());
7979
let seq: Sequence<Box<dyn Node>> =
8080
Sequence::new(vec![Box::new(SimpleStart), n.unwrap(), Box::new(SimpleEnd)]);
8181
let vert = VerticalGrid::<Box<dyn Node>>::new(vec![
@@ -105,7 +105,7 @@ impl Expression {
105105
let choices: Vec<_> = es
106106
.iter()
107107
.map(|e| e.render_railroad(stack, link_map))
108-
.filter_map(|n| n)
108+
.flatten()
109109
.collect();
110110
Box::new(Choice::<Box<dyn Node>>::new(choices))
111111
}
@@ -115,7 +115,7 @@ impl Expression {
115115
let seq: Vec<_> = es
116116
.iter()
117117
.map(|e| e.render_railroad(stack, link_map))
118-
.filter_map(|n| n)
118+
.flatten()
119119
.collect();
120120
let seq: Sequence<Box<dyn Node>> = Sequence::new(seq);
121121
Box::new(seq)
@@ -138,11 +138,10 @@ impl Expression {
138138
) {
139139
&es[..es.len() - 1]
140140
} else {
141-
&es[..]
141+
es
142142
};
143143

144-
let mut breaks: Vec<_> =
145-
es.split(|e| e.is_break()).map(|es| make_seq(es)).collect();
144+
let mut breaks: Vec<_> = es.split(|e| e.is_break()).map(&make_seq).collect();
146145
// If there aren't any breaks, don't bother stacking.
147146
if breaks.len() == 1 {
148147
breaks.pop().unwrap()
@@ -229,7 +228,7 @@ fn node_for_nt(link_map: &HashMap<String, String>, name: &str) -> Box<dyn Node>
229228
let dest = link_map
230229
.get(name)
231230
.map(|path| path.to_string())
232-
.unwrap_or_else(|| format!("missing"));
231+
.unwrap_or_else(|| "missing".to_string());
233232
let n = NonTerminal::new(name.to_string());
234233
Box::new(Link::new(n, dest))
235234
}

mdbook-spec/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ impl Spec {
188188
let blockquote = &caps["blockquote"];
189189
let initial_spaces = blockquote.chars().position(|ch| ch != ' ').unwrap_or(0);
190190
let space = &blockquote[..initial_spaces];
191-
if lower.starts_with("edition-") {
192-
let edition = &lower[8..];
191+
if let Some(edition) = lower.strip_prefix("edition-") {
193192
return format!("{space}<div class=\"alert alert-edition\">\n\
194193
\n\
195194
{space}> <p class=\"alert-title\">\

0 commit comments

Comments
 (0)