markdown_that/parser/core/
rule.rs1use crate::{MarkdownThat, Node};
2
3pub trait CoreRule: 'static {
5 fn run(root: &mut Node, md: &MarkdownThat);
6}
7
8macro_rules! rule_builder {
9 ($var: ident) => {
10 pub struct RuleBuilder<'a, T> {
12 item: &'a mut crate::common::ruler::RuleItem<crate::common::TypeKey, T>,
13 }
14
15 impl<'a, T> RuleBuilder<'a, T> {
16 pub(crate) fn new(
17 item: &'a mut crate::common::ruler::RuleItem<crate::common::TypeKey, T>,
18 ) -> Self {
19 Self { item }
20 }
21
22 pub fn before<U: $var>(self) -> Self {
23 self.item.before(crate::common::TypeKey::of::<U>());
24 self
25 }
26
27 pub fn after<U: $var>(self) -> Self {
28 self.item.after(crate::common::TypeKey::of::<U>());
29 self
30 }
31
32 pub fn before_all(self) -> Self {
33 self.item.before_all();
34 self
35 }
36
37 pub fn after_all(self) -> Self {
38 self.item.after_all();
39 self
40 }
41
42 pub fn alias<U: $var>(self) -> Self {
43 self.item.alias(crate::common::TypeKey::of::<U>());
44 self
45 }
46
47 pub fn require<U: $var>(self) -> Self {
48 self.item.require(crate::common::TypeKey::of::<U>());
49 self
50 }
51 }
52 };
53}
54
55rule_builder!(CoreRule);
56
57pub(crate) use rule_builder;