diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-06-29 10:26:39 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-06-29 10:26:39 +0200 |
commit | 7721f210c16e19b1c2af90f69130386b89bb5104 (patch) | |
tree | c47ff3d9c974ccd0c81a2c5b8ccbce9f7635975d /src/parser.rs | |
parent | 7bb1008f508f61b51dd80086a91ada347be36c68 (diff) | |
download | markdown-rs-7721f210c16e19b1c2af90f69130386b89bb5104.tar.gz markdown-rs-7721f210c16e19b1c2af90f69130386b89bb5104.tar.bz2 markdown-rs-7721f210c16e19b1c2af90f69130386b89bb5104.zip |
Add support for sharing identifiers, references before definitions
Diffstat (limited to 'src/parser.rs')
-rw-r--r-- | src/parser.rs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/parser.rs b/src/parser.rs index 32b7f36..f11f0d1 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -4,24 +4,32 @@ use crate::content::flow::flow; use crate::tokenizer::{as_codes, Code, Event, Point}; +/// To do: could we do without `HashSet`, so we don’t need `std`? +use std::collections::HashSet; + +/// 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 { - /// To do. + /// List of codes. pub codes: Vec<Code>, - /// To do. - pub definitions: Vec<String>, + /// 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 parse_state = ParseState { + let mut parse_state = ParseState { codes: as_codes(value), - definitions: vec![], + definitions: HashSet::new(), }; let events = flow( - &parse_state, + &mut parse_state, Point { line: 1, column: 1, |