diff options
Diffstat (limited to 'src/to_mdast.rs')
-rw-r--r-- | src/to_mdast.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/to_mdast.rs b/src/to_mdast.rs new file mode 100644 index 0000000..d56134a --- /dev/null +++ b/src/to_mdast.rs @@ -0,0 +1,40 @@ +//! Turn events into a syntax tree. + +// To do: example. + +use crate::event::Event; +use crate::mdast; +use crate::Options; +use alloc::vec; + +/// Turn events and bytes into a syntax tree. +pub fn compile(events: &[Event], _bytes: &[u8], _options: &Options) -> mdast::Root { + mdast::Root { + kind: mdast::Kind::Root, + children: vec![], + position: Some(mdast::Position { + start: if events.is_empty() { + create_point(1, 1, 0) + } else { + point_from_event(&events[0]) + }, + end: if events.is_empty() { + create_point(1, 1, 0) + } else { + point_from_event(&events[events.len() - 1]) + }, + }), + } +} + +fn point_from_event(event: &Event) -> mdast::Point { + create_point(event.point.line, event.point.column, event.point.index) +} + +fn create_point(line: usize, column: usize, offset: usize) -> mdast::Point { + mdast::Point { + line, + column, + offset, + } +} |