aboutsummaryrefslogtreecommitdiffstats
path: root/src/to_mdast.rs
blob: d56134a33d388255980dd44d123543375a4e55d4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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,
    }
}