@@ 124,6 124,17 @@ pub enum InlineTag {
},
}
+impl InlineTag {
+ fn parsers() -> &'static [for<'r> fn(
+ &'r str,
+ ) -> Result<
+ (&'r str, InlineTag),
+ nom::Err<nom::error::Error<&'r str>>,
+ >] {
+ &[line_break, no_textile, code, footnote_ref, link, image]
+ }
+}
+
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum PhraseKind {
Italic,
@@ 140,32 151,34 @@ pub enum PhraseKind {
impl PhraseKind {
fn list() -> &'static [PhraseKind] {
+ use PhraseKind::*;
&[
- PhraseKind::Italic,
- PhraseKind::Bold,
- PhraseKind::Emphasis,
- PhraseKind::Strong,
- PhraseKind::Citation,
- PhraseKind::Deleted,
- PhraseKind::Inserted,
- PhraseKind::Superscript,
- PhraseKind::Subscript,
- PhraseKind::Span,
+ Italic,
+ Bold,
+ Emphasis,
+ Strong,
+ Citation,
+ Deleted,
+ Inserted,
+ Superscript,
+ Subscript,
+ Span,
]
}
fn delimiter(self, input: &str) -> IResult<&str, &str> {
+ use PhraseKind::*;
match self {
- PhraseKind::Italic => tag("__")(input),
- PhraseKind::Bold => tag("**")(input),
- PhraseKind::Emphasis => tag("_")(input),
- PhraseKind::Strong => tag("*")(input),
- PhraseKind::Citation => tag("??")(input),
- PhraseKind::Deleted => tag("#")(input),
- PhraseKind::Inserted => tag("+")(input),
- PhraseKind::Superscript => tag("^")(input),
- PhraseKind::Subscript => tag("~")(input),
- PhraseKind::Span => tag("%")(input),
+ Italic => tag("__")(input),
+ Bold => tag("**")(input),
+ Emphasis => tag("_")(input),
+ Strong => tag("*")(input),
+ Citation => tag("??")(input),
+ Deleted => tag("#")(input),
+ Inserted => tag("+")(input),
+ Superscript => tag("^")(input),
+ Subscript => tag("~")(input),
+ Span => tag("%")(input),
}
}
}
@@ 524,9 537,7 @@ pub fn phrase(input: &str) -> IResult<&str, InlineTag> {
}
}
if matched.is_none() {
- for parser in
- [line_break, no_textile, code, footnote_ref, link, image]
- {
+ for parser in InlineTag::parsers() {
if let Ok((rest, tag)) = parser(&input[i..]) {
matched = Some((rest, tag));
break;
@@ 603,9 614,7 @@ fn tagged_phrase(
}
}
if matched.is_none() {
- for parser in
- [line_break, no_textile, code, footnote_ref, link, image]
- {
+ for parser in InlineTag::parsers() {
if let Ok((rest, tag)) = parser(&input[i..]) {
matched = Some((rest, tag));
break;