Skip to content

Commit

Permalink
fix: convert carryover tag contents
Browse files Browse the repository at this point in the history
  • Loading branch information
benlubas committed Oct 13, 2024
1 parent d3d420a commit eabde9a
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 45 deletions.
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,19 @@ mod tests {
---- four
#id 3
--- three
",
"
#comment
multi-line
comments
---
out
",
"
#id 123
#comment
comment with id
",
]
.into_iter()
.map(|example| example.to_string() + "\n")
Expand Down
42 changes: 42 additions & 0 deletions src/snapshots/rust_norg__tests__carryover_tags_tree.snap
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,45 @@ expression: examples
- Token:
Text: three
content: []
- - CarryoverTag:
tag_type: Macro
name:
- comment
parameters: []
next_object:
Paragraph:
- Token:
Text: multi
- Token:
Special: "-"
- Token:
Text: line
- Token: Whitespace
- Token:
Text: comments
- DelimitingModifier: Weak
- Paragraph:
- Token:
Text: out
- - CarryoverTag:
tag_type: Macro
name:
- id
parameters:
- "123"
next_object:
CarryoverTag:
tag_type: Macro
name:
- comment
parameters: []
next_object:
Paragraph:
- Token:
Text: comment
- Token: Whitespace
- Token:
Text: with
- Token: Whitespace
- Token:
Text: id
81 changes: 36 additions & 45 deletions src/stage_4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use serde::Serialize;

use crate::{
stage_3::{DelimitingModifier, NorgASTFlat, ParagraphSegment},
CarryoverTag, DetachedModifierExtension, NestableDetachedModifier,
RangeableDetachedModifier,
CarryoverTag, DetachedModifierExtension, NestableDetachedModifier, RangeableDetachedModifier,
};

#[derive(Debug, PartialEq, Eq, Clone, Hash, Serialize)]
Expand Down Expand Up @@ -54,18 +53,6 @@ pub enum NorgAST {
fn convert(flat: NorgASTFlat) -> NorgAST {
match flat {
NorgASTFlat::Paragraph(tokens) => NorgAST::Paragraph(tokens),
NorgASTFlat::NestableDetachedModifier {
modifier_type,
level,
extensions,
content,
} => NorgAST::NestableDetachedModifier {
modifier_type,
level,
extensions,
text: content,
content: vec![],
},
NorgASTFlat::RangeableDetachedModifier {
modifier_type,
title,
Expand All @@ -77,28 +64,6 @@ fn convert(flat: NorgASTFlat) -> NorgAST {
extensions,
content,
},
NorgASTFlat::Heading {
level,
title,
extensions,
} => NorgAST::Heading {
level,
title,
extensions,
content: vec![],
},
NorgASTFlat::CarryoverTag {
tag_type,
name,
parameters,
..
} => NorgAST::CarryoverTag {
// really, this case should not be reached, we might want to panic here
tag_type,
name,
parameters,
next_object: Box::new(NorgAST::Paragraph(vec![])),
},
NorgASTFlat::VerbatimRangedTag {
name,
parameters,
Expand All @@ -119,6 +84,39 @@ fn convert(flat: NorgASTFlat) -> NorgAST {
},
NorgASTFlat::InfirmTag { name, parameters } => NorgAST::InfirmTag { name, parameters },
NorgASTFlat::DelimitingModifier(t) => NorgAST::DelimitingModifier(t),
NorgASTFlat::NestableDetachedModifier {
modifier_type,
level,
extensions,
content,
} => NorgAST::NestableDetachedModifier {
modifier_type,
level,
extensions,
text: content,
content: vec![],
},
NorgASTFlat::Heading {
level,
title,
extensions,
} => NorgAST::Heading {
level,
title,
extensions,
content: vec![],
},
NorgASTFlat::CarryoverTag {
tag_type,
name,
parameters,
next_object,
} => NorgAST::CarryoverTag {
tag_type,
name,
parameters,
next_object: Box::new(convert(*next_object.clone())),
},
}
}

Expand Down Expand Up @@ -262,14 +260,7 @@ pub fn stage_4(flat: Vec<NorgASTFlat>) -> Vec<NorgAST> {
name,
parameters,
next_object,
// TODO: match list item, and then add a case in the if let in the block to handle
// it
// then alter consume functions to work with tagged headings/list items
} if matches!(
**next_object,
NorgASTFlat::Heading { .. } | NorgASTFlat::NestableDetachedModifier { .. }
) =>
{
} => {
match *next_object.clone() {
NorgASTFlat::Heading {
level,
Expand Down Expand Up @@ -311,7 +302,7 @@ pub fn stage_4(flat: Vec<NorgASTFlat>) -> Vec<NorgAST> {
})
}
_ => {
unreachable!();
ast.push(convert(item.clone()))
}
}
}
Expand Down

0 comments on commit eabde9a

Please sign in to comment.