aboutsummaryrefslogtreecommitdiffstats
path: root/src/tokenizer.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-21 15:32:48 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-21 15:32:53 +0200
commit2d0dfe66d423e707b7de60d9bde0cec7933580fe (patch)
treeddbe9729046c740b07e656920fa991c475983046 /src/tokenizer.rs
parent75c2109c6051009b220436bd823970a374f4f9fd (diff)
downloadmarkdown-rs-2d0dfe66d423e707b7de60d9bde0cec7933580fe.tar.gz
markdown-rs-2d0dfe66d423e707b7de60d9bde0cec7933580fe.tar.bz2
markdown-rs-2d0dfe66d423e707b7de60d9bde0cec7933580fe.zip
Refactor to move some event fields to `link`
Diffstat (limited to 'src/tokenizer.rs')
-rw-r--r--src/tokenizer.rs35
1 files changed, 24 insertions, 11 deletions
diff --git a/src/tokenizer.rs b/src/tokenizer.rs
index 5d03c92..b745ac8 100644
--- a/src/tokenizer.rs
+++ b/src/tokenizer.rs
@@ -66,6 +66,14 @@ pub enum EventType {
Exit,
}
+/// A link to another event.
+#[derive(Debug, Clone)]
+pub struct Link {
+ pub previous: Option<usize>,
+ pub next: Option<usize>,
+ pub content_type: ContentType,
+}
+
/// Something semantic happening somewhere.
#[derive(Debug, Clone)]
pub struct Event {
@@ -73,9 +81,7 @@ pub struct Event {
pub token_type: Token,
pub point: Point,
pub index: usize,
- pub previous: Option<usize>,
- pub next: Option<usize>,
- pub content_type: Option<ContentType>,
+ pub link: Option<Link>,
}
/// The essence of the state machine are functions: `StateFn`.
@@ -357,19 +363,28 @@ impl<'a> Tokenizer<'a> {
/// Mark the start of a semantic label.
pub fn enter(&mut self, token_type: Token) {
- self.enter_with_content(token_type, None);
+ self.enter_with_link(token_type, None);
+ }
+
+ pub fn enter_with_content(&mut self, token_type: Token, content_type_opt: Option<ContentType>) {
+ self.enter_with_link(
+ token_type,
+ content_type_opt.map(|content_type| Link {
+ content_type,
+ previous: None,
+ next: None,
+ }),
+ );
}
- pub fn enter_with_content(&mut self, token_type: Token, content_type: Option<ContentType>) {
+ pub fn enter_with_link(&mut self, token_type: Token, link: Option<Link>) {
log::debug!("enter: `{:?}` ({:?})", token_type, self.point);
self.events.push(Event {
event_type: EventType::Enter,
token_type: token_type.clone(),
point: self.point.clone(),
index: self.index,
- previous: None,
- next: None,
- content_type,
+ link,
});
self.stack.push(token_type);
}
@@ -423,9 +438,7 @@ impl<'a> Tokenizer<'a> {
token_type,
point,
index,
- previous: None,
- next: None,
- content_type: None,
+ link: None,
});
}