aboutsummaryrefslogtreecommitdiffstats
path: root/src/parser.rs
blob: 32689d6a72f3f706a5a0db3bf1f20ba3928afab8 (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
41
42
//! Turn a string of markdown into events.

use std::collections::HashSet;
// To do: this should start with `containers`, when they’re done.
use crate::content::flow::flow;
use crate::tokenizer::{Code, Event, Point};
use crate::util::codes::parse as parse_codes;

/// Information needed, in all content types, when parsing markdown.
///
/// Importantly, this contains a set of known definitions.
/// It also references the input value as [`Code`][]s.
#[derive(Debug)]
pub struct ParseState {
    /// List of codes.
    pub codes: Vec<Code>,
    /// Set of defined identifiers.
    pub definitions: HashSet<String>,
}

/// Turn a string of markdown into events.
///
/// Passes the codes back so the compiler can access the source.
pub fn parse(value: &str) -> (Vec<Event>, Vec<Code>) {
    let mut parse_state = ParseState {
        codes: parse_codes(value),
        definitions: HashSet::new(),
    };

    let events = flow(
        &mut parse_state,
        Point {
            line: 1,
            column: 1,
            offset: 0,
        },
        0,
    );

    // To do: pass whole `parse_state` back?
    (events, parse_state.codes)
}