Skip to content

Commit

Permalink
Merge pull request #15 from Lurk/message
Browse files Browse the repository at this point in the history
Message node and pattern state machine overhaul.
  • Loading branch information
Lurk authored Jul 9, 2023
2 parents 0a46e26 + 2f23f0e commit 90a333d
Show file tree
Hide file tree
Showing 24 changed files with 760 additions and 269 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yamd"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "Yet Another Markdown (flavor)"
Expand Down
5 changes: 1 addition & 4 deletions src/nodes/anchor.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use crate::{
toolkit::context::Context,
toolkit::deserializer::Deserializer,
toolkit::{
node::Node,
tokenizer::{Matcher, Quantifiers::Once},
},
toolkit::{matcher::Matcher, node::Node, pattern::Quantifiers::*},
};

/// Representation of an anchor
Expand Down
3 changes: 2 additions & 1 deletion src/nodes/bold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use crate::{
toolkit::{
context::Context,
deserializer::{Branch, DefinitelyNode, Deserializer, MaybeNode},
matcher::Matcher,
node::Node,
tokenizer::{Matcher, Quantifiers::Once},
pattern::Quantifiers::*,
},
};

Expand Down
9 changes: 2 additions & 7 deletions src/nodes/code.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
use crate::toolkit::{
context::Context,
deserializer::Deserializer,
node::Node,
tokenizer::{
Matcher,
Quantifiers::{Once, RepeatTimes},
},
context::Context, deserializer::Deserializer, matcher::Matcher, node::Node,
pattern::Quantifiers::*,
};

#[derive(Debug, PartialEq)]
Expand Down
6 changes: 2 additions & 4 deletions src/nodes/divider.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::toolkit::{
context::Context,
deserializer::Deserializer,
node::Node,
tokenizer::{Matcher, Quantifiers::RepeatTimes},
context::Context, deserializer::Deserializer, matcher::Matcher, node::Node,
pattern::Quantifiers::*,
};

#[derive(Debug, PartialEq)]
Expand Down
4 changes: 1 addition & 3 deletions src/nodes/embed.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::toolkit::{
deserializer::Deserializer,
node::Node,
tokenizer::{Matcher, Quantifiers::RepeatTimes},
deserializer::Deserializer, matcher::Matcher, node::Node, pattern::Quantifiers::*,
};

#[derive(Debug, PartialEq)]
Expand Down
18 changes: 8 additions & 10 deletions src/nodes/heading.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::toolkit::{
context::Context,
deserializer::Deserializer,
node::Node,
tokenizer::{Matcher, Quantifiers::Once, Quantifiers::RepeatTimes},
context::Context, deserializer::Deserializer, matcher::Matcher, node::Node,
pattern::Quantifiers::*,
};

#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -30,20 +28,20 @@ impl Heading {
impl Deserializer for Heading {
fn deserialize_with_context(input: &str, _: Option<Context>) -> Option<Self> {
let start_tokens = [
[Once('#'), Once(' ')],
[RepeatTimes(2, '#'), Once(' ')],
[RepeatTimes(3, '#'), Once(' ')],
[RepeatTimes(4, '#'), Once(' ')],
[RepeatTimes(5, '#'), Once(' ')],
[RepeatTimes(6, '#'), Once(' ')],
[RepeatTimes(5, '#'), Once(' ')],
[RepeatTimes(4, '#'), Once(' ')],
[RepeatTimes(3, '#'), Once(' ')],
[RepeatTimes(2, '#'), Once(' ')],
[Once('#'), Once(' ')],
];

for (i, start_token) in start_tokens.iter().enumerate() {
let mut matcher = Matcher::new(input);
if let Some(heading) = matcher.get_match(start_token, &[RepeatTimes(2, '\n')], true) {
return Some(Self::new(
heading.body,
(i + 1).try_into().unwrap_or(1),
(start_tokens.len() - i).try_into().unwrap_or(1),
heading.end_token.is_empty(),
));
}
Expand Down
6 changes: 2 additions & 4 deletions src/nodes/highlight.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use crate::toolkit::{
context::Context,
deserializer::{Branch, DefinitelyNode, Deserializer, MaybeNode},
matcher::Matcher,
node::Node,
tokenizer::{
Matcher,
Quantifiers::{Once, RepeatTimes},
},
pattern::Quantifiers::*,
};

use super::paragraph::Paragraph;
Expand Down
6 changes: 2 additions & 4 deletions src/nodes/image.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::toolkit::{
context::Context,
deserializer::Deserializer,
node::Node,
tokenizer::{Matcher, Quantifiers::Once},
context::Context, deserializer::Deserializer, matcher::Matcher, node::Node,
pattern::Quantifiers::*,
};

#[derive(Debug, PartialEq)]
Expand Down
6 changes: 2 additions & 4 deletions src/nodes/image_gallery.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use crate::toolkit::{
context::Context,
deserializer::{Branch, DefinitelyNode, Deserializer, MaybeNode},
matcher::Matcher,
node::Node,
tokenizer::{
Matcher,
Quantifiers::{Once, RepeatTimes},
},
pattern::Quantifiers::*,
};

use super::image::Image;
Expand Down
7 changes: 3 additions & 4 deletions src/nodes/inline_code.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{
toolkit::context::Context,
toolkit::tokenizer::{Matcher, Quantifiers::Once},
toolkit::{deserializer::Deserializer, node::Node},
use crate::toolkit::{
context::Context, deserializer::Deserializer, matcher::Matcher, node::Node,
pattern::Quantifiers::*,
};

#[derive(Debug, PartialEq)]
Expand Down
5 changes: 1 addition & 4 deletions src/nodes/italic.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use crate::{
toolkit::{context::Context, deserializer::Deserializer},
toolkit::{
node::Node,
tokenizer::{Matcher, Quantifiers::Once},
},
toolkit::{matcher::Matcher, node::Node, pattern::Quantifiers::*},
};

/// Representation of an Italic text
Expand Down
6 changes: 2 additions & 4 deletions src/nodes/list.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use crate::toolkit::{
context::Context,
deserializer::{Branch, DefinitelyNode, Deserializer, MaybeNode},
matcher::Matcher,
node::Node,
tokenizer::{
Matcher,
Quantifiers::{Once, RepeatTimes, ZeroOrMore},
},
pattern::Quantifiers::*,
};

use super::list_item::ListItem;
Expand Down
6 changes: 2 additions & 4 deletions src/nodes/list_item.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use crate::toolkit::{
context::Context,
deserializer::{Branch, DefinitelyNode, Deserializer, FallbackNode, MaybeNode},
matcher::Matcher,
node::Node,
tokenizer::{
Matcher,
Quantifiers::{Once, RepeatTimes, ZeroOrMore},
},
pattern::Quantifiers::*,
};

use super::{
Expand Down
Loading

0 comments on commit 90a333d

Please sign in to comment.